diff --git a/lib/Daemon/Control.pm b/lib/Daemon/Control.pm index 891d3a0..0c7fb4c 100644 --- a/lib/Daemon/Control.pm +++ b/lib/Daemon/Control.pm @@ -230,11 +230,12 @@ sub do_stop { exit 1; } $self->pretty_print( "Stopped" ); - exit 0; } else { $self->pretty_print( "Not Running", "red" ); - exit 0; } + + # Clean up the PID file on stop. + unlink($self->pid_file) if $self->pid_file; } sub do_restart { @@ -253,10 +254,8 @@ sub do_status { if ( $self->pid && $self->pid_running ) { $self->pretty_print( "Running" ); - exit 0; } else { $self->pretty_print( "Not Running", "red" ); - exit 1; } } diff --git a/t/02_sleep_perl.t b/t/02_sleep_perl.t index 9dc82ab..cf7db08 100644 --- a/t/02_sleep_perl.t +++ b/t/02_sleep_perl.t @@ -38,4 +38,16 @@ sleep 10; ok $out = get_command_output( "perl -I$ilib $file status" ), "Get status of perl daemon."; ok $out =~ /Not Running/; +# Testing restart. +ok $out = get_command_output( "perl -I$ilib $file start" ), "Started system daemon"; +ok $out =~ /Started/, "Daemon started for restarting."; +ok $out = get_command_output( "perl -I$ilib $file status" ), "Get status of system daemon."; +ok $out =~ /Running/, "Daemon running for restarting."; +ok $out = get_command_output( "perl -I$ilib $file restart" ), "Get status of system daemon."; +ok $out =~ /stopped.*started/si, "Daemon restarted."; +ok $out = get_command_output( "perl -I$ilib $file status" ), "Get status of system daemon."; +ok $out =~ /Running/, "Daemon running after restart."; +ok $out = get_command_output( "perl -I$ilib $file stop" ), "Get status of system daemon."; +ok $out =~ /Stopped/, "Daemon stopped after restart."; + done_testing; diff --git a/t/02_sleep_system.t b/t/02_sleep_system.t index 0fe232a..c488b7a 100644 --- a/t/02_sleep_system.t +++ b/t/02_sleep_system.t @@ -38,4 +38,16 @@ sleep 10; ok $out = get_command_output( "perl -I$ilib $file status" ), "Get status of system daemon."; ok $out =~ /Not Running/; +# Testing restart. +ok $out = get_command_output( "perl -I$ilib $file start" ), "Started system daemon"; +ok $out =~ /Started/, "Daemon started for restarting"; +ok $out = get_command_output( "perl -I$ilib $file status" ), "Get status of system daemon."; +ok $out =~ /Running/, "Daemon running for restarting."; +ok $out = get_command_output( "perl -I$ilib $file restart" ), "Get status of system daemon."; +ok $out =~ /stopped.*started/si, "Daemon restarted."; +ok $out = get_command_output( "perl -I$ilib $file status" ), "Get status of system daemon."; +ok $out =~ /Running/, "Daemon running after restart."; +ok $out = get_command_output( "perl -I$ilib $file stop" ), "Get status of system daemon."; +ok $out =~ /Stopped/, "Daemon stopped after restart."; + done_testing; diff --git a/t/bin/02_sleep_perl.pl b/t/bin/02_sleep_perl.pl index 8d34c02..4f51297 100644 --- a/t/bin/02_sleep_perl.pl +++ b/t/bin/02_sleep_perl.pl @@ -14,7 +14,7 @@ Daemon::Control->new({ program => sub { sleep $_[1] }, program_args => [ 10 ], - pid_file => '/dev/null', # I don't want to leave tmp files for testing. + pid_file => 'pid_tmp', stderr_file => '/dev/null', stdout_file => '/dev/null', diff --git a/t/bin/02_sleep_system.pl b/t/bin/02_sleep_system.pl index ce97a9a..a76032d 100644 --- a/t/bin/02_sleep_system.pl +++ b/t/bin/02_sleep_system.pl @@ -14,7 +14,8 @@ Daemon::Control->new({ program => 'sleep', program_args => [ 10 ], - pid_file => '/dev/null', # I don't want to leave tmp files for testing. + pid_file => 'pid_tmp', + stderr_file => '/dev/null', stdout_file => '/dev/null',