Annotation of loncom/loncron, revision 1.40

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.11      www       319:     print $fh '<hr><a name="lonsql"><h2>lonsql</h2><h3>Log</h3><pre>';
1.23      www       320:     print "lonsql\n";
1.5       harris41  321:     if (-e "$perlvar{'lonDaemons'}/logs/lonsql.log"){
                    322: 	open (DFH,"tail -n100 $perlvar{'lonDaemons'}/logs/lonsql.log|");
                    323: 	while ($line=<DFH>) { 
                    324: 	    print $fh "$line";
                    325: 	    if ($line=~/INFO/) { $notices++; }
                    326: 	    if ($line=~/WARNING/) { $notices++; }
                    327: 	    if ($line=~/CRITICAL/) { $warnings++; }
                    328: 	};
                    329: 	close (DFH);
                    330:     }
                    331:     print $fh "</pre>";
                    332:     
                    333:     my $lonsqlfile="$perlvar{'lonDaemons'}/logs/lonsql.pid";
1.23      www       334:  
                    335:     $restartflag=1;
                    336:    
1.5       harris41  337:     if (-e $lonsqlfile) {
                    338: 	my $lfh=IO::File->new("$lonsqlfile");
                    339: 	my $lonsqlpid=<$lfh>;
                    340: 	chomp($lonsqlpid);
                    341: 	if (kill 0 => $lonsqlpid) {
                    342: 	    print $fh "<h3>lonsql at pid $lonsqlpid responding</h3>";
1.22      harris41  343: 	    $restartflag=0;
1.5       harris41  344: 	} else {
                    345: 	    $errors++; $errors++;
                    346: 	    print $fh "<h3>lonsql at pid $lonsqlpid not responding</h3>";
1.22      harris41  347: 		$restartflag=1;
1.23      www       348: 	print $fh 
                    349: 	    "<h3>Decided to clean up stale .pid file and restart lonsql</h3>";
1.5       harris41  350: 	}
1.22      harris41  351:     }
                    352:     if ($restartflag==1) {
1.5       harris41  353: 	$errors++;
1.23      www       354: 	         print $fh '<br><font color="red">Killall lonsql: '.
                    355:                     system('killall lonsql').' - ';
1.30      albertel  356:                     sleep 2;
1.23      www       357:                     print $fh unlink($lonsqlfile).' - '.
                    358:                               system('killall -9 lonsql').
                    359:                     '</font><br>';
1.5       harris41  360: 	print $fh "<h3>lonsql not running, trying to start</h3>";
1.16      harris41  361: 	system(
                    362:  "$perlvar{'lonDaemons'}/lonsql 2>>$perlvar{'lonDaemons'}/logs/lonsql_errors");
1.30      albertel  363: 	sleep 2;
1.5       harris41  364: 	if (-e $lonsqlfile) {
                    365: 	    print $fh "Seems like it started ...<p>";
                    366: 	    my $lfh=IO::File->new("$lonsqlfile");
                    367: 	    my $lonsqlpid=<$lfh>;
                    368: 	    chomp($lonsqlpid);
1.30      albertel  369: 	    sleep 2;
1.5       harris41  370: 	    if (kill 0 => $lonsqlpid) {
                    371: 		print $fh "<h3>lonsql at pid $lonsqlpid responding</h3>";
                    372: 	    } else {
                    373: 		$errors++; $errors++;
                    374: 		print $fh "<h3>lonsql at pid $lonsqlpid not responding</h3>";
                    375: 		print $fh "Give it one more try ...<p>";
1.16      harris41  376: 		system(
                    377:  "$perlvar{'lonDaemons'}/lonsql 2>>$perlvar{'lonDaemons'}/logs/lonsql_errors");
1.30      albertel  378: 		sleep 2;
1.5       harris41  379: 	    }
                    380: 	} else {
                    381: 	    print $fh "Seems like that did not work!<p>";
                    382: 	    $errors++;
                    383: 	}
                    384: 	if (-e "$perlvar{'lonDaemons'}/logs/lonsql.log"){
                    385: 	    print $fh "<p><pre>";
                    386: 	    open (DFH,"tail -n100 $perlvar{'lonDaemons'}/logs/lonsql.log|");
                    387: 	    while ($line=<DFH>) { 
                    388: 		print $fh "$line";
                    389: 		if ($line=~/WARNING/) { $notices++; }
                    390: 		if ($line=~/CRITICAL/) { $notices++; }
                    391: 	    };
                    392: 	    close (DFH);
                    393: 	    print $fh "</pre>";
                    394: 	}
                    395:     }
                    396: 
                    397:     $fname="$perlvar{'lonDaemons'}/logs/lonsql.log";
                    398: 
                    399:     my ($dev,$ino,$mode,$nlink,
                    400: 	$uid,$gid,$rdev,$size,
                    401: 	$atime,$mtime,$ctime,
                    402: 	$blksize,$blocks)=stat($fname);
                    403: 
1.38      albertel  404:     if ($size>200000) {
1.5       harris41  405: 	print $fh "Rotating logs ...<p>";
                    406: 	rename("$fname.2","$fname.3");
                    407: 	rename("$fname.1","$fname.2");
                    408: 	rename("$fname","$fname.1");
                    409:     }
                    410: 
                    411:     &errout($fh);
1.1       albertel  412: # ------------------------------------------------------------------------ lond
                    413: 
                    414: print $fh '<hr><a name="lond"><h2>lond</h2><h3>Log</h3><pre>';
1.23      www       415: print "lond\n";
1.1       albertel  416: 
                    417: if (-e "$perlvar{'lonDaemons'}/logs/lond.log"){
1.23      www       418: open (DFH,"tail -n25 $perlvar{'lonDaemons'}/logs/lond.log|");
1.1       albertel  419: while ($line=<DFH>) { 
                    420:    print $fh "$line";
1.3       www       421:    if ($line=~/INFO/) { $notices++; }
1.4       www       422:    if ($line=~/WARNING/) { $notices++; }
                    423:    if ($line=~/CRITICAL/) { $warnings++; }
1.1       albertel  424: };
                    425: close (DFH);
                    426: }
                    427: print $fh "</pre>";
                    428: 
                    429: my $londfile="$perlvar{'lonDaemons'}/logs/lond.pid";
                    430: 
1.22      harris41  431: $restartflag=1;
1.7       harris41  432: if (-e $londfile) {    
1.1       albertel  433:    my $lfh=IO::File->new("$londfile");
                    434:    my $londpid=<$lfh>;
                    435:    chomp($londpid);
                    436:    if (kill 0 => $londpid) {
1.25      www       437:       print $fh "<h3>lond at pid $londpid responding, sending USR1</h3>";
                    438:       kill USR1 => $londpid;
1.7       harris41  439:       $restartflag=0;
1.1       albertel  440:    } else {
1.8       harris41  441:       $errors++;
1.1       albertel  442:       print $fh "<h3>lond at pid $londpid not responding</h3>";
1.23      www       443:       $restartflag=1;
1.8       harris41  444:       print $fh 
1.23      www       445: 	  "<h3>Decided to clean up stale .pid file and restart lond</h3>";
1.1       albertel  446:    }
1.7       harris41  447: } 
                    448: if ($restartflag==1) {
1.1       albertel  449:    $errors++;
1.23      www       450: 	  print $fh '<br><font color="red">Killall lond: '.
                    451:                     system('killall lond').' - ';
1.30      albertel  452:           sleep 2;
1.23      www       453:           print $fh unlink($londfile).' - '.system('killall -9 lond').
                    454:                     '</font><br>';
1.1       albertel  455:    print $fh "<h3>lond not running, trying to start</h3>";
1.16      harris41  456:    system(
                    457:      "$perlvar{'lonDaemons'}/lond 2>>$perlvar{'lonDaemons'}/logs/lond_errors");
1.30      albertel  458:    sleep 2;
1.1       albertel  459:    if (-e $londfile) {
                    460:        print $fh "Seems like it started ...<p>";
                    461:        my $lfh=IO::File->new("$londfile");
                    462:        my $londpid=<$lfh>;
                    463:        chomp($londpid);
1.30      albertel  464:        sleep 2;
1.1       albertel  465:        if (kill 0 => $londpid) {
                    466:           print $fh "<h3>lond at pid $londpid responding</h3>";
                    467:        } else {
                    468:           $errors++; $errors++;
                    469:           print $fh "<h3>lond at pid $londpid not responding</h3>";
                    470:           print $fh "Give it one more try ...<p>";
1.16      harris41  471: 	  system(
                    472:  "$perlvar{'lonDaemons'}/lond 2>>$perlvar{'lonDaemons'}/logs/lond_errors");
1.30      albertel  473:           sleep 2;
1.1       albertel  474:        }
                    475:    } else {
                    476:        print $fh "Seems like that did not work!<p>";
                    477:        $errors++;
                    478:    }
1.3       www       479:    if (-e "$perlvar{'lonDaemons'}/logs/lond.log"){
                    480:     print $fh "<p><pre>";
                    481:     open (DFH,"tail -n100 $perlvar{'lonDaemons'}/logs/lond.log|");
                    482:     while ($line=<DFH>) { 
                    483:       print $fh "$line";
1.4       www       484:       if ($line=~/WARNING/) { $notices++; }
                    485:       if ($line=~/CRITICAL/) { $notices++; }
1.3       www       486:     };
                    487:     close (DFH);
                    488:     print $fh "</pre>";
                    489:    }
1.1       albertel  490: }
                    491: 
                    492: $fname="$perlvar{'lonDaemons'}/logs/lond.log";
                    493: 
                    494:                           my ($dev,$ino,$mode,$nlink,
                    495:                               $uid,$gid,$rdev,$size,
                    496:                               $atime,$mtime,$ctime,
                    497:                               $blksize,$blocks)=stat($fname);
                    498: 
                    499: if ($size>40000) {
                    500:     print $fh "Rotating logs ...<p>";
                    501:     rename("$fname.2","$fname.3");
                    502:     rename("$fname.1","$fname.2");
                    503:     rename("$fname","$fname.1");
                    504: }
                    505: 
                    506: &errout($fh);
                    507: # ------------------------------------------------------------------------ lonc
                    508: 
                    509: print $fh '<hr><a name="lonc"><h2>lonc</h2><h3>Log</h3><pre>';
1.23      www       510: print "lonc\n";
1.1       albertel  511: 
                    512: if (-e "$perlvar{'lonDaemons'}/logs/lonc.log"){
1.23      www       513: open (DFH,"tail -n25 $perlvar{'lonDaemons'}/logs/lonc.log|");
1.1       albertel  514: while ($line=<DFH>) { 
                    515:    print $fh "$line";
1.3       www       516:    if ($line=~/INFO/) { $notices++; }
1.4       www       517:    if ($line=~/WARNING/) { $notices++; }
                    518:    if ($line=~/CRITICAL/) { $warnings++; }
1.1       albertel  519: };
                    520: close (DFH);
                    521: }
                    522: print $fh "</pre>";
                    523: 
                    524: my $loncfile="$perlvar{'lonDaemons'}/logs/lonc.pid";
                    525: 
1.7       harris41  526: $restartflag=1;
1.1       albertel  527: if (-e $loncfile) {
                    528:    my $lfh=IO::File->new("$loncfile");
                    529:    my $loncpid=<$lfh>;
                    530:    chomp($loncpid);
                    531:    if (kill 0 => $loncpid) {
                    532:       print $fh "<h3>lonc at pid $loncpid responding, sending USR1</h3>";
                    533:       kill USR1 => $loncpid;
1.7       harris41  534:       $restartflag=0;
1.1       albertel  535:    } else {
1.8       harris41  536:       $errors++;
1.1       albertel  537:       print $fh "<h3>lonc at pid $loncpid not responding</h3>";
1.10      harris41  538:       # Solution: kill parent and children processes, remove .pid and restart
1.8       harris41  539: 	  $restartflag=1;
                    540:       print $fh 
1.23      www       541: 	  "<h3>Decided to clean up stale .pid file and restart lonc</h3>";
1.1       albertel  542:    }
1.7       harris41  543: } 
                    544: if ($restartflag==1) {
1.1       albertel  545:    $errors++;
1.23      www       546: 	  print $fh '<br><font color="red">Killall lonc: '.
                    547: 	            system('killall lonc').' - ';
1.30      albertel  548:           sleep 2;
1.23      www       549:           print $fh unlink($loncfile).' - '.system('killall -9 lonc').
                    550:                     '</font><br>';
1.1       albertel  551:    print $fh "<h3>lonc not running, trying to start</h3>";
1.16      harris41  552: 	system(
1.17      harris41  553:  "$perlvar{'lonDaemons'}/lonc 2>>$perlvar{'lonDaemons'}/logs/lonc_errors");
1.30      albertel  554:    sleep 2;
1.1       albertel  555:    if (-e $loncfile) {
                    556:        print $fh "Seems like it started ...<p>";
                    557:        my $lfh=IO::File->new("$loncfile");
                    558:        my $loncpid=<$lfh>;
                    559:        chomp($loncpid);
1.30      albertel  560:        sleep 2;
1.1       albertel  561:        if (kill 0 => $loncpid) {
                    562:           print $fh "<h3>lonc at pid $loncpid responding</h3>";
                    563:        } else {
                    564:           $errors++; $errors++;
                    565:           print $fh "<h3>lonc at pid $loncpid not responding</h3>";
                    566:           print $fh "Give it one more try ...<p>";
1.16      harris41  567:  	  system(
1.17      harris41  568:  "$perlvar{'lonDaemons'}/lonc 2>>$perlvar{'lonDaemons'}/logs/lonc_errors");
1.30      albertel  569:           sleep 2;
1.1       albertel  570:        }
                    571:    } else {
                    572:        print $fh "Seems like that did not work!<p>";
                    573:        $errors++;
                    574:    }
1.3       www       575:    if (-e "$perlvar{'lonDaemons'}/logs/lonc.log") {
                    576:     print $fh "<p><pre>";
                    577:     open (DFH,"tail -n100 $perlvar{'lonDaemons'}/logs/lonc.log|");
                    578:     while ($line=<DFH>) { 
                    579:       print $fh "$line";
1.4       www       580:       if ($line=~/WARNING/) { $notices++; }
                    581:       if ($line=~/CRITICAL/) { $notices++; }
1.3       www       582:     };
                    583:     close (DFH);
                    584:     print $fh "</pre>";
                    585:    }
1.1       albertel  586: }
                    587: 
                    588: $fname="$perlvar{'lonDaemons'}/logs/lonc.log";
1.34      www       589: 
                    590:                           my ($dev,$ino,$mode,$nlink,
                    591:                               $uid,$gid,$rdev,$size,
                    592:                               $atime,$mtime,$ctime,
                    593:                               $blksize,$blocks)=stat($fname);
                    594: 
                    595: if ($size>40000) {
                    596:     print $fh "Rotating logs ...<p>";
                    597:     rename("$fname.2","$fname.3");
                    598:     rename("$fname.1","$fname.2");
                    599:     rename("$fname","$fname.1");
                    600: }
                    601: 
                    602:    
                    603: &errout($fh);
                    604: # -------------------------------------------------------------------- lonhttpd
                    605: 
                    606: print $fh '<hr><a name="lonhttpd"><h2>lonhttpd</h2><h3>Log</h3><pre>';
                    607: print "lonhttpd\n";
                    608: 
                    609: if (-e "$perlvar{'lonDaemons'}/logs/lonhttpd.log"){
                    610: open (DFH,"tail -n25 $perlvar{'lonDaemons'}/logs/lonhttpd.log|");
                    611: while ($line=<DFH>) { 
                    612:    print $fh "$line";
                    613:    if ($line=~/INFO/) { $notices++; }
                    614:    if ($line=~/WARNING/) { $notices++; }
                    615:    if ($line=~/CRITICAL/) { $warnings++; }
                    616: };
                    617: close (DFH);
                    618: }
                    619: print $fh "</pre>";
                    620: 
                    621: my $lonhttpdfile="$perlvar{'lonDaemons'}/logs/lonhttpd.pid";
                    622: 
                    623: $restartflag=1;
                    624: if (-e $lonhttpdfile) {
                    625:    my $lfh=IO::File->new("$lonhttpdfile");
                    626:    my $lonhttpdpid=<$lfh>;
                    627:    chomp($lonhttpdpid);
                    628:    if (kill 0 => $lonhttpdpid) {
1.35      albertel  629:       print $fh "<h3>lonhttpd at pid $lonhttpdpid responding</h3>";
1.34      www       630:       $restartflag=0;
                    631:    } else {
                    632:       $errors++;
                    633:       print $fh "<h3>lonhttpd at pid $lonhttpdpid not responding</h3>";
                    634:       # Solution: kill parent and children processes, remove .pid and restart
                    635: 	  $restartflag=1;
                    636:       print $fh 
                    637: 	  "<h3>Decided to clean up stale .pid file and restart lonhttpd</h3>";
                    638:    }
                    639: } 
                    640: if ($restartflag==1) {
                    641:    $errors++;
                    642: 	  print $fh '<br><font color="red">Killall lonhttpd: '.
                    643: 	            system('killall lonhttpd').' - ';
                    644:           sleep 2;
                    645:           print $fh unlink($lonhttpdfile).' - '.system('killall -9 lonhttpd').
                    646:                     '</font><br>';
                    647:    print $fh "<h3>lonhttpd not running, trying to start</h3>";
                    648: 	system(
                    649:  "$perlvar{'lonDaemons'}/lonhttpd 2>>$perlvar{'lonDaemons'}/logs/lonhttpd_errors");
                    650:    sleep 2;
                    651:    if (-e $lonhttpdfile) {
                    652:        print $fh "Seems like it started ...<p>";
                    653:        my $lfh=IO::File->new("$lonhttpdfile");
                    654:        my $lonhttpdpid=<$lfh>;
                    655:        chomp($lonhttpdpid);
                    656:        sleep 2;
                    657:        if (kill 0 => $lonhttpdpid) {
                    658:           print $fh "<h3>lonhttpd at pid $lonhttpdpid responding</h3>";
                    659:        } else {
                    660:           $errors++; $errors++;
                    661:           print $fh "<h3>lonhttpd at pid $lonhttpdpid not responding</h3>";
                    662:           print $fh "Give it one more try ...<p>";
                    663:  	  system(
                    664:  "$perlvar{'lonDaemons'}/lonhttpd 2>>$perlvar{'lonDaemons'}/logs/lonhttpd_errors");
                    665:           sleep 2;
                    666:        }
                    667:    } else {
                    668:        print $fh "Seems like that did not work!<p>";
                    669:        $errors++;
                    670:    }
                    671:    if (-e "$perlvar{'lonDaemons'}/logs/lonhttpd.log") {
                    672:     print $fh "<p><pre>";
                    673:     open (DFH,"tail -n100 $perlvar{'lonDaemons'}/logs/lonhttpd.log|");
                    674:     while ($line=<DFH>) { 
                    675:       print $fh "$line";
                    676:       if ($line=~/WARNING/) { $notices++; }
                    677:       if ($line=~/CRITICAL/) { $notices++; }
                    678:     };
                    679:     close (DFH);
                    680:     print $fh "</pre>";
                    681:    }
                    682: }
                    683: 
                    684: $fname="$perlvar{'lonDaemons'}/logs/lonhttpd.log";
1.1       albertel  685: 
                    686:                           my ($dev,$ino,$mode,$nlink,
                    687:                               $uid,$gid,$rdev,$size,
                    688:                               $atime,$mtime,$ctime,
                    689:                               $blksize,$blocks)=stat($fname);
                    690: 
                    691: if ($size>40000) {
                    692:     print $fh "Rotating logs ...<p>";
                    693:     rename("$fname.2","$fname.3");
                    694:     rename("$fname.1","$fname.2");
                    695:     rename("$fname","$fname.1");
                    696: }
                    697: 
                    698:    
                    699: &errout($fh);
                    700: # ---------------------------------------------------------------------- lonnet
                    701: 
                    702: print $fh '<hr><a name="lonnet"><h2>lonnet</h2><h3>Temp Log</h3><pre>';
1.23      www       703: print "lonnet\n";
1.1       albertel  704: if (-e "$perlvar{'lonDaemons'}/logs/lonnet.log"){
                    705: open (DFH,"tail -n50 $perlvar{'lonDaemons'}/logs/lonnet.log|");
                    706: while ($line=<DFH>) { 
                    707:     print $fh "$line";
                    708: };
                    709: close (DFH);
                    710: }
1.11      www       711: print $fh "</pre><h3>Perm Log</h3><pre>";
1.1       albertel  712: 
                    713: if (-e "$perlvar{'lonDaemons'}/logs/lonnet.perm.log") {
                    714:     open(DFH,"tail -n10 $perlvar{'lonDaemons'}/logs/lonnet.perm.log|");
                    715: while ($line=<DFH>) { 
                    716:    print $fh "$line";
                    717: };
                    718: close (DFH);
                    719: } else { print $fh "No perm log\n" }
                    720: 
                    721: $fname="$perlvar{'lonDaemons'}/logs/lonnet.log";
                    722: 
                    723:                           my ($dev,$ino,$mode,$nlink,
                    724:                               $uid,$gid,$rdev,$size,
                    725:                               $atime,$mtime,$ctime,
                    726:                               $blksize,$blocks)=stat($fname);
                    727: 
                    728: if ($size>40000) {
                    729:     print $fh "Rotating logs ...<p>";
                    730:     rename("$fname.2","$fname.3");
                    731:     rename("$fname.1","$fname.2");
                    732:     rename("$fname","$fname.1");
                    733: }
                    734: 
                    735: print $fh "</pre>";
                    736: &errout($fh);
                    737: # ----------------------------------------------------------------- Connections
                    738: 
                    739: print $fh '<hr><a name="connections"><h2>Connections</h2>';
                    740: 
                    741: print $fh "<table border=2>";
1.31      albertel  742: foreach $tryserver (sort(keys(%hostname))) {
1.1       albertel  743: 
                    744:     $answer=reply("pong",$tryserver);
                    745:     if ($answer eq "$tryserver:$perlvar{'lonHostID'}") {
                    746: 	$result="<b>ok</b>";
                    747:     } else {
                    748:         $result=$answer;
                    749:         $warnings++;
                    750:         if ($answer eq 'con_lost') { $warnings++; }
                    751:     }
                    752:     print $fh "<tr><td>$tryserver</td><td>$result</td></tr>\n";
                    753: 
                    754: }
                    755: print $fh "</table>";
                    756: 
                    757: &errout($fh);
                    758: # ------------------------------------------------------------ Delayed messages
                    759: 
                    760: print $fh '<hr><a name="delayed"><h2>Delayed Messages</h2>';
1.23      www       761: print "buffers\n";
1.1       albertel  762: 
                    763: print $fh '<h3>Scanning Permanent Log</h3>';
                    764: 
                    765: $unsend=0;
                    766: {
                    767:     my $dfh=IO::File->new("$perlvar{'lonDaemons'}/logs/lonnet.perm.log");
                    768:     while ($line=<$dfh>) {
                    769: 	($time,$sdf,$dserv,$dcmd)=split(/:/,$line);
                    770:         if ($sdf eq 'F') { 
                    771: 	    $local=localtime($time);
                    772:             print "<b>Failed: $time, $dserv, $dcmd</b><br>";
                    773:             $warnings++;
                    774:         }
                    775:         if ($sdf eq 'S') { $unsend--; }
                    776:         if ($sdf eq 'D') { $unsend++; }
                    777:     }
                    778: }
                    779: print $fh "Total unsend messages: <b>$unsend</b><p>\n";
                    780: $warnings=$warnings+5*$unsend;
                    781: 
                    782: print $fh "<h3>Outgoing Buffer</h3>";
                    783: 
                    784: open (DFH,"ls -lF $perlvar{'lonSockDir'}/delayed|");
                    785: while ($line=<DFH>) { 
                    786:     print $fh "$line<br>";
                    787: };
                    788: close (DFH);
                    789: 
                    790: # ------------------------------------------------------------------------- End
                    791: print $fh "<a name=errcount>\n";
                    792: $totalcount=$notices+4*$warnings+100*$errors;
                    793: &errout($fh);
                    794: print $fh "<h1>Total Error Count: $totalcount</h1>";
                    795: $now=time;
                    796: $date=localtime($now);
                    797: print $fh "<hr>$date ($now)</body></html>\n";
1.23      www       798: print "writing done\n";
1.1       albertel  799: }
                    800: 
                    801: rename ("$statusdir/newstatus.html","$statusdir/index.html");
                    802: 
                    803: if ($totalcount>200) {
1.23      www       804:    print "mailing\n";
1.37      www       805:    $emailto="$perlvar{'lonAdmEMail'}";
1.40    ! www       806:    if ($totalcount>1000) {
1.37      www       807:       $emailto.=",$perlvar{'lonSysEMail'}";
                    808:    }
1.1       albertel  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>