File:  [LON-CAPA] / loncom / loncron
Revision 1.29: download - view: text, annotated - select for diffs
Mon May 27 19:21:59 2002 UTC (21 years, 11 months ago) by www
Branches: MAIN
CVS tags: HEAD
Cleans up CHECKOUTTOKENS only after 100 times normal expiration. Bug #240.

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

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