10 |
use CouchDB; |
use CouchDB; |
11 |
|
|
12 |
our $pids; |
our $pids; |
13 |
$pids = { httpd => $$, kvm => 'not started' } unless defined $pids; # keep pids on refresh |
$pids = { |
14 |
|
httpd => $$, |
15 |
|
kvm => 'not started', |
16 |
|
wireshark => 'not started', |
17 |
|
} unless defined $pids; # keep pids on refresh |
18 |
|
|
19 |
sub DESTROY { |
sub DESTROY { |
20 |
warn "pids ",dump( $pids ); |
warn "pids ",dump( $pids ); |
36 |
my $daemon = shift; |
my $daemon = shift; |
37 |
|
|
38 |
my $pid = $pids->{$daemon}; |
my $pid = $pids->{$daemon}; |
39 |
my $pid_path = "$server::conf/$daemon.pid"; |
my $pid_path = "$daemon.pid"; |
40 |
|
$pid_path =~ s{/}{-}g; |
41 |
|
$pid_path = "$server::conf/$pid_path"; |
42 |
|
|
43 |
if ( ! $pid && -e $pid_path ) { |
if ( ! $pid && -e $pid_path ) { |
44 |
my $p = read_file $pid_path; |
my $p = read_file $pid_path; |
58 |
my $pstree = `pstree -p $pid`; |
my $pstree = `pstree -p $pid`; |
59 |
my @pids = $pstree =~ m{\((\d+)\)}g; |
my @pids = $pstree =~ m{\((\d+)\)}g; |
60 |
warn "pstree $pstree pids ",dump( @pids ); |
warn "pstree $pstree pids ",dump( @pids ); |
61 |
kill 1, $_ foreach reverse @pids; |
foreach ( @pids ) { |
62 |
|
warn "kill $_\n"; |
63 |
|
kill 1, $_; |
64 |
|
if ( kill 0, $_ ) { |
65 |
|
warn "kill 9 $_"; |
66 |
|
kill 9, $_; |
67 |
|
} |
68 |
|
} |
69 |
$pids->{$daemon} = 'stopped'; |
$pids->{$daemon} = 'stopped'; |
70 |
audit 'stopped', $daemon, pid => $pid; |
audit 'stopped', $daemon, pid => $pid; |
71 |
return qq|$daemon pid $pid stopped|; |
return qq|$daemon pid $pid stopped|; |