32 |
CouchDB::audit( $msg, $daemon, { daemon => $daemon, message => $msg, @_ } ); |
CouchDB::audit( $msg, $daemon, { daemon => $daemon, message => $msg, @_ } ); |
33 |
} |
} |
34 |
|
|
35 |
|
mkdir "$server::conf/pid" unless -d "$server::conf/pid"; |
36 |
|
|
37 |
sub start_stop { |
sub start_stop { |
38 |
my $daemon = shift; |
my $daemon = shift; |
39 |
|
|
40 |
my $pid = $pids->{$daemon}; |
my $pid = $pids->{$daemon}; |
41 |
my $pid_path = "$daemon.pid"; |
my $pid_path = $daemon; |
42 |
$pid_path =~ s{/}{-}g; |
$pid_path =~ s{/}{-}g; |
43 |
$pid_path = "$server::conf/$pid_path"; |
$pid_path = "$server::conf/pid/$pid_path"; |
44 |
|
|
45 |
if ( ! $pid && -e $pid_path ) { |
if ( ! $pid && -e $pid_path ) { |
46 |
my $p = read_file $pid_path; |
my $p = read_file $pid_path; |
56 |
$pid ||= 'not started'; |
$pid ||= 'not started'; |
57 |
warn "start_stop $daemon $pid\n"; |
warn "start_stop $daemon $pid\n"; |
58 |
|
|
59 |
if ( $pid =~ m{^\d+$} ) { |
if ( $pid =~ m{^\d+$} && kill 0, $pid ) { |
60 |
my $pstree = `pstree -p $pid`; |
my $pstree = `pstree -p $pid`; |
61 |
my @pids = $pstree =~ m{\((\d+)\)}g; |
my @pids = $pstree =~ m{\((\d+)\)}g; |
62 |
warn "pstree $pstree pids ",dump( @pids ); |
warn "pstree $pstree pids ",dump( @pids ); |
63 |
kill 1, $_ foreach reverse @pids; |
foreach ( @pids ) { |
64 |
|
warn "kill $_\n"; |
65 |
|
kill 1, $_; |
66 |
|
if ( kill 0, $_ ) { |
67 |
|
warn "kill 9 $_"; |
68 |
|
kill 9, $_; |
69 |
|
} |
70 |
|
} |
71 |
$pids->{$daemon} = 'stopped'; |
$pids->{$daemon} = 'stopped'; |
72 |
audit 'stopped', $daemon, pid => $pid; |
audit 'stopped', $daemon, pid => $pid; |
73 |
return qq|$daemon pid $pid stopped|; |
return qq|$daemon pid $pid stopped|; |
82 |
# child |
# child |
83 |
my $invoke = 'start'; |
my $invoke = 'start'; |
84 |
$invoke = $1 if $daemon =~ s{/(.+)}{}; |
$invoke = $1 if $daemon =~ s{/(.+)}{}; |
85 |
if ( $daemon =~ m{dhcpd|tftpd|dnsd} ) { |
if ( $daemon =~ m{dhcpd|tftpd|dnsd|syslogd} ) { |
86 |
my $exec = "perl -I$server::base_dir/lib -I$server::base_dir/lib/PXElator -M$daemon -e ${daemon}::${invoke}"; |
my $exec = "perl -I$server::base_dir/lib -I$server::base_dir/lib/PXElator -M$daemon -e ${daemon}::${invoke}"; |
87 |
audit 'exec', $daemon, 'exec' => $exec; |
audit 'exec', $daemon, 'exec' => $exec; |
88 |
x11::xterm( $daemon => $exec ); |
x11::xterm( $daemon => $exec ); |