On Friday, April 19, 2002, at 07:03 , Chas Owens wrote:
> On Thu, 2002-04-18 at 18:28, drieux wrote: [..] >> you might want to have your 'main loop' in >> >> our $still_going = 1; >> $SIG{TERM} = sub { $still_going = 0 }; # correcting Chas's Issues... 8-) >> while ( $still_going ) { >> # the main loop >> } [..] > > What issues? I use > > my $terminate = 0; > $SIG{TERM} = sub { $terminate = 1 }; > until ($terminate) { > #do stuff > } > > #cleanup There it is... you use the 'until foo' - I lost track of the 'loop' - and so it looked 'insane' to me that the cool oneline sig handler was back end yakward... besides - while($still_going) is up beat, positive, friendly, warm, HappyFluffyBunnies...... whereas - until($terminate) - downer, bummer, badly dressed cyborgs from the future hunting down the terran infestation units... Therapy.... Seek Therapy.... 8-) [..] You do get points for remembering to have a 'shutdown' fail safe solution - but that should be the last knife in your boot. If you put out a PID_FILE in /tmp - then its an if file exists read pid send sig, sleep $reasonable_time , check proc table, if still up - send hard KILL. > <example name="shutdown"> > #!/bin/sh > PID=`ps -ef | grep daemon.pl | grep "/usr/bin/perl" | awk -e '{print > $2}'` yes, yes, yes.... I know that this is not comp.oldGuys.shell but two pieces of advice: 1) always run your daemons under a 'special UID' so that you can use your os's version of ps -u $UID_FOR_ME | awk '/<pattern>/ {print $1}' { this form works on solaris, linux and darwin - and is more portable across the *nix space than ps -ef.... } Also - for safety sake you should expect that PID will be in a 'list context' hence should cope with it in the for pid in $PID do # skank on the puppy done 2) and remember that awk does regex..... and since you are firing up this with the intention of Doing it with perl why not DO Perl? Unless you were planning on the classic 'init script' - at which point - why not just do the classical and canonical???? [..] <example> #!/bin/sh BASE=/the/base/directory BIN=$BASE/bin LOG=$BASE/log LOGFILE=$LOG/CASPERII.log pidGrovel() { PID=`ps -ef | grep daemon.pl | grep "/usr/bin/perl" | awk -e '{print $2}'` if [ "$PID" != '' ] ; then kill -15 $PID else echo "Could not find daemon.pl, try 'ps -ef'ing yourself" fi } start() { $BIN/daemon.pl >> $LOGFILE 2>> $LOGFILE.err } stop() { pidGrovel } case "$1" in start) start ;; stop) stop ;; esac echo "Bye Bye, So Long, Thanks for all the Fish" </example> this way if you want to grow out your verb list for things like reload, status, daemon_act_funky... you isolate those in their own 'functions'...... but the two canonicals ones that you will need start/stop are kosher.... extra credit to show the 'hey guys we can still get our perl init script to run with sh init_script start ciao drieux --- Kids these days, no respect for their elders, no respect for tradition..... not like when I was growing up - we had the doors and dylan, and elders you just had to respect.... 8-) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]