sub start_stop {
my $daemon = shift;
- my $pid = $pids->{$daemon} || 'not started';
+ my $pid = $pids->{$daemon};
+ my $pid_path = "$server::conf/$daemon.pid";
+
+ if ( ! $pid && -e $pid_path ) {
+ my $p = read_file $pid_path;
+ if ( kill 0, $p ) {
+ warn "adopted $daemon $p\n";
+ return $pids->{$daemon} = $p;
+ } else {
+ warn "old $daemon $p not running";
+ unlink $pid_path;
+ }
+ }
+
+ $pid ||= 'not started';
warn "start_stop $daemon $pid\n";
if ( $pid =~ m{^\d+$} ) {
if ( $pid = fork ) {
# parent
$pids->{$daemon} = $pid;
+ write_file $pid_path, $pid;
warn "forked $daemon $pid\n";
return qq|$daemon pid $pid started|;
} elsif ( defined $pid ) {