On Tuesday, August 13, 2002, at 09:01 , Kipp, James wrote:
[..]
> methinks we covered this ground before. will implement the start, stop
> like
> an rc script, but i don't need to deal with a config file in this case.
> Thanks
I think that you and I have gone around that mark,
but thought it best to plonk it back out there as a
part of how to deal with the general idea....
as you noticed in my
http://www.wetware.com/drieux/pbl/Sys/daemon1.txt
in the daemon 102 class
gee, this just needs to be a dumb pig that just gets
launched and does some stuff
we find a simple :
if ( defined($ARGV[0]) and $ARGV[0] eq '-k' ) {
justKillMe(@daemonFoo) if ( -f $daemonFoo[2] );
print "and We $$ Are Outta Here\n";
exit(0);
}
....
#------------------------
# you know, for the -k shutdown side
sub justKillMe {
my ($out,$err,$pidF) = @_;
my $targetPid;
open(PID, "$pidF") or die "unable to open pid file:$!\n";
chomp($targetPid = <PID> );
close(PID);
die "You are on your own bud - grovel the proc table\n" unless
$targetPid ;
kill 'TERM', $targetPid ;
#-------------------------
# here is where you want to do the whole
} # end of justKillMe
since that is one of the simplest ways to go about the process
of being able to implement the
daemon_critter [-k]
where it will attempt to daemonize itself, unless passed the
argument to try and KILL another instance of itself...
I might change that into a more 'oo' style where I had it rigged
as say something like
my $me = do {
require File::Basename;
my $programmeName = basename $0;
{
Iam => $programmeName;
stdout => "/tmp/${programmeName}.stdout" ,
stderr => "/tmp/${programmeName}.stderr" ,
pidF => "/tmp/${programmeName}.pid"
}
};
( I've seen that style before.... ;-)
hence would have done that with
....
justKillMe($me);
....
sub justKillMe {
my ($obj) = @_;
my $targetPid;
open(PID, "$obj_{pidF}") or die "unable to open pid file:$!\n";
chomp($targetPid = <PID> );
close(PID);
die "You are on your own bud - grovel the proc table\n" unless
$targetPid ;
kill 'TERM', $targetPid ;
#-------------------------
# here is where you want to do the whole
} # end of justKillMe
who knows, we might move along to other things,
like how to use closures to encapsulate methods....
hence on to something like
if($me->run_daemon()) {
$me->do_daemon();
} else {
$me->just_shoot_me();
}
ciao
drieux
---
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]