--- loncom/loncron 2014/03/17 14:47:38 1.100
+++ 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.100 2014/03/17 14:47:38 bisitz 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
");
- foreach my $type (sort(keys(%Apache::lonnet::spareid))) {
- &log($fh,"- $type\n
");
- foreach my $id (@{ $Apache::lonnet::spareid{$type} }) {
- &log($fh,"- $id
\n");
- }
- &log($fh,"
\n \n");
+ &log($fh,"Spare Hosts
");
+ if (keys(%Apache::lonnet::spareid) > 0) {
+ &log($fh,"");
+ foreach my $type (sort(keys(%Apache::lonnet::spareid))) {
+ &log($fh,"- $type\n
");
+ foreach my $id (@{ $Apache::lonnet::spareid{$type} }) {
+ &log($fh,"- $id
\n");
+ }
+ &log($fh,"
\n \n");
+ }
+ &log($fh,"
\n");
+ } else {
+ &log($fh,"No spare hosts specified
\n");
}
- &log($fh,"
\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++;
@@ -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--; }
@@ -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,11 +796,34 @@ 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";
}
}