From c98339e152e4b813b5459a9f140e2ccffb6c7ed5 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Thu, 24 May 2018 10:49:20 -0400 Subject: [PATCH] Google code style, list monitor in debug line listing LastWriteTime --- scripts/zmwatch.pl.in | 67 ++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/scripts/zmwatch.pl.in b/scripts/zmwatch.pl.in index 61104f55f..b98b9d22a 100644 --- a/scripts/zmwatch.pl.in +++ b/scripts/zmwatch.pl.in @@ -69,41 +69,44 @@ delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; logInit(); logSetSignal(); -Info( "Watchdog starting, pausing for ".START_DELAY." seconds\n" ); -sleep( START_DELAY ); +Info('Watchdog starting, pausing for '.START_DELAY.' seconds'); +sleep(START_DELAY); my $dbh = zmDbConnect(); my $sql = $Config{ZM_SERVER_ID} ? 'SELECT * FROM Monitors WHERE ServerId=?' : 'SELECT * FROM Monitors'; -my $sth = $dbh->prepare_cached( $sql ) - or Fatal( "Can't prepare '$sql': ".$dbh->errstr() ); +my $sth = $dbh->prepare_cached($sql) + or Fatal("Can't prepare '$sql': ".$dbh->errstr()); while( 1 ) { my $res = $sth->execute( $Config{ZM_SERVER_ID} ? $Config{ZM_SERVER_ID} : () ) - or Fatal( "Can't execute: ".$sth->errstr() ); + or Fatal('Can\'t execute: '.$sth->errstr()); while( my $monitor = $sth->fetchrow_hashref() ) { - my $now = time(); next if $monitor->{Function} eq 'None'; next if $monitor->{Type} eq 'WebSite'; + my $now = time(); my $restart = 0; - if ( zmMemVerify( $monitor ) ) { + if ( zmMemVerify($monitor) ) { # Check we have got an image recently - my $capture_time = zmGetLastWriteTime( $monitor ); + my $capture_time = zmGetLastWriteTime($monitor); if ( !defined($capture_time) ) { # Can't read from shared data - Debug( "LastWriteTime is not defined." ); - zmMemInvalidate( $monitor ); + Debug('LastWriteTime is not defined.'); + zmMemInvalidate($monitor); next; } - Debug( "LastWriteTime is = $capture_time." ); + Debug("Monitor $$monitor{Id} LastWriteTime is $capture_time."); if ( !$capture_time ) { - my $startup_time = zmGetStartupTime( $monitor ); + my $startup_time = zmGetStartupTime($monitor); if ( $now - $startup_time > $Config{ZM_WATCH_MAX_DELAY} ) { - Info( "Restarting capture daemon for ".$monitor->{Name}.", no image since startup. Startup time was $startup_time - now $now > $Config{ZM_WATCH_MAX_DELAY}\n" ); + Info( + "Restarting capture daemon for $$monitor{Name}, no image since startup. ". + "Startup time was $startup_time - now $now > $Config{ZM_WATCH_MAX_DELAY}" + ); $restart = 1; } else { # We can't get the last capture time so can't be sure it's died, it might just be starting up. - zmMemInvalidate( $monitor ); + zmMemInvalidate($monitor); next; } } @@ -115,44 +118,44 @@ while( 1 ) { : $Config{ZM_WATCH_MAX_DELAY} ; my $image_delay = $now-$capture_time; - Debug( "Monitor $monitor->{Id} last captured $image_delay seconds ago, max is $max_image_delay\n" ); + Debug("Monitor $monitor->{Id} last captured $image_delay seconds ago, max is $max_image_delay"); if ( $image_delay > $max_image_delay ) { - Info( "Restarting capture daemon for " - .$monitor->{Name}.", time since last capture $image_delay seconds ($now-$capture_time)\n" + Info("Restarting capture daemon for " + .$monitor->{Name}.", time since last capture $image_delay seconds ($now-$capture_time)" ); $restart = 1; } } # end if ! restart } else { - Info( "Restarting capture daemon for ".$monitor->{Name}.", shared data not valid\n" ); + Info("Restarting capture daemon for $monitor->{Name}, shared data not valid"); $restart = 1; } if ( $restart ) { # Because zma depends on zmc, and zma can hold the shm in place, preventing zmc from using the space in /dev/shm, # we need to stop zma before restarting zmc. - runCommand( "zmdc.pl stop zma -m $$monitor{Id}" ) if $monitor->{Function} ne 'Monitor'; + runCommand("zmdc.pl stop zma -m $$monitor{Id}") if $monitor->{Function} ne 'Monitor'; my $command; if ( $monitor->{Type} eq 'Local' ) { $command = "zmdc.pl restart zmc -d $monitor->{Device}"; } else { $command = "zmdc.pl restart zmc -m $monitor->{Id}"; } - runCommand( $command ); - runCommand( "zmdc.pl start zma -m $$monitor{Id}" ) if $monitor->{Function} ne 'Monitor'; + runCommand($command); + runCommand("zmdc.pl start zma -m $$monitor{Id}") if $monitor->{Function} ne 'Monitor'; } elsif ( $monitor->{Function} ne 'Monitor' ) { # Now check analysis daemon $restart = 0; # Check we have got an image recently - my $image_time = zmGetLastReadTime( $monitor ); + my $image_time = zmGetLastReadTime($monitor); if ( !defined($image_time) ) { # Can't read from shared data $restart = 1; - Error("Error reading shared data for $$monitor{Id} $$monitor{Name}\n"); + Error("Error reading shared data for $$monitor{Id} $$monitor{Name}"); } elsif ( !$image_time ) { # We can't get the last capture time so can't be sure it's died. $restart = 1; - Error("Last analyse time for $$monitor{Id} $$monitor{Name} was zero.\n"); + Error("Last analyse time for $$monitor{Id} $$monitor{Name} was zero."); } else { my $max_image_delay = ( $monitor->{MaxFPS} @@ -162,29 +165,29 @@ while( 1 ) { : $Config{ZM_WATCH_MAX_DELAY} ; my $image_delay = $now-$image_time; - 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"); if ( $image_delay > $max_image_delay ) { - Info( "Analysis daemon for $$monitor{Id} $$monitor{Name} needs restarting," - ." time since last analysis $image_delay seconds ($now-$image_time)\n" + Info("Analysis daemon for $$monitor{Id} $$monitor{Name} needs restarting," + ." time since last analysis $image_delay seconds ($now-$image_time)" ); $restart = 1; } } if ( $restart ) { - Info( "Restarting analysis daemon for $$monitor{Id} $$monitor{Name}\n"); + Info("Restarting analysis daemon for $$monitor{Id} $$monitor{Name}"); my $command = 'zmdc.pl restart zma -m '.$monitor->{Id}; - runCommand( $command ); + runCommand($command); } # end if restart } # end if check analysis daemon # Prevent open handles building up if we have connect to shared memory - zmMemInvalidate( $monitor ); # Close our file handle to the zmc process we are about to end + zmMemInvalidate($monitor); # Close our file handle to the zmc process we are about to end } # 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"); exit(); 1;