X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FDaemonize.pm;h=903832dfd911fb9111ce958ac02a09187b271d2a;hb=92cf56b7c3fd91568e4b964319a7862fc4f1d651;hp=4ce6fd33ad3bc1ec10ea47a42b6dbd81b0a5a4ac;hpb=4a24225a4a5ba994ccec944e4bc617f0506d2eed;p=gitmo%2FMooseX-Daemonize.git diff --git a/lib/MooseX/Daemonize.pm b/lib/MooseX/Daemonize.pm index 4ce6fd3..903832d 100644 --- a/lib/MooseX/Daemonize.pm +++ b/lib/MooseX/Daemonize.pm @@ -7,6 +7,9 @@ our $VERSION = 0.05; with 'MooseX::Daemonize::WithPidFile', 'MooseX::Getopt'; + +use constant OK => 0; +use constant ERROR => 1; has progname => ( metaclass => 'Getopt', @@ -112,7 +115,8 @@ sub start { $self->clear_exit_code; if ($self->pidfile->is_running) { - $self->status_message('Daemon is already running with pid (' . $self->pidfile->pid . ')'); + $self->exit_code(OK); + $self->status_message('Daemon is already running with pid (' . $self->pidfile->pid . ')'); return !($self->exit_code); } @@ -122,13 +126,14 @@ sub start { else { eval { $self->daemonize }; if ($@) { - $self->exit_code(1); + $self->exit_code(ERROR); $self->status_message('Start failed : ' . $@); return !($self->exit_code); } } unless ($self->is_daemon) { + $self->exit_code(OK); $self->status_message('Start succeeded'); return !($self->exit_code); } @@ -150,10 +155,11 @@ sub status { $self->clear_exit_code; if ($self->pidfile->is_running) { + $self->exit_code(OK); $self->status_message('Daemon is running with pid (' . $self->pidfile->pid . ')'); } else { - $self->exit_code(1); + $self->exit_code(ERROR); $self->status_message('Daemon is not running with pid (' . $self->pidfile->pid . ')'); } @@ -167,17 +173,19 @@ sub restart { $self->clear_exit_code; unless ($self->stop) { - $self->exit_code(1); + $self->exit_code(ERROR); $self->status_message('Restart (Stop) failed : ' . $@); } unless ($self->start) { - $self->exit_code(1); + $self->exit_code(ERROR); $self->status_message('Restart (Start) failed : ' . $@); } - $self->status_message("Restart successful") - if !$self->exit_code; + if ($self->exit_code == OK) { + $self->exit_code(OK); + $self->status_message("Restart successful"); + } return !($self->exit_code); } @@ -205,11 +213,12 @@ sub stop { eval { $self->$_kill($self->pidfile->pid) }; # and complain if we can't ... if ($@) { - $self->exit_code(1); + $self->exit_code(ERROR); $self->status_message('Stop failed : ' . $@); } # or gloat if we succeed .. else { + $self->exit_code(OK); $self->status_message('Stop succeeded'); } @@ -228,6 +237,7 @@ sub stop { # this just returns the OK # exit code for now, but # we should make this overridable + $self->exit_code(OK); $self->status_message("Not running"); } @@ -317,7 +327,7 @@ This document describes MooseX::Daemonize version 0.05 $daemon->restart if $command eq 'restart'; $daemon->stop if $command eq 'stop'; - warn($daemon->status); + warn($daemon->status_message); exit($daemon->exit_code); =head1 DESCRIPTION @@ -373,7 +383,7 @@ These are the internal attributes, which are not available through MooseX::Getop =item I -=item I +=item I =back @@ -407,6 +417,8 @@ Literally this is: =item B +=item B + =back @@ -488,10 +500,12 @@ L. L, L -=head1 AUTHOR +=head1 AUTHORS Chris Prather C<< >> +Stevan Little C<< >> + =head1 THANKS Mike Boyko, Matt S. Trout, Stevan Little, Brandon Black, Ash Berlin and the