From: Brandon L Black Date: Wed, 19 Dec 2007 03:39:40 +0000 (+0000) Subject: fix up sigint / stop() stuff. stop() stops a different process from the one that... X-Git-Tag: 0_06~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMooseX-Daemonize.git;a=commitdiff_plain;h=4a24225a4a5ba994ccec944e4bc617f0506d2eed fix up sigint / stop() stuff. stop() stops a different process from the one that is executing stop(), and sigint calls the shutdown method, which clears the pidfile and exits --- diff --git a/lib/MooseX/Daemonize.pm b/lib/MooseX/Daemonize.pm index b16877d..4ce6fd3 100644 --- a/lib/MooseX/Daemonize.pm +++ b/lib/MooseX/Daemonize.pm @@ -92,12 +92,16 @@ sub get_pid { (shift)->pidfile->pid } sub setup_signals { my $self = shift; - $SIG{'INT'} = sub { $self->handle_sigint }; - $SIG{'HUP'} = sub { $self->handle_sighup }; + $SIG{'INT'} = sub { $self->shutdown }; +# I can't think of a sane default here really ... +# $SIG{'HUP'} = sub { $self->handle_sighup }; } -sub handle_sigint { $_[0]->stop } -sub handle_sighup { $_[0]->restart } +sub shutdown { + my $self = shift; + $self->pidfile->remove if $self->pidfile->pid == $$; + exit(0); +} ## daemon control methods ... @@ -237,15 +241,12 @@ $_kill = sub { my ( $self, $pid ) = @_; return unless $pid; unless ( CORE::kill 0 => $pid ) { - # warn "$pid already appears dead."; return; } if ( $pid eq $$ ) { - - # warn "$pid is us! Can't commit suicide."; - return; + die "$pid is us! Can't commit suicide."; } my $timeout = $self->stop_timeout; @@ -253,15 +254,6 @@ $_kill = sub { # kill 0 => $pid returns 0 if the process is dead # $!{EPERM} could also be true if we cant kill it (permission error) - # if this is being called - # inside the daemon then - # we don't want sig-INT to - # fall into a loop here - # so we reset it. - if ($self->is_daemon) { - $SIG{INT} = 'DEFAULT'; - } - # Try SIGINT ... 2s ... SIGTERM ... 2s ... SIGKILL ... 3s ... UNDEAD! for ( [ 2, $timeout ], [15, $timeout], [9, $timeout * 1.5] ) { my ($signal, $timeout) = @$_;