with 'MooseX::Daemonize::WithPidFile',
'MooseX::Getopt';
+
+use constant OK => 0;
+use constant ERROR => 1;
has progname => (
metaclass => 'Getopt',
$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);
}
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);
}
$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 . ')');
}
$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);
}
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');
}
# this just returns the OK
# exit code for now, but
# we should make this overridable
+ $self->exit_code(OK);
$self->status_message("Not running");
}
$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
=item I<exit_code Int>
-=item I<status Str>
+=item I<status_message Str>
=back
=item B<status>
+=item B<shutdown>
+
=back
L<Proc::Daemon>, L<Daemon::Generic>
-=head1 AUTHOR
+=head1 AUTHORS
Chris Prather C<< <perigrin@cpan.org> >>
+Stevan Little C<< <stevan.little@iinteractive.com> >>
+
=head1 THANKS
Mike Boyko, Matt S. Trout, Stevan Little, Brandon Black, Ash Berlin and the
use Cwd;
use File::Spec::Functions;
-use Test::More tests => 9;
-use MooseX::Daemonize;
+use Test::More tests => 29;
+use Test::Moose;
+
+BEGIN {
+ use_ok('MooseX::Daemonize');
+}
use constant DEBUG => 0;
pidbase => $CWD,
filename => $FILENAME,
);
+isa_ok($app, 'FileMaker');
+does_ok($app, 'MooseX::Daemonize');
+does_ok($app, 'MooseX::Daemonize::WithPidFile');
+does_ok($app, 'MooseX::Daemonize::Core');
+
+isa_ok($app->pidfile, 'MooseX::Daemonize::Pid::File');
+
+is($app->pidfile->file, "$CWD/filemaker.pid", '... got the right PID file path');
+ok(not(-e $app->pidfile->file), '... our pidfile does not exist');
ok(!$app->status, '... the daemon is running');
+is($app->exit_code, MooseX::Daemonize->ERROR, '... got the right error code');
+
+ok($app->stop, '... the app will stop cause its not running');
+is($app->status_message, "Not running", '... got the correct status message');
+is($app->exit_code, MooseX::Daemonize->OK, '... got the right error code');
diag $$ if DEBUG;
ok($app->start, '... daemon started');
+is($app->status_message, "Start succeeded", '... got the correct status message');
+is($app->exit_code, MooseX::Daemonize->OK, '... got the right error code');
+
sleep(1); # give it a second ...
-ok($app->status, '... the daemon is running');
+ok(-e $app->pidfile->file, '... our pidfile exists' );
my $pid = $app->pidfile->pid;
isnt($pid, $$, '... the pid in our pidfile is correct (and not us)');
+ok($app->status, '... the daemon is running');
+is($app->status_message, "Daemon is running with pid ($pid)", '... got the correct status message');
+is($app->exit_code, MooseX::Daemonize->OK, '... got the right error code');
+
if (DEBUG) {
diag `ps $pid`;
diag "Status is: " . $app->status_message;
}
ok( -e $app->filename, "file exists" );
-ok($app->status, '... the daemon is still running');
if (DEBUG) {
diag `ps $pid`;
diag "Status is: " . $app->status_message;
}
-ok( $app->stop, 'app stopped' );
+ok( $app->stop, '... app stopped' );
+is($app->status_message, "Stop succeeded", '... got the correct status message');
+is($app->exit_code, MooseX::Daemonize->OK, '... got the right error code');
+
ok(!$app->status, '... the daemon is no longer running');
+is($app->status_message, "Daemon is not running with pid ($pid)", '... got the correct status message');
+is($app->exit_code, MooseX::Daemonize->ERROR, '... got the right error code');
if (DEBUG) {
diag `ps $pid`;
diag "Status is: " . $app->status_message;
}
-ok( not(-e $app->pidfile->file) , 'pidfile gone' );
+ok( not(-e $app->pidfile->file) , '... pidfile gone' );
unlink $FILENAME;
unlink $ENV{MX_DAEMON_STDOUT};