Merge pull request #892 from ZoneMinder/zmwatch_cleanup3

improve debugging for analysis check and restart if can't read shared data
This commit is contained in:
Andrew Bauer 2015-06-23 08:16:11 -05:00
commit 951f13c82a
1 changed files with 28 additions and 17 deletions

View File

@ -133,14 +133,19 @@ while( 1 )
} }
elsif ( $monitor->{Function} ne 'Monitor' ) elsif ( $monitor->{Function} ne 'Monitor' )
{ {
if ( zmMemVerify( $monitor ) # Now check analysis daemon
&& zmMemRead( $monitor, "shared_data:valid" ) $restart = 0;
) # Check we have got an image recently
{ my $image_time = zmGetLastReadTime( $monitor );
# Check we have got an image recently if ( !defined($image_time) ) {
my $image_time = zmGetLastReadTime( $monitor ); # Can't read from shared data
next if ( !defined($image_time) ); # Can't read from shared data $restart = 1;
next if ( !$image_time ); # We can't get the last capture time so can't be sure it's died. Error( "Error reading shared data for $$monitor{id} $$monitor{Name}\n");
} elsif ( !$image_time ) {
# We can't get the last capture time so can't be sure it's died.
$restart = 1;
Error( "Error getting last capture time for $$monitor{id} $$monitor{Name}\n");
} else {
my $max_image_delay = ( $monitor->{MaxFPS} my $max_image_delay = ( $monitor->{MaxFPS}
&&($monitor->{MaxFPS}>0) &&($monitor->{MaxFPS}>0)
@ -152,18 +157,24 @@ while( 1 )
Debug( "Monitor $monitor->{Id} last analysed $image_delay seconds ago, max is $max_image_delay\n" ); Debug( "Monitor $monitor->{Id} last analysed $image_delay seconds ago, max is $max_image_delay\n" );
if ( $image_delay > $max_image_delay ) if ( $image_delay > $max_image_delay )
{ {
Info( "Restarting analysis daemon for " Info( "Analysis daemon for $$monitor{id} $$monitor{Name} needs restarting,"
.$monitor->{Name}.", time since last analysis $image_delay seconds ($now-$image_time)\n" ." time since last analysis $image_delay seconds ($now-$image_time)\n"
); );
my $command = "zmdc.pl restart zma -m ".$monitor->{Id}; $restart = 1;
runCommand( $command );
} }
} }
}
} if ( $restart )
# Prevent open handles building up if we have connect to shared memory {
zmMemInvalidate( $monitor ); Info( "Restarting analysis daemon for $$monitor{id} $$monitor{Name}\n");
my $command = "zmdc.pl restart zma -m ".$monitor->{Id};
runCommand( $command );
} # end if restart
} # end if check analysis daemon
# Prevent open handles building up if we have connect to shared memory
zmMemInvalidate( $monitor );
} # end foreach monitor
sleep( $Config{ZM_WATCH_CHECK_INTERVAL} ); sleep( $Config{ZM_WATCH_CHECK_INTERVAL} );
} } # end while (1)
Info( "Watchdog exiting\n" ); Info( "Watchdog exiting\n" );
exit(); exit();