File:  [LON-CAPA] / loncom / loncron
Revision 1.18: download - view: text, annotated - select for diffs
Thu Mar 15 13:20:46 2001 UTC (23 years, 1 month ago) by harris41
Branches: MAIN
CVS tags: HEAD
enabling lonsql on library servers -Scott

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

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