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:
parent
33411539ee
commit
83d5f55b09
1 changed files with 13 additions and 1 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue