X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FDaemonize.pm;h=ba46d4db36b4351604bee1c822a5c56248501b5a;hb=b38ab84f7a1b83212eefcb2e7f876c42b8dbfb24;hp=dc6be99691cdca0b86c9e688db9330f283c8badc;hpb=892a51e60bd3417ab7c22b4c2c6b2e80b6b0e415;p=gitmo%2FMooseX-Daemonize.git diff --git a/lib/MooseX/Daemonize.pm b/lib/MooseX/Daemonize.pm index dc6be99..ba46d4d 100644 --- a/lib/MooseX/Daemonize.pm +++ b/lib/MooseX/Daemonize.pm @@ -3,7 +3,7 @@ use strict; # because Kwalitee is pedantic use Moose::Role; use MooseX::Types::Path::Class; -our $VERSION = 0.05; +our $VERSION = 0.06; with 'MooseX::Daemonize::WithPidFile', 'MooseX::Getopt'; @@ -30,7 +30,7 @@ has pidbase => ( coerce => 1, required => 1, lazy => 1, - default => sub { Path::Class::Dir->new('var', 'run') }, + default => sub { Path::Class::Dir->new('', 'var', 'run') }, ); has basedir => ( @@ -223,15 +223,6 @@ sub stop { } } - - # clean up ... - eval { $self->pidfile->remove }; - if ($@) { - warn "Could not remove pidfile (" - . $self->pidfile->file - . ") because : $!"; - } - } else { # this just returns the OK @@ -265,22 +256,38 @@ $_kill = sub { # $!{EPERM} could also be true if we cant kill it (permission error) # Try SIGINT ... 2s ... SIGTERM ... 2s ... SIGKILL ... 3s ... UNDEAD! + my $terminating_signal; for ( [ 2, $timeout ], [15, $timeout], [9, $timeout * 1.5] ) { my ($signal, $timeout) = @$_; $timeout = int $timeout; CORE::kill($signal, $pid); - last unless CORE::kill 0 => $pid or $!{EPERM}; - while ($timeout) { - sleep(1); - last unless CORE::kill 0 => $pid or $!{EPERM}; + unless(CORE::kill 0 => $pid or $!{EPERM}) { + $terminating_signal = $signal; + last; + } $timeout--; + sleep(1) if $timeout; } + + last if $terminating_signal; } - return unless ( CORE::kill 0 => $pid or $!{EPERM} ); + if($terminating_signal) { + if($terminating_signal == 9) { + # clean up the pidfile ourselves iff we used -9 and it worked + warn "Had to resort to 'kill -9' and it worked, wiping pidfile"; + eval { $self->pidfile->remove }; + if ($@) { + warn "Could not remove pidfile (" + . $self->pidfile->file + . ") because : $!"; + } + } + return; + } # IF it is still running Carp::carp "$pid doesn't seem to want to die."; # AHH EVIL DEAD!