--- lib/PXElator/httpd.pm 2009/08/09 19:00:52 181 +++ lib/PXElator/httpd.pm 2009/08/09 20:46:00 184 @@ -113,8 +113,22 @@ 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+$} ) { @@ -128,6 +142,7 @@ 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 ) {