Subject: | Daemon::Generic as init script not LSB conformant |
Daemon::Generic has some init script semantics, but is not LSB
conformant which for example makes it unusable in combination with
heartbeat. The attached patch tries to improve the situation by
providing a status action and correct exit codes. It also cleans up the
pid file on stopping the daemon.
It is incompatible with the current version in so far as the exit code
of the start action got changed to 0 in case the daemon is already
running.
Subject: | Daemon_Generic_lsb.diff |
--- Generic.pm 2008-06-03 23:09:45.000000000 +0200
+++ Generic.pm.new 2008-06-03 23:09:21.000000000 +0200
@@ -98,6 +98,10 @@
if (-e $pidfile) {
if ($locked = lock($pidfile, undef, 'nonblocking')) {
# old process is dead
+ if ($do eq 'status') {
+ print "$0 dead\n";
+ exit 1;
+ }
} else {
sleep(2) if -M $pidfile < 2/86400;
my $oldpid = read_file($pidfile);
@@ -105,8 +109,11 @@
if ($oldpid) {
if ($do eq 'stop' or $do eq 'restart') {
$killed = $self->gd_kill($oldpid);
- exit if $do eq 'stop';
$locked = lock($pidfile);
+ if ($do eq 'stop') {
+ unlink($pidfile);
+ exit;
+ }
} elsif ($do eq 'reload') {
if (kill(1,$oldpid)) {
print "Requested reconfiguration\n";
@@ -114,6 +121,15 @@
} else {
print "Kill failed: $!\n";
}
+ } elsif ($do eq 'status') {
+ if (kill(0,$oldpid)) {
+ print "$0 running - pid $oldpid\n";
+ $self->gd_check($pidfile, $oldpid);
+ exit 0;
+ } else {
+ print "$0 dead\n";
+ exit 1;
+ }
} elsif ($do eq 'check') {
if (kill(0,$oldpid)) {
print "$0 running - pid $oldpid\n";
@@ -122,7 +138,7 @@
}
} elsif ($do eq 'start') {
print "\u$self->{gd_progname} is already running (pid $oldpid)\n";
- exit(3);
+ exit; # according to LSB, this is no error
}
} else {
$self->gd_error("Pid file $pidfile is invalid but locked, exiting\n");
@@ -137,7 +153,16 @@
print "No $0 running\n";
}
- exit if $do eq 'stop';
+ if ($do eq 'stop') {
+ unlink($pidfile);
+ exit;
+ }
+
+ if ($do eq 'status') {
+ print "Unused\n";
+ exit 3;
+ }
+
if ($do eq 'check') {
$self->gd_check($pidfile);
exit