--- loncom/loncron 2018/08/07 17:12:09 1.107 +++ loncom/loncron 2018/10/29 02:46:41 1.111 @@ -2,7 +2,7 @@ # Housekeeping program, started by cron, loncontrol and loncron.pl # -# $Id: loncron,v 1.107 2018/08/07 17:12:09 raeburn Exp $ +# $Id: loncron,v 1.111 2018/10/29 02:46:41 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -113,17 +113,20 @@ sub checkon_daemon { my $result; &log($fh,'

'.$daemon.'

Log

'); printf("%-15s ",$daemon); - if (-e "$perlvar{'lonDaemons'}/logs/$daemon.log"){ - open (DFH,"tail -n25 $perlvar{'lonDaemons'}/logs/$daemon.log|"); - while (my $line=) { - &log($fh,"$line"); - if ($line=~/INFO/) { $notices++; } - if ($line=~/WARNING/) { $notices++; } - if ($line=~/CRITICAL/) { $warnings++; } - }; - close (DFH); + if ($fh) { + if (-e "$perlvar{'lonDaemons'}/logs/$daemon.log"){ + if (open(DFH,"tail -n25 $perlvar{'lonDaemons'}/logs/$daemon.log|")) { + while (my $line=) { + &log($fh,"$line"); + if ($line=~/INFO/) { $notices++; } + if ($line=~/WARNING/) { $notices++; } + if ($line=~/CRITICAL/) { $warnings++; } + } + close (DFH); + } + } + &log($fh,"

"); } - &log($fh,"

"); my $pidfile="$perlvar{'lonDaemons'}/logs/$daemon.pid"; @@ -169,7 +172,7 @@ sub checkon_daemon { &clean_lonc_childpids(); } &log($fh,"

$daemon not running, trying to start

"); - + if (&start_daemon($fh,$daemon,$pidfile,$args)) { &log($fh,"

$daemon at pid $daemonpid responding

"); $simplestatus{$daemon}='restarted'; @@ -194,17 +197,19 @@ sub checkon_daemon { &log($fh,"

Unable to start $daemon

"); } } - - if (-e "$perlvar{'lonDaemons'}/logs/$daemon.log"){ - &log($fh,"

");
-	    open (DFH,"tail -n100 $perlvar{'lonDaemons'}/logs/$daemon.log|");
-	    while (my $line=) { 
-		&log($fh,"$line");
-		if ($line=~/WARNING/) { $notices++; }
-		if ($line=~/CRITICAL/) { $notices++; }
-	    };
-	    close (DFH);
-	    &log($fh,"

"); + if ($fh) { + if (-e "$perlvar{'lonDaemons'}/logs/$daemon.log"){ + &log($fh,"

");
+	        if (open(DFH,"tail -n100 $perlvar{'lonDaemons'}/logs/$daemon.log|")) {
+	            while (my $line=) { 
+		        &log($fh,"$line");
+		        if ($line=~/WARNING/) { $notices++; }
+		        if ($line=~/CRITICAL/) { $notices++; }
+	            }
+	            close (DFH);
+                }
+	        &log($fh,"

"); + } } } @@ -1028,7 +1033,7 @@ sub update_revocation_list { } sub reset_nosslverify_pids { - my (%sslrem) = @_; + my ($fh,%sslrem) = @_; &checkon_daemon($fh,'lond',40000,'USR2'); my $loncpidfile="$perlvar{'lonDaemons'}/logs/lonc.pid"; my $loncppid; @@ -1057,8 +1062,8 @@ sub reset_nosslverify_pids { if ($sslrem{$host}) { if (ref($pids_by_host{$host}) eq 'HASH') { if (ref($pids_by_host{$host}{'insecure'}) eq 'HASH') { - if (keys($pids_by_host{$host}{'insecure'})) { - foreach my $pid (keys($pids_by_host{$host}{'insecure'})) { + if (keys(%{$pids_by_host{$host}{'insecure'}})) { + foreach my $pid (keys(%{$pids_by_host{$host}{'insecure'}})) { if (open(PIPE,"ps -o ppid= -p $pid |")) { my $ppid = ; chomp($ppid); @@ -1172,7 +1177,7 @@ sub main () { $hostname=~s/[^\w\.]//g; # make sure is safe to pass through shell my $subj="LON: Unconfigured machine $hostname"; system("echo 'Unconfigured machine $hostname.' |\ - mailto $emailto -s '$subj' > /dev/null"); + mail -s '$subj' $emailto > /dev/null"); exit 1; } @@ -1183,7 +1188,7 @@ sub main () { my $emailto="$perlvar{'lonAdmEMail'},$perlvar{'lonSysEMail'}"; my $subj="LON: $perlvar{'lonHostID'} User ID mismatch"; system("echo 'User ID mismatch. loncron must be run as user www.' |\ - mailto $emailto -s '$subj' > /dev/null"); + mail -s '$subj' $emailto > /dev/null"); exit 1; } @@ -1274,15 +1279,15 @@ sub main () { &write_serverhomeIDs(); &write_checksums(); my %sslrem = &clean_nosslverify($fh); - &finish_logging($fh); my %conchgs = &write_connection_config(); my %hosttypechgs = &write_hosttypes(); my $hadcrlchg = &update_revocation_list(); - if ((keys(%{$conchgs}) > 0) || (keys(%hosttypechgs) > 0) || + if ((keys(%conchgs) > 0) || (keys(%hosttypechgs) > 0) || $hadcrlchg || (keys(%sslrem) > 0)) { &checkon_daemon($fh,'lond',40000,'USR2'); - &reset_nosslverify_pids(%sslrem); + &reset_nosslverify_pids($fh,%sslrem); } + &finish_logging($fh); if ($totalcount>200 && !$noemail) { &send_mail(); } } }