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

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