[LON-CAPA-cvs] cvs: loncom / loncron

raeburn raeburn at source.lon-capa.org
Tue Dec 16 13:18:45 EST 2014


raeburn		Tue Dec 16 18:18:45 2014 EDT

  Modified files:              
    /loncom	loncron 
  Log:
  - Changes to satisfy w3c xhtml validation. 
  - Eliminate use of metasend (provided by metamail) as currently supported
    distros tyically do not have this installed.
  - Include headers (Content-type, MIME-Version etc.) in e-mail of status page 
    contents so e-mailclients will display content as HTML. 
  
  
Index: loncom/loncron
diff -u loncom/loncron:1.100 loncom/loncron:1.101
--- loncom/loncron:1.100	Mon Mar 17 14:47:38 2014
+++ loncom/loncron	Tue Dec 16 18:18:44 2014
@@ -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 @@
 	$errors++;
 	my $kadaemon=$daemon;
 	if ($kadaemon eq 'lonmemcached') { $kadaemon='memcached'; }
-	&log($fh,'<br><font color="red">Killall '.$daemon.': '.
+	&log($fh,'<br /><font color="red">Killall '.$daemon.': '.
 	    `killall $kadaemon 2>&1`.' - ');
 	sleep 1;
 	&log($fh,unlink($pidfile).' - '.
 	    `killall -9 $kadaemon 2>&1`.
-	    '</font><br>');
+	    '</font><br />');
 	&log($fh,"<h3>$daemon not running, trying to start</h3>");
 	
 	if (&start_daemon($fh,$daemon,$pidfile,$args)) {
@@ -285,9 +285,11 @@
     
 
     &log($fh,(<<ENDHEADERS));
-<html>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 <head>
 <title>LON Status Report $perlvar{'lonHostID'}</title>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 </head>
 <body bgcolor="#AAAAAA">
 <a name="top" />
@@ -328,15 +330,20 @@
 	    "</td><td>".$role.
 	    "</td><td>".&Apache::lonnet::hostname($id)."</td></tr>\n");
     }
-    &log($fh,"</table><h3>Spare Hosts</h3><ul>");
-    foreach my $type (sort(keys(%Apache::lonnet::spareid))) {
-	&log($fh,"<li>$type\n<ol>");
-	foreach my $id (@{ $Apache::lonnet::spareid{$type} }) {
-	    &log($fh,"<li>$id</li>\n");
-	}
-	&log($fh,"</ol>\n</li>\n");
+    &log($fh,"</table><h3>Spare Hosts</h3>");
+    if (keys(%Apache::lonnet::spareid) > 0) {
+        &log($fh,"<ul>");
+        foreach my $type (sort(keys(%Apache::lonnet::spareid))) {
+	    &log($fh,"<li>$type\n<ol>");
+	    foreach my $id (@{ $Apache::lonnet::spareid{$type} }) {
+	        &log($fh,"<li>$id</li>\n");
+	    }
+	    &log($fh,"</ol>\n</li>\n");
+        }
+        &log($fh,"</ul>\n");
+    } else {
+        &log($fh,"No spare hosts specified<br />\n");
     }
-    &log($fh,"</ul>\n");
     return $fh;
 }
 
@@ -482,7 +489,7 @@
 	my $since=$now-$mtime;
 	if ($since>$perlvar{'lonExpire'}) {
 	    $cleaned++;
-	    &log($fh,"Unlinking $fname<br>");
+	    &log($fh,"Unlinking $fname<br />");
 	    unlink("$fname");
 	} else {
 	    $active++;
@@ -615,7 +622,7 @@
 	my ($time,$sdf,$dserv,$dcmd)=split(/:/,$line);
 	if ($sdf eq 'F') { 
 	    my $local=localtime($time);
-	    &log($fh,"<b>Failed: $time, $dserv, $dcmd</b><br>");
+	    &log($fh,"<b>Failed: $time, $dserv, $dcmd</b><br />");
 	    $warnings++;
 	}
 	if ($sdf eq 'S') { $unsend--; }
@@ -782,7 +789,6 @@
 }
 
 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 @@
     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";
     }
 }
 




More information about the LON-CAPA-cvs mailing list