PID files contain the PID so that on next run, we can test to see

if that PID is still alive.  If it isn't, the daemon was kill -9'd,
the system crashed, or similar.  It isn't running any more and it's
safe to start up again.  Don't die on startup unless the PID in the
PID file is valid.
This commit is contained in:
Scott Walters 2010-05-19 07:52:43 -04:00
parent 33411539ee
commit 83d5f55b09

View file

@ -114,8 +114,20 @@ elsif ($daemon) {
die "Spectre is already running.\n";
}
elsif (-e $pidFileName){
die "pidFile $pidFileName already exists\n";
# oh, ffs ... die "pidFile $pidFileName already exists\n";
open my $pidFile, '<', $pidFileName or die "$pidFileName: $!";
(my $pid) = readline $pidFile;
chomp $pid;
if(defined $pid and $pid =~ m/^(\d+)$/) {
if(kill 0, $1) {
die "$0: already running as PID $1";
} else {
warn "pidfile contains $pid but that process seems to have terminated"
}
}
close $pidFile;
}
# XXXX warn if we can't open the log file before forking or else make it not fatal or else close STDOUT/STDERR afterwards; don't fail silently -- sdw
#fork and exit(sleep(1) and print((ping())?"Spectre failed to start!\n":"Spectre started successfully!\n")); #Can't have right now.
require POSIX;
fork and exit;