File:  [LON-CAPA] / loncom / loncron
Revision 1.32: download - view: text, annotated - select for diffs
Sat Jul 27 19:06:41 2002 UTC (21 years, 9 months ago) by www
Branches: MAIN
CVS tags: version_0_5_1, version_0_5, HEAD
Toward bug 481.

To use token-based access, use for example

'<img src="'.&Apache::lonnet::tokenwrapper($fulluri).'" />'

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

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