File:  [LON-CAPA] / loncom / loncron
Revision 1.38: download - view: text, annotated - select for diffs
Mon Apr 7 18:19:23 2003 UTC (21 years, 1 month ago) by albertel
Branches: MAIN
CVS tags: version_0_99_1, version_0_99_0, conference_2003, HEAD
- allow for larger log files, as things have gotten more noisy

    1: #!/usr/bin/perl
    2: 
    3: # The LearningOnline Network
    4: # Housekeeping program, started by cron
    5: #
    6: # (TCP networking package
    7: # 6/1/99,6/2,6/10,6/11,6/12,6/14,6/26,6/28,6/29,6/30,
    8: # 7/1,7/2,7/9,7/10,7/12 Gerd Kortemeyer)
    9: #
   10: # 7/14,7/15,7/19,7/21,7/22,11/18,
   11: # 2/8 Gerd Kortemeyer
   12: # 12/23 Gerd Kortemeyer
   13: # YEAR=2001
   14: # 09/04,09/06,11/26 Gerd Kortemeyer
   15: 
   16: $|=1;
   17: 
   18: use lib '/home/httpd/lib/perl/';
   19: use LONCAPA::Configuration;
   20: 
   21: use IO::File;
   22: use IO::Socket;
   23: 
   24: # -------------------------------------------------- Non-critical communication
   25: sub reply {
   26:     my ($cmd,$server)=@_;
   27:     my $peerfile="$perlvar{'lonSockDir'}/$server";
   28:     my $client=IO::Socket::UNIX->new(Peer    =>"$peerfile",
   29:                                      Type    => SOCK_STREAM,
   30:                                      Timeout => 10)
   31:        or return "con_lost";
   32:     print $client "$cmd\n";
   33:     my $answer=<$client>;
   34:     chomp($answer);
   35:     if (!$answer) { $answer="con_lost"; }
   36:     return $answer;
   37: }
   38: 
   39: # --------------------------------------------------------- Output error status
   40: 
   41: sub errout {
   42:    my $fh=shift;
   43:    print $fh (<<ENDERROUT);
   44:      <p><table border=2 bgcolor="#CCCCCC">
   45:      <tr><td>Notices</td><td>$notices</td></tr>
   46:      <tr><td>Warnings</td><td>$warnings</td></tr>
   47:      <tr><td>Errors</td><td>$errors</td></tr>
   48:      </table><p><a href="#top">Top</a><p>
   49: ENDERROUT
   50: }
   51: 
   52: # ================================================================ Main Program
   53: 
   54: # --------------------------------- Read loncapa_apache.conf and loncapa.conf
   55: my $perlvarref=LONCAPA::Configuration::read_conf('loncapa.conf');
   56: %perlvar=%{$perlvarref};
   57: undef $perlvarref;
   58: delete $perlvar{'lonReceipt'}; # remove since sensitive and not needed
   59: delete $perlvar{'lonSqlAccess'}; # remove since sensitive and not needed
   60: 
   61: # --------------------------------------- Make sure that LON-CAPA is configured
   62: # I only test for one thing here (lonHostID).  This is just a safeguard.
   63: if ('{[[[[lonHostID]]]]}' eq $perlvar{'lonHostID'}) {
   64:    print("Unconfigured machine.\n");
   65:    $emailto=$perlvar{'lonSysEMail'};
   66:    $hostname=`/bin/hostname`;
   67:    chop $hostname;
   68:    $hostname=~s/[^\w\.]//g; # make sure is safe to pass through shell
   69:    $subj="LON: Unconfigured machine $hostname";
   70:    system("echo 'Unconfigured machine $hostname.' |\
   71:  mailto $emailto -s '$subj' > /dev/null");
   72:     exit 1;
   73: }
   74: 
   75: # ----------------------------- Make sure this process is running from user=www
   76: my $wwwid=getpwnam('www');
   77: if ($wwwid!=$<) {
   78:    print("User ID mismatch.  This program must be run as user 'www'\n");
   79:    $emailto="$perlvar{'lonAdmEMail'},$perlvar{'lonSysEMail'}";
   80:    $subj="LON: $perlvar{'lonHostID'} User ID mismatch";
   81:    system("echo 'User ID mismatch.  loncron must be run as user www.' |\
   82:  mailto $emailto -s '$subj' > /dev/null");
   83:    exit 1;
   84: }
   85: 
   86: # ------------------------------------------------------------- Read hosts file
   87: {
   88:     my $config=IO::File->new("$perlvar{'lonTabDir'}/hosts.tab");
   89: 
   90:     while (my $configline=<$config>) {
   91: 	my ($id,$domain,$role,$name,$ip,$domdescr)=split(/:/,$configline);
   92: 	if ($id && $domain && $role && $name && $ip) {
   93: 	    $hostname{$id}=$name;
   94: 	    $hostdom{$id}=$domain;
   95: 	    $hostip{$id}=$ip;
   96: 	    $hostrole{$id}=$role;
   97: 	    if ($domdescr) { $domaindescription{$domain}=$domdescr; }
   98: 	    if (($role eq 'library') && ($id ne $perlvar{'lonHostID'})) {
   99: 		$libserv{$id}=$name;
  100: 	    }
  101: 	} else {
  102: 	    if ($configline) {
  103: #		&logthis("Skipping hosts.tab line -$configline-");
  104: 	    }
  105: 	}
  106:     }
  107: }
  108: 
  109: # ------------------------------------------------------ Read spare server file
  110: {
  111:     my $config=IO::File->new("$perlvar{'lonTabDir'}/spare.tab");
  112: 
  113:     while (my $configline=<$config>) {
  114:        chomp($configline);
  115:        if (($configline) && ($configline ne $perlvar{'lonHostID'})) {
  116:           $spareid{$configline}=1;
  117:        }
  118:     }
  119: }
  120: 
  121: # ---------------------------------------------------------------- Start report
  122: 
  123: $statusdir="/home/httpd/html/lon-status";
  124: 
  125: $errors=0;
  126: $warnings=0;
  127: $notices=0;
  128: 
  129: $now=time;
  130: $date=localtime($now);
  131: 
  132: {
  133: my $fh=IO::File->new(">$statusdir/newstatus.html");
  134: 
  135: print $fh (<<ENDHEADERS);
  136: <html>
  137: <head>
  138: <title>LON Status Report $perlvar{'lonHostID'}</title>
  139: </head>
  140: <body bgcolor="#AAAAAA">
  141: <a name="top">
  142: <h1>LON Status Report $perlvar{'lonHostID'}</h1>
  143: <h2>$date ($now)</h2>
  144: <ol>
  145: <li><a href="#configuration">Configuration</a>
  146: <li><a href="#machine">Machine Information</a>
  147: <li><a href="#tmp">Temporary Files</a>
  148: <li><a href="#tokens">Session Tokens</a>
  149: <li><a href="#httpd">httpd</a>
  150: <li><a href="#lonsql">lonsql</a>
  151: <li><a href="#lond">lond</a>
  152: <li><a href="#lonc">lonc</a>
  153: <li><a href="#lonhttpd">lonhttpd</a>
  154: <li><a href="#lonnet">lonnet</a>
  155: <li><a href="#connections">Connections</a>
  156: <li><a href="#delayed">Delayed Messages</a>
  157: <li><a href="#errcount">Error Count</a>
  158: </ol>
  159: <hr>
  160: <a name="configuration">
  161: <h2>Configuration</h2>
  162: <h3>PerlVars</h3>
  163: <table border=2>
  164: ENDHEADERS
  165: 
  166: foreach $varname (sort(keys(%perlvar))) {
  167:     print $fh "<tr><td>$varname</td><td>$perlvar{$varname}</td></tr>\n";
  168: }
  169: print $fh "</table><h3>Hosts</h3><table border=2>";
  170: foreach $id (sort(keys(%hostname))) {
  171:     print $fh 
  172: 	"<tr><td>$id</td><td>$hostdom{$id}</td><td>$hostrole{$id}</td>";
  173:     print $fh "<td>$hostname{$id}</td><td>$hostip{$id}</td></tr>\n";
  174: }
  175: print $fh "</table><h3>Spare Hosts</h3><ol>";
  176: foreach $id (sort(keys(%spareid))) {
  177:     print $fh "<li>$id\n";
  178: }
  179: 
  180: print $fh "</ol>\n";
  181: 
  182: # --------------------------------------------------------------------- Machine
  183: 
  184: print $fh '<hr><a name="machine"><h2>Machine Information</h2>';
  185: print $fh "<h3>loadavg</h3>";
  186: 
  187: open (LOADAVGH,"/proc/loadavg");
  188: $loadavg=<LOADAVGH>;
  189: close (LOADAVGH);
  190: 
  191: print $fh "<tt>$loadavg</tt>";
  192: 
  193: @parts=split(/\s+/,$loadavg);
  194: if ($parts[1]>4.0) {
  195:     $errors++;
  196: } elsif ($parts[1]>2.0) {
  197:     $warnings++;
  198: } elsif ($parts[1]>1.0) {
  199:     $notices++;
  200: }
  201: 
  202: print $fh "<h3>df</h3>";
  203: print $fh "<pre>";
  204: 
  205: open (DFH,"df|");
  206: while ($line=<DFH>) { 
  207:    print $fh "$line"; 
  208:    @parts=split(/\s+/,$line);
  209:    $usage=$parts[4];
  210:    $usage=~s/\W//g;
  211:    if ($usage>90) { 
  212:       $warnings++;
  213:       $notices++; 
  214:    } elsif ($usage>80) {
  215:       $warnings++;
  216:    } elsif ($usage>60) {
  217:       $notices++;
  218:    }
  219:    if ($usage>95) { $warnings++; $warnings++ }
  220: }
  221: close (DFH);
  222: print $fh "</pre>";
  223: 
  224: 
  225: print $fh "<h3>ps</h3>";
  226: print $fh "<pre>";
  227: $psproc=0;
  228: 
  229: open (PSH,"ps -aux|");
  230: while ($line=<PSH>) { 
  231:    print $fh "$line"; 
  232:    $psproc++;
  233: }
  234: close (PSH);
  235: print $fh "</pre>";
  236: 
  237: if ($psproc>200) { $notices++; }
  238: if ($psproc>250) { $notices++; }
  239: 
  240: &errout($fh);
  241: 
  242: # --------------------------------------------------------------- clean out tmp
  243: print $fh '<hr><a name="tmp"><h2>Temporary Files</h2>';
  244: $cleaned=0;
  245: $old=0;
  246: while ($fname=<$perlvar{'lonDaemons'}/tmp/*>) {
  247:                           my ($dev,$ino,$mode,$nlink,
  248:                               $uid,$gid,$rdev,$size,
  249:                               $atime,$mtime,$ctime,
  250:                               $blksize,$blocks)=stat($fname);
  251:                           $now=time;
  252:                           $since=$now-$mtime;
  253:                           if ($since>$perlvar{'lonExpire'}) {
  254:                               $line='';
  255:                               if (open(PROBE,$fname)) {
  256: 				  $line=<PROBE>;
  257:                                   close(PROBE);
  258: 			      }
  259: 			      unless ($line=~/^CHECKOUTTOKEN\&/) {
  260:                                  $cleaned++;
  261:                                  unlink("$fname");
  262: 			      } else {
  263: 				  if ($since>365*$perlvar{'lonExpire'}) {
  264:                                      $cleaned++;
  265:                                      unlink("$fname");
  266: 				 } else { $old++; }
  267:                               }
  268:                           }
  269:     
  270: }
  271: print $fh "Cleaned up ".$cleaned." files (".$old." old checkout tokens).";
  272: 
  273: # ------------------------------------------------------------ clean out lonIDs
  274: print $fh '<hr><a name="tokens"><h2>Session Tokens</h2>';
  275: $cleaned=0;
  276: $active=0;
  277: while ($fname=<$perlvar{'lonIDsDir'}/*>) {
  278:                           my ($dev,$ino,$mode,$nlink,
  279:                               $uid,$gid,$rdev,$size,
  280:                               $atime,$mtime,$ctime,
  281:                               $blksize,$blocks)=stat($fname);
  282:                           $now=time;
  283:                           $since=$now-$mtime;
  284:                           if ($since>$perlvar{'lonExpire'}) {
  285:                               $cleaned++;
  286:                               print $fh "Unlinking $fname<br>";
  287:                               unlink("$fname");
  288:                           } else {
  289:                               $active++;
  290:                           }
  291:     
  292: }
  293: print $fh "<p>Cleaned up ".$cleaned." stale session token(s).";
  294: print $fh "<h3>$active open session(s)</h3>";
  295: 
  296: # ----------------------------------------------------------------------- httpd
  297: 
  298: print $fh '<hr><a name="httpd"><h2>httpd</h2><h3>Access Log</h3><pre>';
  299: 
  300: open (DFH,"tail -n25 /etc/httpd/logs/access_log|");
  301: while ($line=<DFH>) { print $fh "$line" };
  302: close (DFH);
  303: 
  304: print $fh "</pre><h3>Error Log</h3><pre>";
  305: 
  306: open (DFH,"tail -n25 /etc/httpd/logs/error_log|");
  307: while ($line=<DFH>) { 
  308:    print $fh "$line";
  309:    if ($line=~/\[error\]/) { $notices++; } 
  310: };
  311: close (DFH);
  312: print $fh "</pre>";
  313: &errout($fh);
  314: 
  315: 
  316: # ---------------------------------------------------------------------- lonsql
  317: 
  318: my $restartflag=1;
  319: if ($perlvar{'lonRole'} eq "library") {
  320: 
  321:     print $fh '<hr><a name="lonsql"><h2>lonsql</h2><h3>Log</h3><pre>';
  322:     print "lonsql\n";
  323:     if (-e "$perlvar{'lonDaemons'}/logs/lonsql.log"){
  324: 	open (DFH,"tail -n100 $perlvar{'lonDaemons'}/logs/lonsql.log|");
  325: 	while ($line=<DFH>) { 
  326: 	    print $fh "$line";
  327: 	    if ($line=~/INFO/) { $notices++; }
  328: 	    if ($line=~/WARNING/) { $notices++; }
  329: 	    if ($line=~/CRITICAL/) { $warnings++; }
  330: 	};
  331: 	close (DFH);
  332:     }
  333:     print $fh "</pre>";
  334:     
  335:     my $lonsqlfile="$perlvar{'lonDaemons'}/logs/lonsql.pid";
  336:  
  337:     $restartflag=1;
  338:    
  339:     if (-e $lonsqlfile) {
  340: 	my $lfh=IO::File->new("$lonsqlfile");
  341: 	my $lonsqlpid=<$lfh>;
  342: 	chomp($lonsqlpid);
  343: 	if (kill 0 => $lonsqlpid) {
  344: 	    print $fh "<h3>lonsql at pid $lonsqlpid responding</h3>";
  345: 	    $restartflag=0;
  346: 	} else {
  347: 	    $errors++; $errors++;
  348: 	    print $fh "<h3>lonsql at pid $lonsqlpid not responding</h3>";
  349: 		$restartflag=1;
  350: 	print $fh 
  351: 	    "<h3>Decided to clean up stale .pid file and restart lonsql</h3>";
  352: 	}
  353:     }
  354:     if ($restartflag==1) {
  355: 	$errors++;
  356: 	         print $fh '<br><font color="red">Killall lonsql: '.
  357:                     system('killall lonsql').' - ';
  358:                     sleep 2;
  359:                     print $fh unlink($lonsqlfile).' - '.
  360:                               system('killall -9 lonsql').
  361:                     '</font><br>';
  362: 	print $fh "<h3>lonsql not running, trying to start</h3>";
  363: 	system(
  364:  "$perlvar{'lonDaemons'}/lonsql 2>>$perlvar{'lonDaemons'}/logs/lonsql_errors");
  365: 	sleep 2;
  366: 	if (-e $lonsqlfile) {
  367: 	    print $fh "Seems like it started ...<p>";
  368: 	    my $lfh=IO::File->new("$lonsqlfile");
  369: 	    my $lonsqlpid=<$lfh>;
  370: 	    chomp($lonsqlpid);
  371: 	    sleep 2;
  372: 	    if (kill 0 => $lonsqlpid) {
  373: 		print $fh "<h3>lonsql at pid $lonsqlpid responding</h3>";
  374: 	    } else {
  375: 		$errors++; $errors++;
  376: 		print $fh "<h3>lonsql at pid $lonsqlpid not responding</h3>";
  377: 		print $fh "Give it one more try ...<p>";
  378: 		system(
  379:  "$perlvar{'lonDaemons'}/lonsql 2>>$perlvar{'lonDaemons'}/logs/lonsql_errors");
  380: 		sleep 2;
  381: 	    }
  382: 	} else {
  383: 	    print $fh "Seems like that did not work!<p>";
  384: 	    $errors++;
  385: 	}
  386: 	if (-e "$perlvar{'lonDaemons'}/logs/lonsql.log"){
  387: 	    print $fh "<p><pre>";
  388: 	    open (DFH,"tail -n100 $perlvar{'lonDaemons'}/logs/lonsql.log|");
  389: 	    while ($line=<DFH>) { 
  390: 		print $fh "$line";
  391: 		if ($line=~/WARNING/) { $notices++; }
  392: 		if ($line=~/CRITICAL/) { $notices++; }
  393: 	    };
  394: 	    close (DFH);
  395: 	    print $fh "</pre>";
  396: 	}
  397:     }
  398: 
  399:     $fname="$perlvar{'lonDaemons'}/logs/lonsql.log";
  400: 
  401:     my ($dev,$ino,$mode,$nlink,
  402: 	$uid,$gid,$rdev,$size,
  403: 	$atime,$mtime,$ctime,
  404: 	$blksize,$blocks)=stat($fname);
  405: 
  406:     if ($size>200000) {
  407: 	print $fh "Rotating logs ...<p>";
  408: 	rename("$fname.2","$fname.3");
  409: 	rename("$fname.1","$fname.2");
  410: 	rename("$fname","$fname.1");
  411:     }
  412: 
  413:     &errout($fh);
  414: }
  415: # ------------------------------------------------------------------------ lond
  416: 
  417: print $fh '<hr><a name="lond"><h2>lond</h2><h3>Log</h3><pre>';
  418: print "lond\n";
  419: 
  420: if (-e "$perlvar{'lonDaemons'}/logs/lond.log"){
  421: open (DFH,"tail -n25 $perlvar{'lonDaemons'}/logs/lond.log|");
  422: while ($line=<DFH>) { 
  423:    print $fh "$line";
  424:    if ($line=~/INFO/) { $notices++; }
  425:    if ($line=~/WARNING/) { $notices++; }
  426:    if ($line=~/CRITICAL/) { $warnings++; }
  427: };
  428: close (DFH);
  429: }
  430: print $fh "</pre>";
  431: 
  432: my $londfile="$perlvar{'lonDaemons'}/logs/lond.pid";
  433: 
  434: $restartflag=1;
  435: if (-e $londfile) {    
  436:    my $lfh=IO::File->new("$londfile");
  437:    my $londpid=<$lfh>;
  438:    chomp($londpid);
  439:    if (kill 0 => $londpid) {
  440:       print $fh "<h3>lond at pid $londpid responding, sending USR1</h3>";
  441:       kill USR1 => $londpid;
  442:       $restartflag=0;
  443:    } else {
  444:       $errors++;
  445:       print $fh "<h3>lond at pid $londpid not responding</h3>";
  446:       $restartflag=1;
  447:       print $fh 
  448: 	  "<h3>Decided to clean up stale .pid file and restart lond</h3>";
  449:    }
  450: } 
  451: if ($restartflag==1) {
  452:    $errors++;
  453: 	  print $fh '<br><font color="red">Killall lond: '.
  454:                     system('killall lond').' - ';
  455:           sleep 2;
  456:           print $fh unlink($londfile).' - '.system('killall -9 lond').
  457:                     '</font><br>';
  458:    print $fh "<h3>lond not running, trying to start</h3>";
  459:    system(
  460:      "$perlvar{'lonDaemons'}/lond 2>>$perlvar{'lonDaemons'}/logs/lond_errors");
  461:    sleep 2;
  462:    if (-e $londfile) {
  463:        print $fh "Seems like it started ...<p>";
  464:        my $lfh=IO::File->new("$londfile");
  465:        my $londpid=<$lfh>;
  466:        chomp($londpid);
  467:        sleep 2;
  468:        if (kill 0 => $londpid) {
  469:           print $fh "<h3>lond at pid $londpid responding</h3>";
  470:        } else {
  471:           $errors++; $errors++;
  472:           print $fh "<h3>lond at pid $londpid not responding</h3>";
  473:           print $fh "Give it one more try ...<p>";
  474: 	  system(
  475:  "$perlvar{'lonDaemons'}/lond 2>>$perlvar{'lonDaemons'}/logs/lond_errors");
  476:           sleep 2;
  477:        }
  478:    } else {
  479:        print $fh "Seems like that did not work!<p>";
  480:        $errors++;
  481:    }
  482:    if (-e "$perlvar{'lonDaemons'}/logs/lond.log"){
  483:     print $fh "<p><pre>";
  484:     open (DFH,"tail -n100 $perlvar{'lonDaemons'}/logs/lond.log|");
  485:     while ($line=<DFH>) { 
  486:       print $fh "$line";
  487:       if ($line=~/WARNING/) { $notices++; }
  488:       if ($line=~/CRITICAL/) { $notices++; }
  489:     };
  490:     close (DFH);
  491:     print $fh "</pre>";
  492:    }
  493: }
  494: 
  495: $fname="$perlvar{'lonDaemons'}/logs/lond.log";
  496: 
  497:                           my ($dev,$ino,$mode,$nlink,
  498:                               $uid,$gid,$rdev,$size,
  499:                               $atime,$mtime,$ctime,
  500:                               $blksize,$blocks)=stat($fname);
  501: 
  502: if ($size>40000) {
  503:     print $fh "Rotating logs ...<p>";
  504:     rename("$fname.2","$fname.3");
  505:     rename("$fname.1","$fname.2");
  506:     rename("$fname","$fname.1");
  507: }
  508: 
  509: &errout($fh);
  510: # ------------------------------------------------------------------------ lonc
  511: 
  512: print $fh '<hr><a name="lonc"><h2>lonc</h2><h3>Log</h3><pre>';
  513: print "lonc\n";
  514: 
  515: if (-e "$perlvar{'lonDaemons'}/logs/lonc.log"){
  516: open (DFH,"tail -n25 $perlvar{'lonDaemons'}/logs/lonc.log|");
  517: while ($line=<DFH>) { 
  518:    print $fh "$line";
  519:    if ($line=~/INFO/) { $notices++; }
  520:    if ($line=~/WARNING/) { $notices++; }
  521:    if ($line=~/CRITICAL/) { $warnings++; }
  522: };
  523: close (DFH);
  524: }
  525: print $fh "</pre>";
  526: 
  527: my $loncfile="$perlvar{'lonDaemons'}/logs/lonc.pid";
  528: 
  529: $restartflag=1;
  530: if (-e $loncfile) {
  531:    my $lfh=IO::File->new("$loncfile");
  532:    my $loncpid=<$lfh>;
  533:    chomp($loncpid);
  534:    if (kill 0 => $loncpid) {
  535:       print $fh "<h3>lonc at pid $loncpid responding, sending USR1</h3>";
  536:       kill USR1 => $loncpid;
  537:       $restartflag=0;
  538:    } else {
  539:       $errors++;
  540:       print $fh "<h3>lonc at pid $loncpid not responding</h3>";
  541:       # Solution: kill parent and children processes, remove .pid and restart
  542: 	  $restartflag=1;
  543:       print $fh 
  544: 	  "<h3>Decided to clean up stale .pid file and restart lonc</h3>";
  545:    }
  546: } 
  547: if ($restartflag==1) {
  548:    $errors++;
  549: 	  print $fh '<br><font color="red">Killall lonc: '.
  550: 	            system('killall lonc').' - ';
  551:           sleep 2;
  552:           print $fh unlink($loncfile).' - '.system('killall -9 lonc').
  553:                     '</font><br>';
  554:    print $fh "<h3>lonc not running, trying to start</h3>";
  555: 	system(
  556:  "$perlvar{'lonDaemons'}/lonc 2>>$perlvar{'lonDaemons'}/logs/lonc_errors");
  557:    sleep 2;
  558:    if (-e $loncfile) {
  559:        print $fh "Seems like it started ...<p>";
  560:        my $lfh=IO::File->new("$loncfile");
  561:        my $loncpid=<$lfh>;
  562:        chomp($loncpid);
  563:        sleep 2;
  564:        if (kill 0 => $loncpid) {
  565:           print $fh "<h3>lonc at pid $loncpid responding</h3>";
  566:        } else {
  567:           $errors++; $errors++;
  568:           print $fh "<h3>lonc at pid $loncpid not responding</h3>";
  569:           print $fh "Give it one more try ...<p>";
  570:  	  system(
  571:  "$perlvar{'lonDaemons'}/lonc 2>>$perlvar{'lonDaemons'}/logs/lonc_errors");
  572:           sleep 2;
  573:        }
  574:    } else {
  575:        print $fh "Seems like that did not work!<p>";
  576:        $errors++;
  577:    }
  578:    if (-e "$perlvar{'lonDaemons'}/logs/lonc.log") {
  579:     print $fh "<p><pre>";
  580:     open (DFH,"tail -n100 $perlvar{'lonDaemons'}/logs/lonc.log|");
  581:     while ($line=<DFH>) { 
  582:       print $fh "$line";
  583:       if ($line=~/WARNING/) { $notices++; }
  584:       if ($line=~/CRITICAL/) { $notices++; }
  585:     };
  586:     close (DFH);
  587:     print $fh "</pre>";
  588:    }
  589: }
  590: 
  591: $fname="$perlvar{'lonDaemons'}/logs/lonc.log";
  592: 
  593:                           my ($dev,$ino,$mode,$nlink,
  594:                               $uid,$gid,$rdev,$size,
  595:                               $atime,$mtime,$ctime,
  596:                               $blksize,$blocks)=stat($fname);
  597: 
  598: if ($size>40000) {
  599:     print $fh "Rotating logs ...<p>";
  600:     rename("$fname.2","$fname.3");
  601:     rename("$fname.1","$fname.2");
  602:     rename("$fname","$fname.1");
  603: }
  604: 
  605:    
  606: &errout($fh);
  607: # -------------------------------------------------------------------- lonhttpd
  608: 
  609: print $fh '<hr><a name="lonhttpd"><h2>lonhttpd</h2><h3>Log</h3><pre>';
  610: print "lonhttpd\n";
  611: 
  612: if (-e "$perlvar{'lonDaemons'}/logs/lonhttpd.log"){
  613: open (DFH,"tail -n25 $perlvar{'lonDaemons'}/logs/lonhttpd.log|");
  614: while ($line=<DFH>) { 
  615:    print $fh "$line";
  616:    if ($line=~/INFO/) { $notices++; }
  617:    if ($line=~/WARNING/) { $notices++; }
  618:    if ($line=~/CRITICAL/) { $warnings++; }
  619: };
  620: close (DFH);
  621: }
  622: print $fh "</pre>";
  623: 
  624: my $lonhttpdfile="$perlvar{'lonDaemons'}/logs/lonhttpd.pid";
  625: 
  626: $restartflag=1;
  627: if (-e $lonhttpdfile) {
  628:    my $lfh=IO::File->new("$lonhttpdfile");
  629:    my $lonhttpdpid=<$lfh>;
  630:    chomp($lonhttpdpid);
  631:    if (kill 0 => $lonhttpdpid) {
  632:       print $fh "<h3>lonhttpd at pid $lonhttpdpid responding</h3>";
  633:       $restartflag=0;
  634:    } else {
  635:       $errors++;
  636:       print $fh "<h3>lonhttpd at pid $lonhttpdpid not responding</h3>";
  637:       # Solution: kill parent and children processes, remove .pid and restart
  638: 	  $restartflag=1;
  639:       print $fh 
  640: 	  "<h3>Decided to clean up stale .pid file and restart lonhttpd</h3>";
  641:    }
  642: } 
  643: if ($restartflag==1) {
  644:    $errors++;
  645: 	  print $fh '<br><font color="red">Killall lonhttpd: '.
  646: 	            system('killall lonhttpd').' - ';
  647:           sleep 2;
  648:           print $fh unlink($lonhttpdfile).' - '.system('killall -9 lonhttpd').
  649:                     '</font><br>';
  650:    print $fh "<h3>lonhttpd not running, trying to start</h3>";
  651: 	system(
  652:  "$perlvar{'lonDaemons'}/lonhttpd 2>>$perlvar{'lonDaemons'}/logs/lonhttpd_errors");
  653:    sleep 2;
  654:    if (-e $lonhttpdfile) {
  655:        print $fh "Seems like it started ...<p>";
  656:        my $lfh=IO::File->new("$lonhttpdfile");
  657:        my $lonhttpdpid=<$lfh>;
  658:        chomp($lonhttpdpid);
  659:        sleep 2;
  660:        if (kill 0 => $lonhttpdpid) {
  661:           print $fh "<h3>lonhttpd at pid $lonhttpdpid responding</h3>";
  662:        } else {
  663:           $errors++; $errors++;
  664:           print $fh "<h3>lonhttpd at pid $lonhttpdpid not responding</h3>";
  665:           print $fh "Give it one more try ...<p>";
  666:  	  system(
  667:  "$perlvar{'lonDaemons'}/lonhttpd 2>>$perlvar{'lonDaemons'}/logs/lonhttpd_errors");
  668:           sleep 2;
  669:        }
  670:    } else {
  671:        print $fh "Seems like that did not work!<p>";
  672:        $errors++;
  673:    }
  674:    if (-e "$perlvar{'lonDaemons'}/logs/lonhttpd.log") {
  675:     print $fh "<p><pre>";
  676:     open (DFH,"tail -n100 $perlvar{'lonDaemons'}/logs/lonhttpd.log|");
  677:     while ($line=<DFH>) { 
  678:       print $fh "$line";
  679:       if ($line=~/WARNING/) { $notices++; }
  680:       if ($line=~/CRITICAL/) { $notices++; }
  681:     };
  682:     close (DFH);
  683:     print $fh "</pre>";
  684:    }
  685: }
  686: 
  687: $fname="$perlvar{'lonDaemons'}/logs/lonhttpd.log";
  688: 
  689:                           my ($dev,$ino,$mode,$nlink,
  690:                               $uid,$gid,$rdev,$size,
  691:                               $atime,$mtime,$ctime,
  692:                               $blksize,$blocks)=stat($fname);
  693: 
  694: if ($size>40000) {
  695:     print $fh "Rotating logs ...<p>";
  696:     rename("$fname.2","$fname.3");
  697:     rename("$fname.1","$fname.2");
  698:     rename("$fname","$fname.1");
  699: }
  700: 
  701:    
  702: &errout($fh);
  703: # ---------------------------------------------------------------------- lonnet
  704: 
  705: print $fh '<hr><a name="lonnet"><h2>lonnet</h2><h3>Temp Log</h3><pre>';
  706: print "lonnet\n";
  707: if (-e "$perlvar{'lonDaemons'}/logs/lonnet.log"){
  708: open (DFH,"tail -n50 $perlvar{'lonDaemons'}/logs/lonnet.log|");
  709: while ($line=<DFH>) { 
  710:     print $fh "$line";
  711: };
  712: close (DFH);
  713: }
  714: print $fh "</pre><h3>Perm Log</h3><pre>";
  715: 
  716: if (-e "$perlvar{'lonDaemons'}/logs/lonnet.perm.log") {
  717:     open(DFH,"tail -n10 $perlvar{'lonDaemons'}/logs/lonnet.perm.log|");
  718: while ($line=<DFH>) { 
  719:    print $fh "$line";
  720: };
  721: close (DFH);
  722: } else { print $fh "No perm log\n" }
  723: 
  724: $fname="$perlvar{'lonDaemons'}/logs/lonnet.log";
  725: 
  726:                           my ($dev,$ino,$mode,$nlink,
  727:                               $uid,$gid,$rdev,$size,
  728:                               $atime,$mtime,$ctime,
  729:                               $blksize,$blocks)=stat($fname);
  730: 
  731: if ($size>40000) {
  732:     print $fh "Rotating logs ...<p>";
  733:     rename("$fname.2","$fname.3");
  734:     rename("$fname.1","$fname.2");
  735:     rename("$fname","$fname.1");
  736: }
  737: 
  738: print $fh "</pre>";
  739: &errout($fh);
  740: # ----------------------------------------------------------------- Connections
  741: 
  742: print $fh '<hr><a name="connections"><h2>Connections</h2>';
  743: 
  744: print $fh "<table border=2>";
  745: foreach $tryserver (sort(keys(%hostname))) {
  746: 
  747:     $answer=reply("pong",$tryserver);
  748:     if ($answer eq "$tryserver:$perlvar{'lonHostID'}") {
  749: 	$result="<b>ok</b>";
  750:     } else {
  751:         $result=$answer;
  752:         $warnings++;
  753:         if ($answer eq 'con_lost') { $warnings++; }
  754:     }
  755:     print $fh "<tr><td>$tryserver</td><td>$result</td></tr>\n";
  756: 
  757: }
  758: print $fh "</table>";
  759: 
  760: &errout($fh);
  761: # ------------------------------------------------------------ Delayed messages
  762: 
  763: print $fh '<hr><a name="delayed"><h2>Delayed Messages</h2>';
  764: print "buffers\n";
  765: 
  766: print $fh '<h3>Scanning Permanent Log</h3>';
  767: 
  768: $unsend=0;
  769: {
  770:     my $dfh=IO::File->new("$perlvar{'lonDaemons'}/logs/lonnet.perm.log");
  771:     while ($line=<$dfh>) {
  772: 	($time,$sdf,$dserv,$dcmd)=split(/:/,$line);
  773:         if ($sdf eq 'F') { 
  774: 	    $local=localtime($time);
  775:             print "<b>Failed: $time, $dserv, $dcmd</b><br>";
  776:             $warnings++;
  777:         }
  778:         if ($sdf eq 'S') { $unsend--; }
  779:         if ($sdf eq 'D') { $unsend++; }
  780:     }
  781: }
  782: print $fh "Total unsend messages: <b>$unsend</b><p>\n";
  783: $warnings=$warnings+5*$unsend;
  784: 
  785: print $fh "<h3>Outgoing Buffer</h3>";
  786: 
  787: open (DFH,"ls -lF $perlvar{'lonSockDir'}/delayed|");
  788: while ($line=<DFH>) { 
  789:     print $fh "$line<br>";
  790: };
  791: close (DFH);
  792: 
  793: # ------------------------------------------------------------------------- End
  794: print $fh "<a name=errcount>\n";
  795: $totalcount=$notices+4*$warnings+100*$errors;
  796: &errout($fh);
  797: print $fh "<h1>Total Error Count: $totalcount</h1>";
  798: $now=time;
  799: $date=localtime($now);
  800: print $fh "<hr>$date ($now)</body></html>\n";
  801: print "writing done\n";
  802: }
  803: 
  804: rename ("$statusdir/newstatus.html","$statusdir/index.html");
  805: 
  806: if ($totalcount>200) {
  807:    print "mailing\n";
  808:    $emailto="$perlvar{'lonAdmEMail'}";
  809:    if ($totalcount>600) {
  810:       $emailto.=",$perlvar{'lonSysEMail'}";
  811:    }
  812:    $subj="LON: $perlvar{'lonHostID'} E:$errors W:$warnings N:$notices"; 
  813:    system(
  814:  "metasend -b -t $emailto -s '$subj' -f $statusdir/index.html -m text/html");
  815: }
  816: 1;
  817: 
  818: 
  819: 
  820: 
  821: 
  822: 
  823: 
  824: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>