fix problem causing processes to not be restarted. Also, tabs to spaces

pull/847/head
Isaac Connor 2015-06-22 13:37:26 -04:00
parent 47192156cd
commit 612e96bbfe
1 changed files with 34 additions and 34 deletions

View File

@ -507,10 +507,11 @@ sub start
# Sends the stop signal, without waiting around to see if the process died. # Sends the stop signal, without waiting around to see if the process died.
sub send_stop { sub send_stop {
my ( $final, $process ) = @_; my ( $final, $process ) = @_;
my $command = $process->{command}; my $command = $process->{command};
if ( $process->{pending} ) { if ( $process->{pending} ) {
delete( $cmd_hash{$command} ); delete( $cmd_hash{$command} );
dPrint( ZoneMinder::Logger::INFO, "Command '$command' removed from pending list at " dPrint( ZoneMinder::Logger::INFO, "Command '$command' removed from pending list at "
.strftime( '%y/%m/%d %H:%M:%S', localtime() ) .strftime( '%y/%m/%d %H:%M:%S', localtime() )
@ -532,43 +533,43 @@ sub send_stop {
); );
$process->{keepalive} = !$final; $process->{keepalive} = !$final;
kill( 'TERM', $pid ); kill( 'TERM', $pid );
return $pid; return $pid;
} # end sub send_stop } # end sub send_stop
sub kill_until_dead { sub kill_until_dead {
my ( $process ) = @_; my ( $process ) = @_;
# Now check it has actually gone away, if not kill -9 it # Now check it has actually gone away, if not kill -9 it
my $count = 0; my $count = 0;
while( $process and $$process{pid} and kill( 0, $$process{pid} ) ) while( $process and $$process{pid} and kill( 0, $$process{pid} ) )
{ {
if ( $count++ > 5 ) if ( $count++ > 5 )
{ {
dPrint( ZoneMinder::Logger::WARNING, "'$$process{command}' has not stopped at " dPrint( ZoneMinder::Logger::WARNING, "'$$process{command}' has not stopped at "
.strftime( '%y/%m/%d %H:%M:%S', localtime() ) .strftime( '%y/%m/%d %H:%M:%S', localtime() )
.". Sending KILL to pid $$process{pid}\n" .". Sending KILL to pid $$process{pid}\n"
); );
kill( 'KILL', $$process{pid} ); kill( 'KILL', $$process{pid} );
} }
sleep( 1 ); sleep( 1 );
} }
} }
sub _stop { sub _stop {
my ($final, $process ) = @_; my ($final, $process ) = @_;
my $pid = send_stop( $final, $process );
return if ! $pid;
kill_until_dead( $process );
delete( $cmd_hash{$$process{command}} ); delete( $cmd_hash{$$process{command}} );
my $pid = send_stop( $final, $process );
return if ! $pid;
kill_until_dead( $process );
} }
sub stop sub stop
{ {
my ( $daemon, @args ) = @_; my ( $daemon, @args ) = @_;
my $command = join(' ', $daemon, @args ); my $command = join(' ', $daemon, @args );
my $process = $cmd_hash{$command}; my $process = $cmd_hash{$command};
if ( !$process ) if ( !$process )
{ {
dPrint( ZoneMinder::Logger::WARNING, "Can't find process with command of '$command'\n" ); dPrint( ZoneMinder::Logger::WARNING, "Can't find process with command of '$command'\n" );
@ -654,7 +655,7 @@ sub reaper
my $exit_signal = $status&0xfe; my $exit_signal = $status&0xfe;
my $core_dumped = $status&0x01; my $core_dumped = $status&0x01;
my $out_str = "'$process->{daemon} ".join( ' ', @{$process->{args}} )."' "; my $out_str = "'$process->{command}' ";
if ( $exit_signal ) if ( $exit_signal )
{ {
if ( $exit_signal == 15 || $exit_signal == 14 ) # TERM or ALRM if ( $exit_signal == 15 || $exit_signal == 14 ) # TERM or ALRM
@ -693,17 +694,16 @@ sub reaper
if ( $process->{keepalive} ) if ( $process->{keepalive} )
{ {
# Schedule for immediate restart
$cmd_hash{$process->{command}} = $process;
if ( !$process->{delay} || ($process->{runtime} > $Config{ZM_MAX_RESTART_DELAY} ) ) if ( !$process->{delay} || ($process->{runtime} > $Config{ZM_MAX_RESTART_DELAY} ) )
{ {
#start( $process->{daemon}, @{$process->{args}} ); #start( $process->{daemon}, @{$process->{args}} );
# Schedule for immediate restart
$cmd_hash{$process->{command}} = $process;
$process->{pending} = $process->{stopped}; $process->{pending} = $process->{stopped};
$process->{delay} = 5; $process->{delay} = 5;
} }
else else
{ {
$cmd_hash{$process->{command}} = $process;
$process->{pending} = $process->{stopped}+$process->{delay}; $process->{pending} = $process->{stopped}+$process->{delay};
$process->{delay} *= 2; $process->{delay} *= 2;
# Limit the start delay to 15 minutes max # Limit the start delay to 15 minutes max
@ -733,20 +733,20 @@ sub restartPending
sub shutdownAll sub shutdownAll
{ {
foreach my $pid ( keys %pid_hash ) { foreach my $pid ( keys %pid_hash ) {
# This is a quick fix because a SIGCHLD can happen and alter pid_hash while we are in here. # This is a quick fix because a SIGCHLD can happen and alter pid_hash while we are in here.
next if ! $pid_hash{$pid}; next if ! $pid_hash{$pid};
send_stop( 1, $pid_hash{$pid} ); send_stop( 1, $pid_hash{$pid} );
} }
foreach my $pid ( keys %pid_hash ) { foreach my $pid ( keys %pid_hash ) {
# This is a quick fix because a SIGCHLD can happen and alter pid_hash while we are in here. # This is a quick fix because a SIGCHLD can happen and alter pid_hash while we are in here.
next if ! $pid_hash{$pid}; next if ! $pid_hash{$pid};
my $process = $pid_hash{$pid}; my $process = $pid_hash{$pid};
kill_until_dead( $process ); kill_until_dead( $process );
delete( $cmd_hash{$$process{command}} ); delete( $cmd_hash{$$process{command}} );
delete( $pid_hash{$pid} ); delete( $pid_hash{$pid} );
} }
killAll( 5 ); killAll( 5 );
dPrint( ZoneMinder::Logger::INFO, "Server shutdown at " dPrint( ZoneMinder::Logger::INFO, "Server shutdown at "
@ -860,8 +860,8 @@ sub killAll
if ( 'linux' eq 'BSD' ) if ( 'linux' eq 'BSD' )
{ {
$killall = 'killall -'; $killall = 'killall -';
} elsif ( 'linux' eq 'solaris' ) { } elsif ( 'linux' eq 'solaris' ) {
$killall = 'pkill -'; $killall = 'pkill -';
} else { } else {
$killall = 'killall -q -s '; $killall = 'killall -q -s ';
} }