--- loncom/loncron 2013/05/29 18:10:54 1.99 +++ loncom/loncron 2014/12/16 18:18:44 1.101 @@ -2,7 +2,7 @@ # Housekeeping program, started by cron, loncontrol and loncron.pl # -# $Id: loncron,v 1.99 2013/05/29 18:10:54 raeburn Exp $ +# $Id: loncron,v 1.101 2014/12/16 18:18:44 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -157,12 +157,12 @@ sub checkon_daemon { $errors++; my $kadaemon=$daemon; if ($kadaemon eq 'lonmemcached') { $kadaemon='memcached'; } - &log($fh,'
Killall '.$daemon.': '. + &log($fh,'
Killall '.$daemon.': '. `killall $kadaemon 2>&1`.' - '); sleep 1; &log($fh,unlink($pidfile).' - '. `killall -9 $kadaemon 2>&1`. - '
'); + '

'); &log($fh,"

$daemon not running, trying to start

"); if (&start_daemon($fh,$daemon,$pidfile,$args)) { @@ -285,9 +285,11 @@ sub start_logging { &log($fh,(< + + LON Status Report $perlvar{'lonHostID'} + @@ -328,15 +330,20 @@ ENDHEADERS "".$role. "".&Apache::lonnet::hostname($id)."\n"); } - &log($fh,"

Spare Hosts

\n"); return $fh; } @@ -482,7 +489,7 @@ sub clean_lonIDs { my $since=$now-$mtime; if ($since>$perlvar{'lonExpire'}) { $cleaned++; - &log($fh,"Unlinking $fname
"); + &log($fh,"Unlinking $fname
"); unlink("$fname"); } else { $active++; @@ -526,7 +533,7 @@ sub check_httpd_logs { sub rotate_lonnet_logs { my ($fh)=@_; &log($fh,'

lonnet

Temp Log

');
-    print "checking logs\n";
+    print "Checking logs.\n";
     if (-e "$perlvar{'lonDaemons'}/logs/lonnet.log"){
 	open (DFH,"tail -n50 $perlvar{'lonDaemons'}/logs/lonnet.log|");
 	while (my $line=) { 
@@ -570,7 +577,7 @@ sub rotate_other_logs {
 sub test_connections {
     my ($fh)=@_;
     &log($fh,'

Connections

'); - print "testing connections\n"; + print "Testing connections.\n"; &log($fh,""); my ($good,$bad)=(0,0); my %hostname = &Apache::lonnet::all_hostnames(); @@ -604,7 +611,7 @@ sub test_connections { sub check_delayed_msg { my ($fh)=@_; &log($fh,'

Delayed Messages

'); - print "checking buffers\n"; + print "Checking buffers.\n"; &log($fh,'

Scanning Permanent Log

'); @@ -615,7 +622,7 @@ sub check_delayed_msg { my ($time,$sdf,$dserv,$dcmd)=split(/:/,$line); if ($sdf eq 'F') { my $local=localtime($time); - &log($fh,"Failed: $time, $dserv, $dcmd
"); + &log($fh,"Failed: $time, $dserv, $dcmd
"); $warnings++; } if ($sdf eq 'S') { $unsend--; } @@ -654,7 +661,7 @@ sub check_delayed_msg { }; if ($@ && $@ =~ m/TIMEOUT/) { &log($fh,"Attempted pong to $tryserver timed out
"); - print "time out while contacting: $tryserver for pong\n"; + print "Time out while contacting: $tryserver for pong.\n"; } else { &log($fh,"Pong to $tryserver: $answer
"); } @@ -673,7 +680,7 @@ sub finish_logging { my $now=time; my $date=localtime($now); &log($fh,"
$date ($now)\n"); - print "lon-status webpage updated\n"; + print "lon-status webpage updated.\n"; $fh->close(); if ($errors) { $simplestatus{'errors'}=$errors; } @@ -694,7 +701,7 @@ sub log_simplestatus { } sub write_loncaparevs { - print "Retrieving LON-CAPA version information\n"; + print "Retrieving LON-CAPA version information.\n"; my %hostname = &Apache::lonnet::all_hostnames(); my $output; foreach my $id (sort(keys(%hostname))) { @@ -708,7 +715,7 @@ sub write_loncaparevs { alarm(0); }; if ($@ && $@ =~ m/TIMEOUT/) { - print "time out while contacting lonHost: $id for version\n"; + print "Time out while contacting lonHost: $id for version.\n"; } if ($loncaparev =~ /^[\w.\-]+$/) { $output .= $id.':'.$loncaparev."\n"; @@ -726,7 +733,7 @@ sub write_loncaparevs { } sub write_serverhomeIDs { - print "Retrieving LON-CAPA lonHostID information\n"; + print "Retrieving LON-CAPA lonHostID information.\n"; my %name_to_host = &Apache::lonnet::all_names(); my $output; foreach my $name (sort(keys(%name_to_host))) { @@ -782,7 +789,6 @@ sub write_checksums { } sub send_mail { - print "sending mail\n"; my $defdom = $perlvar{'lonDefDomain'}; my $origmail = $perlvar{'lonAdmEMail'}; my $emailto = &Apache::loncommon::build_recipient_list(undef, @@ -790,17 +796,40 @@ sub send_mail { if ($totalcount>2500) { $emailto.=",$perlvar{'lonSysEMail'}"; } - my $subj="LON: $perlvar{'lonHostID'} E:$errors W:$warnings N:$notices"; - - my $result=system("metasend -b -S 4000000 -t $emailto -s '$subj' -f $statusdir/index.html -m text/html >& /dev/null"); - if ($result != 0) { - $result=system("mail -s '$subj' $emailto < $statusdir/index.html"); + my $from; + my $hostname=`/bin/hostname`; + chop($hostname); + $hostname=~s/[^\w\.]//g; + if ($hostname) { + $from = 'www@'.$hostname; + } + my $subj="LON: $perlvar{'lonHostID'} E:$errors W:$warnings N:$notices"; + my $loncronmail = "To: $emailto\n". + "From: $from\n". + "Subject: ".$subj."\n". + "Content-type: text/html\; charset=UTF-8\n". + "MIME-Version: 1.0\n\n"; + if (open(my $fh,"<$statusdir/index.html")) { + while (<$fh>) { + $loncronmail .= $_; + } + close($fh); + } else { + $loncronmail .= "Failed to read from http://$hostname/lon-status/index.html\n"; + } + $loncronmail .= "\n\n"; + if (open(my $mailh, "|/usr/lib/sendmail -oi -t -odb")) { + print $mailh $loncronmail; + close($mailh); + print "Sending mail.\n"; + } else { + print "Sending mail failed.\n"; } } sub usage { print(< /dev/null"); exit 1; }