113 |
|
|
114 |
sub start_stop { |
sub start_stop { |
115 |
my $daemon = shift; |
my $daemon = shift; |
|
my $pid = $pids->{$daemon} || 'not started'; |
|
116 |
|
|
117 |
|
my $pid = $pids->{$daemon}; |
118 |
|
my $pid_path = "$server::conf/$daemon.pid"; |
119 |
|
|
120 |
|
if ( ! $pid && -e $pid_path ) { |
121 |
|
my $p = read_file $pid_path; |
122 |
|
if ( kill 0, $p ) { |
123 |
|
warn "adopted $daemon $p\n"; |
124 |
|
return $pids->{$daemon} = $p; |
125 |
|
} else { |
126 |
|
warn "old $daemon $p not running"; |
127 |
|
unlink $pid_path; |
128 |
|
} |
129 |
|
} |
130 |
|
|
131 |
|
$pid ||= 'not started'; |
132 |
warn "start_stop $daemon $pid\n"; |
warn "start_stop $daemon $pid\n"; |
133 |
|
|
134 |
if ( $pid =~ m{^\d+$} ) { |
if ( $pid =~ m{^\d+$} ) { |
142 |
if ( $pid = fork ) { |
if ( $pid = fork ) { |
143 |
# parent |
# parent |
144 |
$pids->{$daemon} = $pid; |
$pids->{$daemon} = $pid; |
145 |
|
write_file $pid_path, $pid; |
146 |
warn "forked $daemon $pid\n"; |
warn "forked $daemon $pid\n"; |
147 |
return qq|$daemon pid $pid started|; |
return qq|$daemon pid $pid started|; |
148 |
} elsif ( defined $pid ) { |
} elsif ( defined $pid ) { |