File:  [LON-CAPA] / loncom / loncron
Revision 1.23: download - view: text, annotated - select for diffs
Tue Sep 4 17:58:44 2001 UTC (22 years, 7 months ago) by www
Branches: MAIN
CVS tags: HEAD
Kills more radically - especially, kills orphans who would become zombies
(and block the IO Socket while alive).

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

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