This commit is contained in:
Isaac Connor 2021-08-30 13:32:43 -04:00
parent 6b481fa2b5
commit 1a0d488457
1 changed files with 18 additions and 19 deletions

View File

@ -98,19 +98,19 @@ while (!$zm_terminate) {
next if $monitor->{Type} eq 'WebSite'; next if $monitor->{Type} eq 'WebSite';
my $now = time(); my $now = time();
my $restart = 0; my $restart = 0;
if ( zmMemVerify($monitor) ) { if (zmMemVerify($monitor)) {
# Check we have got an image recently # Check we have got an image recently
my $capture_time = zmGetLastWriteTime($monitor); my $capture_time = zmGetLastWriteTime($monitor);
if ( !defined($capture_time) ) { if (!defined($capture_time)) {
# Can't read from shared data # Can't read from shared data
Debug('LastWriteTime is not defined.'); Debug('LastWriteTime is not defined.');
zmMemInvalidate($monitor); zmMemInvalidate($monitor);
next; next;
} }
Debug("Monitor $$monitor{Id} LastWriteTime is $capture_time."); Debug("Monitor $$monitor{Id} LastWriteTime is $capture_time.");
if ( !$capture_time ) { if (!$capture_time) {
my $startup_time = zmGetStartupTime($monitor); my $startup_time = zmGetStartupTime($monitor);
if ( ( $now - $startup_time ) > $Config{ZM_WATCH_MAX_DELAY} ) { if (($now - $startup_time) > $Config{ZM_WATCH_MAX_DELAY}) {
Warning( Warning(
"Restarting capture daemon for $$monitor{Name}, no image since startup. ". "Restarting capture daemon for $$monitor{Name}, no image since startup. ".
"Startup time was $startup_time - now $now > $Config{ZM_WATCH_MAX_DELAY}" "Startup time was $startup_time - now $now > $Config{ZM_WATCH_MAX_DELAY}"
@ -122,7 +122,7 @@ while (!$zm_terminate) {
next; next;
} }
} }
if ( ! $restart ) { if (!$restart) {
my $max_image_delay = ( my $max_image_delay = (
$monitor->{MaxFPS} $monitor->{MaxFPS}
&&($monitor->{MaxFPS}>0) &&($monitor->{MaxFPS}>0)
@ -144,29 +144,28 @@ while (!$zm_terminate) {
$restart = 1; $restart = 1;
} }
if ( $restart ) { if ($restart) {
my $command; my $command;
if ( $monitor->{Type} eq 'Local' ) { if ($monitor->{Type} eq 'Local') {
$command = "zmdc.pl restart zmc -d $monitor->{Device}"; $command = 'zmdc.pl restart zmc -d '.$monitor->{Device};
} else { } else {
$command = "zmdc.pl restart zmc -m $monitor->{Id}"; $command = 'zmdc.pl restart zmc -m '.$monitor->{Id};
} }
runCommand($command); runCommand($command);
} elsif ( $monitor->{Function} ne 'Monitor' ) { } elsif ($monitor->{Function} ne 'Monitor') {
# Now check analysis daemon # Now check analysis daemon
$restart = 0; $restart = 0;
# Check we have got an image recently # Check we have got an image recently
my $image_time = zmGetLastReadTime($monitor); my $image_time = zmGetLastReadTime($monitor);
if ( !defined($image_time) ) { if (!defined($image_time)) {
# Can't read from shared data # Can't read from shared data
$restart = 1; $restart = 1;
Error("Error reading shared data for $$monitor{Id} $$monitor{Name}"); Error("Error reading shared data for $$monitor{Id} $$monitor{Name}");
} elsif ( !$image_time ) { } elsif (!$image_time) {
# We can't get the last capture time so can't be sure it's died. # We can't get the last capture time so can't be sure it's died.
#$restart = 1; #$restart = 1;
Error("Last analyse time for $$monitor{Id} $$monitor{Name} was zero."); Error("Last analyse time for $$monitor{Id} $$monitor{Name} was zero.");
} else { } else {
my $max_image_delay = ( $monitor->{MaxFPS} my $max_image_delay = ( $monitor->{MaxFPS}
&&($monitor->{MaxFPS}>0) &&($monitor->{MaxFPS}>0)
&&($monitor->{MaxFPS}<1) &&($monitor->{MaxFPS}<1)
@ -175,7 +174,7 @@ while (!$zm_terminate) {
; ;
my $image_delay = $now-$image_time; my $image_delay = $now-$image_time;
Debug("Monitor $monitor->{Id} last analysed $image_delay seconds ago, max is $max_image_delay"); Debug("Monitor $monitor->{Id} last analysed $image_delay seconds ago, max is $max_image_delay");
if ( $image_delay > $max_image_delay ) { if ($image_delay > $max_image_delay) {
Warning("Analysis daemon for $$monitor{Id} $$monitor{Name} needs restarting," Warning("Analysis daemon for $$monitor{Id} $$monitor{Name} needs restarting,"
." time since last analysis $image_delay seconds ($now-$image_time)" ." time since last analysis $image_delay seconds ($now-$image_time)"
); );
@ -183,13 +182,13 @@ while (!$zm_terminate) {
} }
} }
if ( $restart ) { if ($restart) {
Info("Restarting analysis daemon for $$monitor{Id} $$monitor{Name}\n"); Info("Restarting analysis daemon for $$monitor{Id} $$monitor{Name}");
my $command; my $command;
if ( $monitor->{Type} eq 'Local' ) { if ( $monitor->{Type} eq 'Local' ) {
$command = "zmdc.pl restart zmc -d $monitor->{Device}"; $command = 'zmdc.pl restart zmc -d '.$monitor->{Device};
} else { } else {
$command = "zmdc.pl restart zmc -m $monitor->{Id}"; $command = 'zmdc.pl restart zmc -m '.$monitor->{Id};
} }
runCommand($command); runCommand($command);
} # end if restart } # end if restart
@ -201,7 +200,7 @@ while (!$zm_terminate) {
sleep($Config{ZM_WATCH_CHECK_INTERVAL}); sleep($Config{ZM_WATCH_CHECK_INTERVAL});
} # end while (!$zm_terminate) } # end while (!$zm_terminate)
Info("Watchdog exiting"); Info('Watchdog exiting');
exit(); exit();
1; 1;