From lembark at wrkhors.com  Thu Feb  6 11:18:10 2025
From: lembark at wrkhors.com (Steven Lembark)
Date: Thu, 06 Feb 2025 14:18:10 -0500
Subject: [Chicago-talk] Determining if another perl process is running.
In-Reply-To: <dc108236-8f0f-4147-ad77-d952f1c803fc@alanmead.org>
References: <CAKLxnzZvDvRR0Nvn=_8_9AGXpzWibwZXBbU9Db-495_ZpLi3Jw@mail.gmail.com>
 <SJ0PR09MB931920FE8E2A4CC76ADA5B16C02E2@SJ0PR09MB9319.namprd09.prod.outlook.com>
 <dc108236-8f0f-4147-ad77-d952f1c803fc@alanmead.org>
Message-ID: <1308027F-FE50-4852-863B-3D0300281B6E@wrkhors.com>

On November 25, 2024 10:54:06 AM EST, Alan Mead <amead2 at alanmead.org> wrote:
>I like Andy's PID file suggestion, but I would be inclined to make this a bash script rather than a perl one-liner and test something like:
>
>`ps aux | grep perl | grep starman`
>
>
>And if that command causes it's own failure (by always creating a process with 'perl' and 'starman') then:
>
>`ps aux | grep [p]erl | grep [s]tarman`
>
>
>If you find bash scripting not super easy (like me), ChatGPT is very helpful. It's helped me a lot in writing better admin scripts.
>
>
>-Alan
>
>
>On 11/25/24 9:41 AM, Andy Bach wrote:
>> Need to expand your grep RE or add a grep -v to remove the ones you don't want, though, then you have to remove the one you just added.? Another is to track the pids, find the ones you've created and look for one outside that set.? You could have starman (if it doesn't) create a .pid file and use that to check that pid's status (with lsof -p <pid> maybe), rather than grepping.
>> ------------------------------------------------------------------------
>> *From:* Chicago-talk <chicago-talk-bounces+andy_bach=wiwb.uscourts.gov at pm.org> on behalf of Richard Reina <gatorreina at gmail.com>
>> *Sent:* Sunday, November 24, 2024 5:19 PM
>> *To:* Chicago.pm chatter <chicago-talk at pm.org>
>> *Subject:* [Chicago-talk] Determining if another perl process is running.
>> *CAUTION - EXTERNAL:
>> *
>> 
>> 
>> Hello everyone,
>> 
>> So excited about the Winter Perl Conference that I just registered for that I thought I would rebuild my aged Perl Dancer2 website. I 've done so and deployed it on a Digital Ocean droplet but I've hit a snag in setting up a cron job to make sure starman is running. It seems my query into whether the process is running gets treated as evidence that the process IS running.
>> 
>> When I do:
>> 
>> perl -e 'my $smstat = `ps -ef | grep starman`; unless ($smstat =~ /starman master/) { system("XDG_RUNTIME_DIR=/run/user/1001 exec /home/starman/starman.pl <http://starman.pl> start &>> /home/starman/starman.log"); print localtime . " starting starman\n"; } else { print "Starman is already running\n\n\n $smstat\n" }';
>> 
>> RESULTS IN:
>> 
>> Starman is already running
>> 
>> 
>> ?starman ? 203805 ? ? ? 1 ?0 Nov08 ? ? ? ? ?00:00:00 /lib/systemd/systemd --user
>> starman ? 203806 ?203805 ?0 Nov08 ? ? ? ? ?00:00:00 (sd-pam)
>> root ? ? ?472040 ? ? 385 ?0 Nov20 ? ? ? ? ?00:00:00 sshd: starman [priv]
>> starman ? 472049 ?472040 ?0 Nov20 ? ? ? ? ?00:00:01 sshd: starman at pts/0
>> starman ? 472050 ?472049 ?0 Nov20 pts/0 ? ?00:00:00 -bash
>> starman ? 544383 ?472050 ?0 23:11 pts/0 ? ?00:00:00 perl -e my $smstat = `ps -ef | grep starman`; unless ($smstat =~ /starman master/) { system("XDG_RUNTIME_DIR=/run/user/1001 exec /home/starman/starman.pl <http://starman.pl> start &>> /home/starman/starman.log"); print localtime . " starting starman\n"; } else { print "Starman is already running\n\n\n $smstat\n" }
>> starman ? 544384 ?544383 ?0 23:11 pts/0 ? ?00:00:00 sh -c ps -ef | grep starman
>> starman ? 544385 ?544384 ?0 23:11 pts/0 ? ?00:00:00 ps -ef
>> starman ? 544386 ?544384 ?0 23:11 pts/0 ? ?00:00:00 grep starman
>> 
>> It always says it's running even if it is not apparently because it's seeing 'starman master/ in the perl script that is inquiring.
>> 
>> Anyone know a good solution to avoid this so that I can determine whether my starman startup?script is indeed?running?
>> 
>> *CAUTION - EXTERNAL EMAIL:* This email originated outside the Judiciary. Exercise caution when opening attachments or clicking on links.
>> 
>> 
>> 
>> _______________________________________________
>> Chicago-talk mailing list
>> Chicago-talk at pm.org
>> https://mail.pm.org/mailman/listinfo/chicago-talk
>

PID files have one annoying shortfall: unlinking the file leaves you unprotected.

pgrep makes it simple enough to scan for a running proc by path and args, e.g.

pgrep -f 'starman.*master,*8080';

and saves you from dealing with stale files, accidental unlinks, etc.
-- 
Steven Lembark
888 359 3508
lembark at wrkhors.com

From lembark at wrkhors.com  Thu Feb  6 11:19:24 2025
From: lembark at wrkhors.com (Steven Lembark)
Date: Thu, 06 Feb 2025 14:19:24 -0500
Subject: [Chicago-talk] Determining if another perl process is running.
In-Reply-To: <CAKLxnzYuZuZd6Py21yb8OEb7uN9rUubw8q8ebFFb6GjZXJy3OA@mail.gmail.com>
References: <CAKLxnzZvDvRR0Nvn=_8_9AGXpzWibwZXBbU9Db-495_ZpLi3Jw@mail.gmail.com>
 <SJ0PR09MB931920FE8E2A4CC76ADA5B16C02E2@SJ0PR09MB9319.namprd09.prod.outlook.com>
 <CAKLxnzYuZuZd6Py21yb8OEb7uN9rUubw8q8ebFFb6GjZXJy3OA@mail.gmail.com>
Message-ID: <2E82EB70-0E56-4292-80EC-09498EAC9DAC@wrkhors.com>

On November 25, 2024 6:47:52 PM EST, Richard Reina <gatorreina at gmail.com> wrote:
>Gentlemen,
>
>Thank you for the replies I ended up using pgrep in my crontab and it seems
>to work well so far:
>
>perl -e 'my $smstat = `pgrep -w "starman master"`; unless ($smstat &&
>$smstat > 0) { system("XDG_RUNTIME_DIR=/run/user/1001 exec /home/starman/
>starman.pl start &>> /home/starman/starman.log"); print localtime . "
>starting starman\n"; } else { print "Starman is already running\n" }';
>
>Is that okay?
>
>El lun, 25 nov 2024 a las 9:41, Andy Bach (<Andy_Bach at wiwb.uscourts.gov>)
>escribi?:
>
>> Need to expand your grep RE or add a grep -v to remove the ones you don't
>> want, though, then you have to remove the one you just added.  Another is
>> to track the pids, find the ones you've created and look for one outside
>> that set.  You could have starman (if it doesn't) create a .pid file and
>> use that to check that pid's status (with lsof -p <pid> maybe), rather than
>> grepping.
>> ------------------------------
>> *From:* Chicago-talk <chicago-talk-bounces+andy_bach=
>> wiwb.uscourts.gov at pm.org> on behalf of Richard Reina <gatorreina at gmail.com
>> >
>> *Sent:* Sunday, November 24, 2024 5:19 PM
>> *To:* Chicago.pm chatter <chicago-talk at pm.org>
>> *Subject:* [Chicago-talk] Determining if another perl process is running.
>>
>>
>> *CAUTION - EXTERNAL: *
>> Hello everyone,
>>
>> So excited about the Winter Perl Conference that I just registered for
>> that I thought I would rebuild my aged Perl Dancer2 website. I 've done so
>> and deployed it on a Digital Ocean droplet but I've hit a snag in setting
>> up a cron job to make sure starman is running. It seems my query into
>> whether the process is running gets treated as evidence that the process IS
>> running.
>>
>> When I do:
>>
>> perl -e 'my $smstat = `ps -ef | grep starman`; unless ($smstat =~ /starman
>> master/) { system("XDG_RUNTIME_DIR=/run/user/1001 exec /home/starman/
>> starman.pl start &>> /home/starman/starman.log"); print localtime . "
>> starting starman\n"; } else { print "Starman is already running\n\n\n
>> $smstat\n" }';
>>
>> RESULTS IN:
>>
>> Starman is already running
>>
>>
>>  starman   203805       1  0 Nov08 ?        00:00:00 /lib/systemd/systemd
>> --user
>> starman   203806  203805  0 Nov08 ?        00:00:00 (sd-pam)
>> root      472040     385  0 Nov20 ?        00:00:00 sshd: starman [priv]
>> starman   472049  472040  0 Nov20 ?        00:00:01 sshd: starman at pts/0
>> starman   472050  472049  0 Nov20 pts/0    00:00:00 -bash
>> starman   544383  472050  0 23:11 pts/0    00:00:00 perl -e my $smstat =
>> `ps -ef | grep starman`; unless ($smstat =~ /starman master/) {
>> system("XDG_RUNTIME_DIR=/run/user/1001 exec /home/starman/starman.pl
>> start &>> /home/starman/starman.log"); print localtime . " starting
>> starman\n"; } else { print "Starman is already running\n\n\n $smstat\n" }
>> starman   544384  544383  0 23:11 pts/0    00:00:00 sh -c ps -ef | grep
>> starman
>> starman   544385  544384  0 23:11 pts/0    00:00:00 ps -ef
>> starman   544386  544384  0 23:11 pts/0    00:00:00 grep starman
>>
>> It always says it's running even if it is not apparently because it's
>> seeing 'starman master/ in the perl script that is inquiring.
>>
>> Anyone know a good solution to avoid this so that I can determine whether
>> my starman startup script is indeed running?
>>
>> *CAUTION - EXTERNAL EMAIL:* This email originated outside the Judiciary.
>> Exercise caution when opening attachments or clicking on links.
>> _______________________________________________
>> Chicago-talk mailing list
>> Chicago-talk at pm.org
>> https://mail.pm.org/mailman/listinfo/chicago-talk
>>

PGREP(1)    User Commands   PGREP(1)

NAME
       pgrep,  pkill, pidwait - look
       up,  signal,  or   wait   for
       processes  based  on name and
       other attributes

SYNOPSIS
       pgrep [options] pattern
       pkill [options] pattern
       pidwait [options] pattern
-- 
Steven Lembark
888 359 3508
lembark at wrkhors.com

From richard at rushlogistics.com  Thu Feb  6 12:05:25 2025
From: richard at rushlogistics.com (Richard Reina)
Date: Thu, 06 Feb 2025 15:05:25 -0500
Subject: [Chicago-talk] Determining if another perl process is running.
In-Reply-To: <1308027F-FE50-4852-863B-3D0300281B6E@wrkhors.com>
References: <CAKLxnzZvDvRR0Nvn=_8_9AGXpzWibwZXBbU9Db-495_ZpLi3Jw@mail.gmail.com>
 <SJ0PR09MB931920FE8E2A4CC76ADA5B16C02E2@SJ0PR09MB9319.namprd09.prod.outlook.com>
 <dc108236-8f0f-4147-ad77-d952f1c803fc@alanmead.org>
 <1308027F-FE50-4852-863B-3D0300281B6E@wrkhors.com>
Message-ID: <1738872325.4zwzwl1ygw48k48o@hostingemail.digitalspace.net>

Hey Steve,

Great to hear from you. Thanks for the reply. I ended up doing something similar: pgrep -w "starman master"

Let's meet up Quenchers at 5pm for a quick beer! :)






On Thu, 06 Feb 2025 14:18:10 -0500, Steven Lembark <lembark at wrkhors.com> wrote:

On November 25, 2024 10:54:06 AM EST, Alan Mead wrote:
>I like Andy's PID file suggestion, but I would be inclined to make this a bash script rather than a perl one-liner and test something like:
>
>`ps aux | grep perl | grep starman`
>
>
>And if that command causes it's own failure (by always creating a process with 'perl' and 'starman') then:
>
>`ps aux | grep [p]erl | grep [s]tarman`
>
>
>If you find bash scripting not super easy (like me), ChatGPT is very helpful. It's helped me a lot in writing better admin scripts.
>
>
>-Alan
>
>
>On 11/25/24 9:41 AM, Andy Bach wrote:
>> Need to expand your grep RE or add a grep -v to remove the ones you don't want, though, then you have to remove the one you just added.? Another is to track the pids, find the ones you've created and look for one outside that set.? You could have starman (if it doesn't) create a .pid file and use that to check that pid's status (with lsof -p maybe), rather than grepping.
>> ------------------------------------------------------------------------
>> *From:* Chicago-talk on behalf of Richard Reina
>> *Sent:* Sunday, November 24, 2024 5:19 PM
>> *To:* Chicago.pm chatter
>> *Subject:* [Chicago-talk] Determining if another perl process is running.
>> *CAUTION - EXTERNAL:
>> *
>>
>>
>> Hello everyone,
>>
>> So excited about the Winter Perl Conference that I just registered for that I thought I would rebuild my aged Perl Dancer2 website. I 've done so and deployed it on a Digital Ocean droplet but I've hit a snag in setting up a cron job to make sure starman is running. It seems my query into whether the process is running gets treated as evidence that the process IS running.
>>
>> When I do:
>>
>> perl -e 'my $smstat = `ps -ef | grep starman`; unless ($smstat =~ /starman master/) { system("XDG_RUNTIME_DIR=/run/user/1001 exec /home/starman/starman.pl start &>> /home/starman/starman.log"); print localtime . " starting starman\n"; } else { print "Starman is already running\n\n\n $smstat\n" }';
>>
>> RESULTS IN:
>>
>> Starman is already running
>>
>>
>> ?starman ? 203805 ? ? ? 1 ?0 Nov08 ? ? ? ? ?00:00:00 /lib/systemd/systemd --user
>> starman ? 203806 ?203805 ?0 Nov08 ? ? ? ? ?00:00:00 (sd-pam)
>> root ? ? ?472040 ? ? 385 ?0 Nov20 ? ? ? ? ?00:00:00 sshd: starman [priv]
>> starman ? 472049 ?472040 ?0 Nov20 ? ? ? ? ?00:00:01 sshd: starman at pts/0
>> starman ? 472050 ?472049 ?0 Nov20 pts/0 ? ?00:00:00 -bash
>> starman ? 544383 ?472050 ?0 23:11 pts/0 ? ?00:00:00 perl -e my $smstat = `ps -ef | grep starman`; unless ($smstat =~ /starman master/) { system("XDG_RUNTIME_DIR=/run/user/1001 exec /home/starman/starman.pl start &>> /home/starman/starman.log"); print localtime . " starting starman\n"; } else { print "Starman is already running\n\n\n $smstat\n" }
>> starman ? 544384 ?544383 ?0 23:11 pts/0 ? ?00:00:00 sh -c ps -ef | grep starman
>> starman ? 544385 ?544384 ?0 23:11 pts/0 ? ?00:00:00 ps -ef
>> starman ? 544386 ?544384 ?0 23:11 pts/0 ? ?00:00:00 grep starman
>>
>> It always says it's running even if it is not apparently because it's seeing 'starman master/ in the perl script that is inquiring.
>>
>> Anyone know a good solution to avoid this so that I can determine whether my starman startup?script is indeed?running?
>>
>> *CAUTION - EXTERNAL EMAIL:* This email originated outside the Judiciary. Exercise caution when opening attachments or clicking on links.
>>
>>
>>
>> _______________________________________________
>> Chicago-talk mailing list
>> Chicago-talk at pm.org
>> https://mail.pm.org/mailman/listinfo/chicago-talk
>

PID files have one annoying shortfall: unlinking the file leaves you unprotected.

pgrep makes it simple enough to scan for a running proc by path and args, e.g.

pgrep -f 'starman.*master,*8080';

and saves you from dealing with stale files, accidental unlinks, etc.
--
Steven Lembark
888 359 3508
lembark at wrkhors.com
_______________________________________________
Chicago-talk mailing list
Chicago-talk at pm.org
https://mail.pm.org/mailman/listinfo/chicago-talk
?

From amead2 at alanmead.org  Wed Feb 26 11:18:22 2025
From: amead2 at alanmead.org (Alan Mead)
Date: Wed, 26 Feb 2025 13:18:22 -0600
Subject: [Chicago-talk] Experiences with AI/OpenAI API access with Perl?
Message-ID: <a524d205fbd886ec5b869728a79ab41f@alanmead.org>

Is anyone using OpenAI (or any of the many compatible APIs) with Perl? I 
have rolled my own code to do research like this: 
https://jattjournal.net/index.php/atp/article/view/173204

But I'm wondering what others are doing?

I had a longer summary, but suffice it to say that I've had limited 
success with OpenAI::API and OpenAPI::Client::OpenAI, and I'd rather use 
Python (this isn't my day job and I'm annoyed ever time I use Python). I 
think what I'd like is an OpenAI::Tiny::API or OpenAI::TinyAPI that 
handles chat completions and doesn't have dozens of dependencies.

-Alan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/chicago-talk/attachments/20250226/824ca5fa/attachment.html>