Annotation of loncom/loncron, revision 1.36

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

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