Annotation of loncom/loncron, revision 1.34

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.20      harris41   12: # 12/6/2000,12/8 Scott Harrison
1.11      www        13: # 12/23 Gerd Kortemeyer
1.22      harris41   14: # YEAR=2001
                     15: # 1/10/2001, 2/12/, 2/26, 3/15, 04/11, 04/21,8/27 Scott Harrison
1.25      www        16: # 09/04,09/06,11/26 Gerd Kortemeyer
1.26      harris41   17: # YEAR=2002
                     18: # 5/11/2002 Scott Harrison
1.24      www        19: 
                     20: $|=1;
1.1       albertel   21: 
1.26      harris41   22: use lib '/home/httpd/lib/perl/';
                     23: use LONCAPA::Configuration;
                     24: 
1.1       albertel   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: 
1.27      matthew    58: # --------------------------------- Read loncapa_apache.conf and loncapa.conf
1.33      harris41   59: my $perlvarref=LONCAPA::Configuration::read_conf('loncapa.conf');
1.28      albertel   60: %perlvar=%{$perlvarref};
1.26      harris41   61: undef $perlvarref;
                     62: delete $perlvar{'lonReceipt'}; # remove since sensitive and not needed
                     63: delete $perlvar{'lonSqlAccess'}; # remove since sensitive and not needed
1.13      harris41   64: 
1.14      harris41   65: # --------------------------------------- Make sure that LON-CAPA is configured
                     66: # I only test for one thing here (lonHostID).  This is just a safeguard.
                     67: if ('{[[[[lonHostID]]]]}' eq $perlvar{'lonHostID'}) {
1.15      harris41   68:    print("Unconfigured machine.\n");
1.14      harris41   69:    $emailto=$perlvar{'lonSysEMail'};
                     70:    $hostname=`/bin/hostname`;
                     71:    chop $hostname;
                     72:    $hostname=~s/[^\w\.]//g; # make sure is safe to pass through shell
                     73:    $subj="LON: Unconfigured machine $hostname";
                     74:    system("echo 'Unconfigured machine $hostname.' |\
                     75:  mailto $emailto -s '$subj' > /dev/null");
                     76:     exit 1;
                     77: }
                     78: 
1.13      harris41   79: # ----------------------------- Make sure this process is running from user=www
                     80: my $wwwid=getpwnam('www');
                     81: if ($wwwid!=$<) {
1.14      harris41   82:    print("User ID mismatch.  This program must be run as user 'www'\n");
1.13      harris41   83:    $emailto="$perlvar{'lonAdmEMail'},$perlvar{'lonSysEMail'}";
                     84:    $subj="LON: $perlvar{'lonHostID'} User ID mismatch";
                     85:    system("echo 'User ID mismatch.  loncron must be run as user www.' |\
                     86:  mailto $emailto -s '$subj' > /dev/null");
1.14      harris41   87:    exit 1;
1.1       albertel   88: }
                     89: 
                     90: # ------------------------------------------------------------- Read hosts file
                     91: {
                     92:     my $config=IO::File->new("$perlvar{'lonTabDir'}/hosts.tab");
                     93: 
                     94:     while (my $configline=<$config>) {
1.31      albertel   95: 	my ($id,$domain,$role,$name,$ip,$domdescr)=split(/:/,$configline);
                     96: 	if ($id && $domain && $role && $name && $ip) {
                     97: 	    $hostname{$id}=$name;
                     98: 	    $hostdom{$id}=$domain;
                     99: 	    $hostip{$id}=$ip;
                    100: 	    $hostrole{$id}=$role;
                    101: 	    if ($domdescr) { $domaindescription{$domain}=$domdescr; }
                    102: 	    if (($role eq 'library') && ($id ne $perlvar{'lonHostID'})) {
                    103: 		$libserv{$id}=$name;
                    104: 	    }
                    105: 	} else {
                    106: 	    if ($configline) {
                    107: #		&logthis("Skipping hosts.tab line -$configline-");
                    108: 	    }
                    109: 	}
1.1       albertel  110:     }
                    111: }
                    112: 
                    113: # ------------------------------------------------------ Read spare server file
                    114: {
                    115:     my $config=IO::File->new("$perlvar{'lonTabDir'}/spare.tab");
                    116: 
                    117:     while (my $configline=<$config>) {
                    118:        chomp($configline);
                    119:        if (($configline) && ($configline ne $perlvar{'lonHostID'})) {
                    120:           $spareid{$configline}=1;
                    121:        }
                    122:     }
                    123: }
                    124: 
                    125: # ---------------------------------------------------------------- Start report
                    126: 
                    127: $statusdir="/home/httpd/html/lon-status";
                    128: 
                    129: $errors=0;
                    130: $warnings=0;
                    131: $notices=0;
                    132: 
                    133: $now=time;
                    134: $date=localtime($now);
                    135: 
                    136: {
                    137: my $fh=IO::File->new(">$statusdir/newstatus.html");
                    138: 
                    139: print $fh (<<ENDHEADERS);
                    140: <html>
                    141: <head>
                    142: <title>LON Status Report $perlvar{'lonHostID'}</title>
                    143: </head>
1.3       www       144: <body bgcolor="#AAAAAA">
1.1       albertel  145: <a name="top">
                    146: <h1>LON Status Report $perlvar{'lonHostID'}</h1>
                    147: <h2>$date ($now)</h2>
                    148: <ol>
                    149: <li><a href="#configuration">Configuration</a>
                    150: <li><a href="#machine">Machine Information</a>
1.11      www       151: <li><a href="#tmp">Temporary Files</a>
                    152: <li><a href="#tokens">Session Tokens</a>
1.1       albertel  153: <li><a href="#httpd">httpd</a>
1.11      www       154: <li><a href="#lonsql">lonsql</a>
1.1       albertel  155: <li><a href="#lond">lond</a>
                    156: <li><a href="#lonc">lonc</a>
1.34    ! www       157: <li><a href="#lonhttpd">lonhttpd</a>
1.1       albertel  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: 
1.31      albertel  170: foreach $varname (sort(keys(%perlvar))) {
1.1       albertel  171:     print $fh "<tr><td>$varname</td><td>$perlvar{$varname}</td></tr>\n";
                    172: }
                    173: print $fh "</table><h3>Hosts</h3><table border=2>";
1.31      albertel  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";
1.1       albertel  178: }
                    179: print $fh "</table><h3>Spare Hosts</h3><ol>";
1.31      albertel  180: foreach $id (sort(keys(%spareid))) {
1.1       albertel  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);
1.4       www       198: if ($parts[1]>4.0) {
1.1       albertel  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) { 
1.24      www       216:       $warnings++;
                    217:       $notices++; 
1.1       albertel  218:    } elsif ($usage>80) {
                    219:       $warnings++;
                    220:    } elsif ($usage>60) {
                    221:       $notices++;
                    222:    }
1.4       www       223:    if ($usage>95) { $warnings++; $warnings++ }
1.1       albertel  224: }
                    225: close (DFH);
                    226: print $fh "</pre>";
1.24      www       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: 
1.1       albertel  244: &errout($fh);
1.11      www       245: 
                    246: # --------------------------------------------------------------- clean out tmp
                    247: print $fh '<hr><a name="tmp"><h2>Temporary Files</h2>';
                    248: $cleaned=0;
1.29      www       249: $old=0;
1.11      www       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'}) {
1.29      www       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 {
1.32      www       267: 				  if ($since>365*$perlvar{'lonExpire'}) {
1.29      www       268:                                      $cleaned++;
                    269:                                      unlink("$fname");
                    270: 				 } else { $old++; }
                    271:                               }
1.11      www       272:                           }
                    273:     
                    274: }
1.29      www       275: print $fh "Cleaned up ".$cleaned." files (".$old." old checkout tokens).";
1.11      www       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: 
1.1       albertel  300: # ----------------------------------------------------------------------- httpd
                    301: 
                    302: print $fh '<hr><a name="httpd"><h2>httpd</h2><h3>Access Log</h3><pre>';
                    303: 
1.23      www       304: open (DFH,"tail -n25 /etc/httpd/logs/access_log|");
1.1       albertel  305: while ($line=<DFH>) { print $fh "$line" };
                    306: close (DFH);
                    307: 
                    308: print $fh "</pre><h3>Error Log</h3><pre>";
                    309: 
1.23      www       310: open (DFH,"tail -n25 /etc/httpd/logs/error_log|");
1.1       albertel  311: while ($line=<DFH>) { 
                    312:    print $fh "$line";
                    313:    if ($line=~/\[error\]/) { $notices++; } 
                    314: };
                    315: close (DFH);
                    316: print $fh "</pre>";
                    317: &errout($fh);
1.5       harris41  318: 
                    319: 
1.11      www       320: # ---------------------------------------------------------------------- lonsql
1.22      harris41  321: 
                    322: my $restartflag=1;
1.18      harris41  323: if ($perlvar{'lonRole'} eq "library") {
1.5       harris41  324: 
1.11      www       325:     print $fh '<hr><a name="lonsql"><h2>lonsql</h2><h3>Log</h3><pre>';
1.23      www       326:     print "lonsql\n";
1.5       harris41  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";
1.23      www       340:  
                    341:     $restartflag=1;
                    342:    
1.5       harris41  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>";
1.22      harris41  349: 	    $restartflag=0;
1.5       harris41  350: 	} else {
                    351: 	    $errors++; $errors++;
                    352: 	    print $fh "<h3>lonsql at pid $lonsqlpid not responding</h3>";
1.22      harris41  353: 		$restartflag=1;
1.23      www       354: 	print $fh 
                    355: 	    "<h3>Decided to clean up stale .pid file and restart lonsql</h3>";
1.5       harris41  356: 	}
1.22      harris41  357:     }
                    358:     if ($restartflag==1) {
1.5       harris41  359: 	$errors++;
1.23      www       360: 	         print $fh '<br><font color="red">Killall lonsql: '.
                    361:                     system('killall lonsql').' - ';
1.30      albertel  362:                     sleep 2;
1.23      www       363:                     print $fh unlink($lonsqlfile).' - '.
                    364:                               system('killall -9 lonsql').
                    365:                     '</font><br>';
1.5       harris41  366: 	print $fh "<h3>lonsql not running, trying to start</h3>";
1.16      harris41  367: 	system(
                    368:  "$perlvar{'lonDaemons'}/lonsql 2>>$perlvar{'lonDaemons'}/logs/lonsql_errors");
1.30      albertel  369: 	sleep 2;
1.5       harris41  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);
1.30      albertel  375: 	    sleep 2;
1.5       harris41  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>";
1.16      harris41  382: 		system(
                    383:  "$perlvar{'lonDaemons'}/lonsql 2>>$perlvar{'lonDaemons'}/logs/lonsql_errors");
1.30      albertel  384: 		sleep 2;
1.5       harris41  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: }
1.1       albertel  419: # ------------------------------------------------------------------------ lond
                    420: 
                    421: print $fh '<hr><a name="lond"><h2>lond</h2><h3>Log</h3><pre>';
1.23      www       422: print "lond\n";
1.1       albertel  423: 
                    424: if (-e "$perlvar{'lonDaemons'}/logs/lond.log"){
1.23      www       425: open (DFH,"tail -n25 $perlvar{'lonDaemons'}/logs/lond.log|");
1.1       albertel  426: while ($line=<DFH>) { 
                    427:    print $fh "$line";
1.3       www       428:    if ($line=~/INFO/) { $notices++; }
1.4       www       429:    if ($line=~/WARNING/) { $notices++; }
                    430:    if ($line=~/CRITICAL/) { $warnings++; }
1.1       albertel  431: };
                    432: close (DFH);
                    433: }
                    434: print $fh "</pre>";
                    435: 
                    436: my $londfile="$perlvar{'lonDaemons'}/logs/lond.pid";
                    437: 
1.22      harris41  438: $restartflag=1;
1.7       harris41  439: if (-e $londfile) {    
1.1       albertel  440:    my $lfh=IO::File->new("$londfile");
                    441:    my $londpid=<$lfh>;
                    442:    chomp($londpid);
                    443:    if (kill 0 => $londpid) {
1.25      www       444:       print $fh "<h3>lond at pid $londpid responding, sending USR1</h3>";
                    445:       kill USR1 => $londpid;
1.7       harris41  446:       $restartflag=0;
1.1       albertel  447:    } else {
1.8       harris41  448:       $errors++;
1.1       albertel  449:       print $fh "<h3>lond at pid $londpid not responding</h3>";
1.23      www       450:       $restartflag=1;
1.8       harris41  451:       print $fh 
1.23      www       452: 	  "<h3>Decided to clean up stale .pid file and restart lond</h3>";
1.1       albertel  453:    }
1.7       harris41  454: } 
                    455: if ($restartflag==1) {
1.1       albertel  456:    $errors++;
1.23      www       457: 	  print $fh '<br><font color="red">Killall lond: '.
                    458:                     system('killall lond').' - ';
1.30      albertel  459:           sleep 2;
1.23      www       460:           print $fh unlink($londfile).' - '.system('killall -9 lond').
                    461:                     '</font><br>';
1.1       albertel  462:    print $fh "<h3>lond not running, trying to start</h3>";
1.16      harris41  463:    system(
                    464:      "$perlvar{'lonDaemons'}/lond 2>>$perlvar{'lonDaemons'}/logs/lond_errors");
1.30      albertel  465:    sleep 2;
1.1       albertel  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);
1.30      albertel  471:        sleep 2;
1.1       albertel  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>";
1.16      harris41  478: 	  system(
                    479:  "$perlvar{'lonDaemons'}/lond 2>>$perlvar{'lonDaemons'}/logs/lond_errors");
1.30      albertel  480:           sleep 2;
1.1       albertel  481:        }
                    482:    } else {
                    483:        print $fh "Seems like that did not work!<p>";
                    484:        $errors++;
                    485:    }
1.3       www       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";
1.4       www       491:       if ($line=~/WARNING/) { $notices++; }
                    492:       if ($line=~/CRITICAL/) { $notices++; }
1.3       www       493:     };
                    494:     close (DFH);
                    495:     print $fh "</pre>";
                    496:    }
1.1       albertel  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>';
1.23      www       517: print "lonc\n";
1.1       albertel  518: 
                    519: if (-e "$perlvar{'lonDaemons'}/logs/lonc.log"){
1.23      www       520: open (DFH,"tail -n25 $perlvar{'lonDaemons'}/logs/lonc.log|");
1.1       albertel  521: while ($line=<DFH>) { 
                    522:    print $fh "$line";
1.3       www       523:    if ($line=~/INFO/) { $notices++; }
1.4       www       524:    if ($line=~/WARNING/) { $notices++; }
                    525:    if ($line=~/CRITICAL/) { $warnings++; }
1.1       albertel  526: };
                    527: close (DFH);
                    528: }
                    529: print $fh "</pre>";
                    530: 
                    531: my $loncfile="$perlvar{'lonDaemons'}/logs/lonc.pid";
                    532: 
1.7       harris41  533: $restartflag=1;
1.1       albertel  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;
1.7       harris41  541:       $restartflag=0;
1.1       albertel  542:    } else {
1.8       harris41  543:       $errors++;
1.1       albertel  544:       print $fh "<h3>lonc at pid $loncpid not responding</h3>";
1.10      harris41  545:       # Solution: kill parent and children processes, remove .pid and restart
1.8       harris41  546: 	  $restartflag=1;
                    547:       print $fh 
1.23      www       548: 	  "<h3>Decided to clean up stale .pid file and restart lonc</h3>";
1.1       albertel  549:    }
1.7       harris41  550: } 
                    551: if ($restartflag==1) {
1.1       albertel  552:    $errors++;
1.23      www       553: 	  print $fh '<br><font color="red">Killall lonc: '.
                    554: 	            system('killall lonc').' - ';
1.30      albertel  555:           sleep 2;
1.23      www       556:           print $fh unlink($loncfile).' - '.system('killall -9 lonc').
                    557:                     '</font><br>';
1.1       albertel  558:    print $fh "<h3>lonc not running, trying to start</h3>";
1.16      harris41  559: 	system(
1.17      harris41  560:  "$perlvar{'lonDaemons'}/lonc 2>>$perlvar{'lonDaemons'}/logs/lonc_errors");
1.30      albertel  561:    sleep 2;
1.1       albertel  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);
1.30      albertel  567:        sleep 2;
1.1       albertel  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>";
1.16      harris41  574:  	  system(
1.17      harris41  575:  "$perlvar{'lonDaemons'}/lonc 2>>$perlvar{'lonDaemons'}/logs/lonc_errors");
1.30      albertel  576:           sleep 2;
1.1       albertel  577:        }
                    578:    } else {
                    579:        print $fh "Seems like that did not work!<p>";
                    580:        $errors++;
                    581:    }
1.3       www       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";
1.4       www       587:       if ($line=~/WARNING/) { $notices++; }
                    588:       if ($line=~/CRITICAL/) { $notices++; }
1.3       www       589:     };
                    590:     close (DFH);
                    591:     print $fh "</pre>";
                    592:    }
1.1       albertel  593: }
                    594: 
                    595: $fname="$perlvar{'lonDaemons'}/logs/lonc.log";
1.34    ! www       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: # -------------------------------------------------------------------- lonhttpd
        !           612: 
        !           613: print $fh '<hr><a name="lonhttpd"><h2>lonhttpd</h2><h3>Log</h3><pre>';
        !           614: print "lonhttpd\n";
        !           615: 
        !           616: if (-e "$perlvar{'lonDaemons'}/logs/lonhttpd.log"){
        !           617: open (DFH,"tail -n25 $perlvar{'lonDaemons'}/logs/lonhttpd.log|");
        !           618: while ($line=<DFH>) { 
        !           619:    print $fh "$line";
        !           620:    if ($line=~/INFO/) { $notices++; }
        !           621:    if ($line=~/WARNING/) { $notices++; }
        !           622:    if ($line=~/CRITICAL/) { $warnings++; }
        !           623: };
        !           624: close (DFH);
        !           625: }
        !           626: print $fh "</pre>";
        !           627: 
        !           628: my $lonhttpdfile="$perlvar{'lonDaemons'}/logs/lonhttpd.pid";
        !           629: 
        !           630: $restartflag=1;
        !           631: if (-e $lonhttpdfile) {
        !           632:    my $lfh=IO::File->new("$lonhttpdfile");
        !           633:    my $lonhttpdpid=<$lfh>;
        !           634:    chomp($lonhttpdpid);
        !           635:    if (kill 0 => $lonhttpdpid) {
        !           636:       print $fh "<h3>lonhttpd at pid $lonhttpdpid responding, sending USR1</h3>";
        !           637:       kill USR1 => $lonhttpdpid;
        !           638:       $restartflag=0;
        !           639:    } else {
        !           640:       $errors++;
        !           641:       print $fh "<h3>lonhttpd at pid $lonhttpdpid not responding</h3>";
        !           642:       # Solution: kill parent and children processes, remove .pid and restart
        !           643: 	  $restartflag=1;
        !           644:       print $fh 
        !           645: 	  "<h3>Decided to clean up stale .pid file and restart lonhttpd</h3>";
        !           646:    }
        !           647: } 
        !           648: if ($restartflag==1) {
        !           649:    $errors++;
        !           650: 	  print $fh '<br><font color="red">Killall lonhttpd: '.
        !           651: 	            system('killall lonhttpd').' - ';
        !           652:           sleep 2;
        !           653:           print $fh unlink($lonhttpdfile).' - '.system('killall -9 lonhttpd').
        !           654:                     '</font><br>';
        !           655:    print $fh "<h3>lonhttpd not running, trying to start</h3>";
        !           656: 	system(
        !           657:  "$perlvar{'lonDaemons'}/lonhttpd 2>>$perlvar{'lonDaemons'}/logs/lonhttpd_errors");
        !           658:    sleep 2;
        !           659:    if (-e $lonhttpdfile) {
        !           660:        print $fh "Seems like it started ...<p>";
        !           661:        my $lfh=IO::File->new("$lonhttpdfile");
        !           662:        my $lonhttpdpid=<$lfh>;
        !           663:        chomp($lonhttpdpid);
        !           664:        sleep 2;
        !           665:        if (kill 0 => $lonhttpdpid) {
        !           666:           print $fh "<h3>lonhttpd at pid $lonhttpdpid responding</h3>";
        !           667:        } else {
        !           668:           $errors++; $errors++;
        !           669:           print $fh "<h3>lonhttpd at pid $lonhttpdpid not responding</h3>";
        !           670:           print $fh "Give it one more try ...<p>";
        !           671:  	  system(
        !           672:  "$perlvar{'lonDaemons'}/lonhttpd 2>>$perlvar{'lonDaemons'}/logs/lonhttpd_errors");
        !           673:           sleep 2;
        !           674:        }
        !           675:    } else {
        !           676:        print $fh "Seems like that did not work!<p>";
        !           677:        $errors++;
        !           678:    }
        !           679:    if (-e "$perlvar{'lonDaemons'}/logs/lonhttpd.log") {
        !           680:     print $fh "<p><pre>";
        !           681:     open (DFH,"tail -n100 $perlvar{'lonDaemons'}/logs/lonhttpd.log|");
        !           682:     while ($line=<DFH>) { 
        !           683:       print $fh "$line";
        !           684:       if ($line=~/WARNING/) { $notices++; }
        !           685:       if ($line=~/CRITICAL/) { $notices++; }
        !           686:     };
        !           687:     close (DFH);
        !           688:     print $fh "</pre>";
        !           689:    }
        !           690: }
        !           691: 
        !           692: $fname="$perlvar{'lonDaemons'}/logs/lonhttpd.log";
1.1       albertel  693: 
                    694:                           my ($dev,$ino,$mode,$nlink,
                    695:                               $uid,$gid,$rdev,$size,
                    696:                               $atime,$mtime,$ctime,
                    697:                               $blksize,$blocks)=stat($fname);
                    698: 
                    699: if ($size>40000) {
                    700:     print $fh "Rotating logs ...<p>";
                    701:     rename("$fname.2","$fname.3");
                    702:     rename("$fname.1","$fname.2");
                    703:     rename("$fname","$fname.1");
                    704: }
                    705: 
                    706:    
                    707: &errout($fh);
                    708: # ---------------------------------------------------------------------- lonnet
                    709: 
                    710: print $fh '<hr><a name="lonnet"><h2>lonnet</h2><h3>Temp Log</h3><pre>';
1.23      www       711: print "lonnet\n";
1.1       albertel  712: if (-e "$perlvar{'lonDaemons'}/logs/lonnet.log"){
                    713: open (DFH,"tail -n50 $perlvar{'lonDaemons'}/logs/lonnet.log|");
                    714: while ($line=<DFH>) { 
                    715:     print $fh "$line";
                    716: };
                    717: close (DFH);
                    718: }
1.11      www       719: print $fh "</pre><h3>Perm Log</h3><pre>";
1.1       albertel  720: 
                    721: if (-e "$perlvar{'lonDaemons'}/logs/lonnet.perm.log") {
                    722:     open(DFH,"tail -n10 $perlvar{'lonDaemons'}/logs/lonnet.perm.log|");
                    723: while ($line=<DFH>) { 
                    724:    print $fh "$line";
                    725: };
                    726: close (DFH);
                    727: } else { print $fh "No perm log\n" }
                    728: 
                    729: $fname="$perlvar{'lonDaemons'}/logs/lonnet.log";
                    730: 
                    731:                           my ($dev,$ino,$mode,$nlink,
                    732:                               $uid,$gid,$rdev,$size,
                    733:                               $atime,$mtime,$ctime,
                    734:                               $blksize,$blocks)=stat($fname);
                    735: 
                    736: if ($size>40000) {
                    737:     print $fh "Rotating logs ...<p>";
                    738:     rename("$fname.2","$fname.3");
                    739:     rename("$fname.1","$fname.2");
                    740:     rename("$fname","$fname.1");
                    741: }
                    742: 
                    743: print $fh "</pre>";
                    744: &errout($fh);
                    745: # ----------------------------------------------------------------- Connections
                    746: 
                    747: print $fh '<hr><a name="connections"><h2>Connections</h2>';
                    748: 
                    749: print $fh "<table border=2>";
1.31      albertel  750: foreach $tryserver (sort(keys(%hostname))) {
1.1       albertel  751: 
                    752:     $answer=reply("pong",$tryserver);
                    753:     if ($answer eq "$tryserver:$perlvar{'lonHostID'}") {
                    754: 	$result="<b>ok</b>";
                    755:     } else {
                    756:         $result=$answer;
                    757:         $warnings++;
                    758:         if ($answer eq 'con_lost') { $warnings++; }
                    759:     }
                    760:     print $fh "<tr><td>$tryserver</td><td>$result</td></tr>\n";
                    761: 
                    762: }
                    763: print $fh "</table>";
                    764: 
                    765: &errout($fh);
                    766: # ------------------------------------------------------------ Delayed messages
                    767: 
                    768: print $fh '<hr><a name="delayed"><h2>Delayed Messages</h2>';
1.23      www       769: print "buffers\n";
1.1       albertel  770: 
                    771: print $fh '<h3>Scanning Permanent Log</h3>';
                    772: 
                    773: $unsend=0;
                    774: {
                    775:     my $dfh=IO::File->new("$perlvar{'lonDaemons'}/logs/lonnet.perm.log");
                    776:     while ($line=<$dfh>) {
                    777: 	($time,$sdf,$dserv,$dcmd)=split(/:/,$line);
                    778:         if ($sdf eq 'F') { 
                    779: 	    $local=localtime($time);
                    780:             print "<b>Failed: $time, $dserv, $dcmd</b><br>";
                    781:             $warnings++;
                    782:         }
                    783:         if ($sdf eq 'S') { $unsend--; }
                    784:         if ($sdf eq 'D') { $unsend++; }
                    785:     }
                    786: }
                    787: print $fh "Total unsend messages: <b>$unsend</b><p>\n";
                    788: $warnings=$warnings+5*$unsend;
                    789: 
                    790: print $fh "<h3>Outgoing Buffer</h3>";
                    791: 
                    792: open (DFH,"ls -lF $perlvar{'lonSockDir'}/delayed|");
                    793: while ($line=<DFH>) { 
                    794:     print $fh "$line<br>";
                    795: };
                    796: close (DFH);
                    797: 
                    798: # ------------------------------------------------------------------------- End
                    799: print $fh "<a name=errcount>\n";
                    800: $totalcount=$notices+4*$warnings+100*$errors;
                    801: &errout($fh);
                    802: print $fh "<h1>Total Error Count: $totalcount</h1>";
                    803: $now=time;
                    804: $date=localtime($now);
                    805: print $fh "<hr>$date ($now)</body></html>\n";
1.23      www       806: print "writing done\n";
1.1       albertel  807: }
                    808: 
                    809: rename ("$statusdir/newstatus.html","$statusdir/index.html");
                    810: 
                    811: if ($totalcount>200) {
1.23      www       812:    print "mailing\n";
1.1       albertel  813:    $emailto="$perlvar{'lonAdmEMail'},$perlvar{'lonSysEMail'}";
                    814:    $subj="LON: $perlvar{'lonHostID'} E:$errors W:$warnings N:$notices"; 
                    815:    system(
1.24      www       816:  "metasend -b -t $emailto -s '$subj' -f $statusdir/index.html -m text/html");
1.1       albertel  817: }
                    818: 1;
                    819: 
                    820: 
                    821: 
                    822: 
                    823: 
                    824: 
                    825: 
                    826: 

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