Annotation of loncom/loncron, revision 1.29

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
                     59: my $perlvarref=LONCAPA::Configuration::read_conf('loncapa_apache.conf',
                     60:                                                  'loncapa.conf');
1.28      albertel   61: %perlvar=%{$perlvarref};
1.26      harris41   62: undef $perlvarref;
                     63: delete $perlvar{'lonReceipt'}; # remove since sensitive and not needed
                     64: delete $perlvar{'lonSqlAccess'}; # remove since sensitive and not needed
1.13      harris41   65: 
1.14      harris41   66: # --------------------------------------- Make sure that LON-CAPA is configured
                     67: # I only test for one thing here (lonHostID).  This is just a safeguard.
                     68: if ('{[[[[lonHostID]]]]}' eq $perlvar{'lonHostID'}) {
1.15      harris41   69:    print("Unconfigured machine.\n");
1.14      harris41   70:    $emailto=$perlvar{'lonSysEMail'};
                     71:    $hostname=`/bin/hostname`;
                     72:    chop $hostname;
                     73:    $hostname=~s/[^\w\.]//g; # make sure is safe to pass through shell
                     74:    $subj="LON: Unconfigured machine $hostname";
                     75:    system("echo 'Unconfigured machine $hostname.' |\
                     76:  mailto $emailto -s '$subj' > /dev/null");
                     77:     exit 1;
                     78: }
                     79: 
1.13      harris41   80: # ----------------------------- Make sure this process is running from user=www
                     81: my $wwwid=getpwnam('www');
                     82: if ($wwwid!=$<) {
1.14      harris41   83:    print("User ID mismatch.  This program must be run as user 'www'\n");
1.13      harris41   84:    $emailto="$perlvar{'lonAdmEMail'},$perlvar{'lonSysEMail'}";
                     85:    $subj="LON: $perlvar{'lonHostID'} User ID mismatch";
                     86:    system("echo 'User ID mismatch.  loncron must be run as user www.' |\
                     87:  mailto $emailto -s '$subj' > /dev/null");
1.14      harris41   88:    exit 1;
1.1       albertel   89: }
                     90: 
                     91: # ------------------------------------------------------------- Read hosts file
                     92: {
                     93:     my $config=IO::File->new("$perlvar{'lonTabDir'}/hosts.tab");
                     94: 
                     95:     while (my $configline=<$config>) {
                     96:        my ($id,$domain,$role,$name,$ip)=split(/:/,$configline);
                     97:        $hostname{$id}=$name;
                     98:        $hostdom{$id}=$domain;
                     99:        $hostrole{$id}=$role;
                    100:        $hostip{$id}=$ip;
                    101:        if (($role eq 'library') && ($id ne $perlvar{'lonHostID'})) {
                    102: 	   $libserv{$id}=$name;
                    103:        }
                    104:     }
                    105: }
                    106: 
                    107: # ------------------------------------------------------ Read spare server file
                    108: {
                    109:     my $config=IO::File->new("$perlvar{'lonTabDir'}/spare.tab");
                    110: 
                    111:     while (my $configline=<$config>) {
                    112:        chomp($configline);
                    113:        if (($configline) && ($configline ne $perlvar{'lonHostID'})) {
                    114:           $spareid{$configline}=1;
                    115:        }
                    116:     }
                    117: }
                    118: 
                    119: # ---------------------------------------------------------------- Start report
                    120: 
                    121: $statusdir="/home/httpd/html/lon-status";
                    122: 
                    123: $errors=0;
                    124: $warnings=0;
                    125: $notices=0;
                    126: 
                    127: $now=time;
                    128: $date=localtime($now);
                    129: 
                    130: {
                    131: my $fh=IO::File->new(">$statusdir/newstatus.html");
                    132: 
                    133: print $fh (<<ENDHEADERS);
                    134: <html>
                    135: <head>
                    136: <title>LON Status Report $perlvar{'lonHostID'}</title>
                    137: </head>
1.3       www       138: <body bgcolor="#AAAAAA">
1.1       albertel  139: <a name="top">
                    140: <h1>LON Status Report $perlvar{'lonHostID'}</h1>
                    141: <h2>$date ($now)</h2>
                    142: <ol>
                    143: <li><a href="#configuration">Configuration</a>
                    144: <li><a href="#machine">Machine Information</a>
1.11      www       145: <li><a href="#tmp">Temporary Files</a>
                    146: <li><a href="#tokens">Session Tokens</a>
1.1       albertel  147: <li><a href="#httpd">httpd</a>
1.11      www       148: <li><a href="#lonsql">lonsql</a>
1.1       albertel  149: <li><a href="#lond">lond</a>
                    150: <li><a href="#lonc">lonc</a>
                    151: <li><a href="#lonnet">lonnet</a>
                    152: <li><a href="#connections">Connections</a>
                    153: <li><a href="#delayed">Delayed Messages</a>
                    154: <li><a href="#errcount">Error Count</a>
                    155: </ol>
                    156: <hr>
                    157: <a name="configuration">
                    158: <h2>Configuration</h2>
                    159: <h3>PerlVars</h3>
                    160: <table border=2>
                    161: ENDHEADERS
                    162: 
                    163: foreach $varname (keys %perlvar) {
                    164:     print $fh "<tr><td>$varname</td><td>$perlvar{$varname}</td></tr>\n";
                    165: }
                    166: print $fh "</table><h3>Hosts</h3><table border=2>";
                    167: foreach $id (keys %hostname) {
                    168: print $fh 
                    169:     "<tr><td>$id</td><td>$hostdom{$id}</td><td>$hostrole{$id}</td>";
                    170: print $fh "<td>$hostname{$id}</td><td>$hostip{$id}</td></tr>\n";
                    171: }
                    172: print $fh "</table><h3>Spare Hosts</h3><ol>";
                    173: foreach $id (keys %spareid) {
                    174:     print $fh "<li>$id\n";
                    175: }
                    176: 
                    177: print $fh "</ol>\n";
                    178: 
                    179: # --------------------------------------------------------------------- Machine
                    180: 
                    181: print $fh '<hr><a name="machine"><h2>Machine Information</h2>';
                    182: print $fh "<h3>loadavg</h3>";
                    183: 
                    184: open (LOADAVGH,"/proc/loadavg");
                    185: $loadavg=<LOADAVGH>;
                    186: close (LOADAVGH);
                    187: 
                    188: print $fh "<tt>$loadavg</tt>";
                    189: 
                    190: @parts=split(/\s+/,$loadavg);
1.4       www       191: if ($parts[1]>4.0) {
1.1       albertel  192:     $errors++;
                    193: } elsif ($parts[1]>2.0) {
                    194:     $warnings++;
                    195: } elsif ($parts[1]>1.0) {
                    196:     $notices++;
                    197: }
                    198: 
                    199: print $fh "<h3>df</h3>";
                    200: print $fh "<pre>";
                    201: 
                    202: open (DFH,"df|");
                    203: while ($line=<DFH>) { 
                    204:    print $fh "$line"; 
                    205:    @parts=split(/\s+/,$line);
                    206:    $usage=$parts[4];
                    207:    $usage=~s/\W//g;
                    208:    if ($usage>90) { 
1.24      www       209:       $warnings++;
                    210:       $notices++; 
1.1       albertel  211:    } elsif ($usage>80) {
                    212:       $warnings++;
                    213:    } elsif ($usage>60) {
                    214:       $notices++;
                    215:    }
1.4       www       216:    if ($usage>95) { $warnings++; $warnings++ }
1.1       albertel  217: }
                    218: close (DFH);
                    219: print $fh "</pre>";
1.24      www       220: 
                    221: 
                    222: print $fh "<h3>ps</h3>";
                    223: print $fh "<pre>";
                    224: $psproc=0;
                    225: 
                    226: open (PSH,"ps -aux|");
                    227: while ($line=<PSH>) { 
                    228:    print $fh "$line"; 
                    229:    $psproc++;
                    230: }
                    231: close (PSH);
                    232: print $fh "</pre>";
                    233: 
                    234: if ($psproc>200) { $notices++; }
                    235: if ($psproc>250) { $notices++; }
                    236: 
1.1       albertel  237: &errout($fh);
1.11      www       238: 
                    239: # --------------------------------------------------------------- clean out tmp
                    240: print $fh '<hr><a name="tmp"><h2>Temporary Files</h2>';
                    241: $cleaned=0;
1.29    ! www       242: $old=0;
1.11      www       243: while ($fname=<$perlvar{'lonDaemons'}/tmp/*>) {
                    244:                           my ($dev,$ino,$mode,$nlink,
                    245:                               $uid,$gid,$rdev,$size,
                    246:                               $atime,$mtime,$ctime,
                    247:                               $blksize,$blocks)=stat($fname);
                    248:                           $now=time;
                    249:                           $since=$now-$mtime;
                    250:                           if ($since>$perlvar{'lonExpire'}) {
1.29    ! www       251:                               $line='';
        !           252:                               if (open(PROBE,$fname)) {
        !           253: 				  $line=<PROBE>;
        !           254:                                   close(PROBE);
        !           255: 			      }
        !           256: 			      unless ($line=~/^CHECKOUTTOKEN\&/) {
        !           257:                                  $cleaned++;
        !           258:                                  unlink("$fname");
        !           259: 			      } else {
        !           260: 				  if ($since>100*$perlvar{'lonExpire'}) {
        !           261:                                      $cleaned++;
        !           262:                                      unlink("$fname");
        !           263: 				 } else { $old++; }
        !           264:                               }
1.11      www       265:                           }
                    266:     
                    267: }
1.29    ! www       268: print $fh "Cleaned up ".$cleaned." files (".$old." old checkout tokens).";
1.11      www       269: 
                    270: # ------------------------------------------------------------ clean out lonIDs
                    271: print $fh '<hr><a name="tokens"><h2>Session Tokens</h2>';
                    272: $cleaned=0;
                    273: $active=0;
                    274: while ($fname=<$perlvar{'lonIDsDir'}/*>) {
                    275:                           my ($dev,$ino,$mode,$nlink,
                    276:                               $uid,$gid,$rdev,$size,
                    277:                               $atime,$mtime,$ctime,
                    278:                               $blksize,$blocks)=stat($fname);
                    279:                           $now=time;
                    280:                           $since=$now-$mtime;
                    281:                           if ($since>$perlvar{'lonExpire'}) {
                    282:                               $cleaned++;
                    283:                               print $fh "Unlinking $fname<br>";
                    284:                               unlink("$fname");
                    285:                           } else {
                    286:                               $active++;
                    287:                           }
                    288:     
                    289: }
                    290: print $fh "<p>Cleaned up ".$cleaned." stale session token(s).";
                    291: print $fh "<h3>$active open session(s)</h3>";
                    292: 
1.1       albertel  293: # ----------------------------------------------------------------------- httpd
                    294: 
                    295: print $fh '<hr><a name="httpd"><h2>httpd</h2><h3>Access Log</h3><pre>';
                    296: 
1.23      www       297: open (DFH,"tail -n25 /etc/httpd/logs/access_log|");
1.1       albertel  298: while ($line=<DFH>) { print $fh "$line" };
                    299: close (DFH);
                    300: 
                    301: print $fh "</pre><h3>Error Log</h3><pre>";
                    302: 
1.23      www       303: open (DFH,"tail -n25 /etc/httpd/logs/error_log|");
1.1       albertel  304: while ($line=<DFH>) { 
                    305:    print $fh "$line";
                    306:    if ($line=~/\[error\]/) { $notices++; } 
                    307: };
                    308: close (DFH);
                    309: print $fh "</pre>";
                    310: &errout($fh);
1.5       harris41  311: 
                    312: 
1.11      www       313: # ---------------------------------------------------------------------- lonsql
1.22      harris41  314: 
                    315: my $restartflag=1;
1.18      harris41  316: if ($perlvar{'lonRole'} eq "library") {
1.5       harris41  317: 
1.11      www       318:     print $fh '<hr><a name="lonsql"><h2>lonsql</h2><h3>Log</h3><pre>';
1.23      www       319:     print "lonsql\n";
1.5       harris41  320:     if (-e "$perlvar{'lonDaemons'}/logs/lonsql.log"){
                    321: 	open (DFH,"tail -n100 $perlvar{'lonDaemons'}/logs/lonsql.log|");
                    322: 	while ($line=<DFH>) { 
                    323: 	    print $fh "$line";
                    324: 	    if ($line=~/INFO/) { $notices++; }
                    325: 	    if ($line=~/WARNING/) { $notices++; }
                    326: 	    if ($line=~/CRITICAL/) { $warnings++; }
                    327: 	};
                    328: 	close (DFH);
                    329:     }
                    330:     print $fh "</pre>";
                    331:     
                    332:     my $lonsqlfile="$perlvar{'lonDaemons'}/logs/lonsql.pid";
1.23      www       333:  
                    334:     $restartflag=1;
                    335:    
1.5       harris41  336:     if (-e $lonsqlfile) {
                    337: 	my $lfh=IO::File->new("$lonsqlfile");
                    338: 	my $lonsqlpid=<$lfh>;
                    339: 	chomp($lonsqlpid);
                    340: 	if (kill 0 => $lonsqlpid) {
                    341: 	    print $fh "<h3>lonsql at pid $lonsqlpid responding</h3>";
1.22      harris41  342: 	    $restartflag=0;
1.5       harris41  343: 	} else {
                    344: 	    $errors++; $errors++;
                    345: 	    print $fh "<h3>lonsql at pid $lonsqlpid not responding</h3>";
1.22      harris41  346: 		$restartflag=1;
1.23      www       347: 	print $fh 
                    348: 	    "<h3>Decided to clean up stale .pid file and restart lonsql</h3>";
1.5       harris41  349: 	}
1.22      harris41  350:     }
                    351:     if ($restartflag==1) {
1.5       harris41  352: 	$errors++;
1.23      www       353: 	         print $fh '<br><font color="red">Killall lonsql: '.
                    354:                     system('killall lonsql').' - ';
                    355:                     sleep 60;
                    356:                     print $fh unlink($lonsqlfile).' - '.
                    357:                               system('killall -9 lonsql').
                    358:                     '</font><br>';
1.5       harris41  359: 	print $fh "<h3>lonsql not running, trying to start</h3>";
1.16      harris41  360: 	system(
                    361:  "$perlvar{'lonDaemons'}/lonsql 2>>$perlvar{'lonDaemons'}/logs/lonsql_errors");
1.24      www       362: 	sleep 10;
1.5       harris41  363: 	if (-e $lonsqlfile) {
                    364: 	    print $fh "Seems like it started ...<p>";
                    365: 	    my $lfh=IO::File->new("$lonsqlfile");
                    366: 	    my $lonsqlpid=<$lfh>;
                    367: 	    chomp($lonsqlpid);
1.24      www       368: 	    sleep 30;
1.5       harris41  369: 	    if (kill 0 => $lonsqlpid) {
                    370: 		print $fh "<h3>lonsql at pid $lonsqlpid responding</h3>";
                    371: 	    } else {
                    372: 		$errors++; $errors++;
                    373: 		print $fh "<h3>lonsql at pid $lonsqlpid not responding</h3>";
                    374: 		print $fh "Give it one more try ...<p>";
1.16      harris41  375: 		system(
                    376:  "$perlvar{'lonDaemons'}/lonsql 2>>$perlvar{'lonDaemons'}/logs/lonsql_errors");
1.24      www       377: 		sleep 10;
1.5       harris41  378: 	    }
                    379: 	} else {
                    380: 	    print $fh "Seems like that did not work!<p>";
                    381: 	    $errors++;
                    382: 	}
                    383: 	if (-e "$perlvar{'lonDaemons'}/logs/lonsql.log"){
                    384: 	    print $fh "<p><pre>";
                    385: 	    open (DFH,"tail -n100 $perlvar{'lonDaemons'}/logs/lonsql.log|");
                    386: 	    while ($line=<DFH>) { 
                    387: 		print $fh "$line";
                    388: 		if ($line=~/WARNING/) { $notices++; }
                    389: 		if ($line=~/CRITICAL/) { $notices++; }
                    390: 	    };
                    391: 	    close (DFH);
                    392: 	    print $fh "</pre>";
                    393: 	}
                    394:     }
                    395: 
                    396:     $fname="$perlvar{'lonDaemons'}/logs/lonsql.log";
                    397: 
                    398:     my ($dev,$ino,$mode,$nlink,
                    399: 	$uid,$gid,$rdev,$size,
                    400: 	$atime,$mtime,$ctime,
                    401: 	$blksize,$blocks)=stat($fname);
                    402: 
                    403:     if ($size>40000) {
                    404: 	print $fh "Rotating logs ...<p>";
                    405: 	rename("$fname.2","$fname.3");
                    406: 	rename("$fname.1","$fname.2");
                    407: 	rename("$fname","$fname.1");
                    408:     }
                    409: 
                    410:     &errout($fh);
                    411: }
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').' - ';
                    452:           sleep 60;
                    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.24      www       458:    sleep 10;
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.24      www       464:        sleep 30;
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.24      www       473:           sleep 10;
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').' - ';
                    548:           sleep 60;
                    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.24      www       554:    sleep 10;
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.24      www       560:        sleep 30;
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.24      www       569:           sleep 10;
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";
                    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: # ---------------------------------------------------------------------- lonnet
                    605: 
                    606: print $fh '<hr><a name="lonnet"><h2>lonnet</h2><h3>Temp Log</h3><pre>';
1.23      www       607: print "lonnet\n";
1.1       albertel  608: if (-e "$perlvar{'lonDaemons'}/logs/lonnet.log"){
                    609: open (DFH,"tail -n50 $perlvar{'lonDaemons'}/logs/lonnet.log|");
                    610: while ($line=<DFH>) { 
                    611:     print $fh "$line";
                    612: };
                    613: close (DFH);
                    614: }
1.11      www       615: print $fh "</pre><h3>Perm Log</h3><pre>";
1.1       albertel  616: 
                    617: if (-e "$perlvar{'lonDaemons'}/logs/lonnet.perm.log") {
                    618:     open(DFH,"tail -n10 $perlvar{'lonDaemons'}/logs/lonnet.perm.log|");
                    619: while ($line=<DFH>) { 
                    620:    print $fh "$line";
                    621: };
                    622: close (DFH);
                    623: } else { print $fh "No perm log\n" }
                    624: 
                    625: $fname="$perlvar{'lonDaemons'}/logs/lonnet.log";
                    626: 
                    627:                           my ($dev,$ino,$mode,$nlink,
                    628:                               $uid,$gid,$rdev,$size,
                    629:                               $atime,$mtime,$ctime,
                    630:                               $blksize,$blocks)=stat($fname);
                    631: 
                    632: if ($size>40000) {
                    633:     print $fh "Rotating logs ...<p>";
                    634:     rename("$fname.2","$fname.3");
                    635:     rename("$fname.1","$fname.2");
                    636:     rename("$fname","$fname.1");
                    637: }
                    638: 
                    639: print $fh "</pre>";
                    640: &errout($fh);
                    641: # ----------------------------------------------------------------- Connections
                    642: 
                    643: print $fh '<hr><a name="connections"><h2>Connections</h2>';
                    644: 
                    645: print $fh "<table border=2>";
                    646: foreach $tryserver (keys %hostname) {
                    647: 
                    648:     $answer=reply("pong",$tryserver);
                    649:     if ($answer eq "$tryserver:$perlvar{'lonHostID'}") {
                    650: 	$result="<b>ok</b>";
                    651:     } else {
                    652:         $result=$answer;
                    653:         $warnings++;
                    654:         if ($answer eq 'con_lost') { $warnings++; }
                    655:     }
                    656:     print $fh "<tr><td>$tryserver</td><td>$result</td></tr>\n";
                    657: 
                    658: }
                    659: print $fh "</table>";
                    660: 
                    661: &errout($fh);
                    662: # ------------------------------------------------------------ Delayed messages
                    663: 
                    664: print $fh '<hr><a name="delayed"><h2>Delayed Messages</h2>';
1.23      www       665: print "buffers\n";
1.1       albertel  666: 
                    667: print $fh '<h3>Scanning Permanent Log</h3>';
                    668: 
                    669: $unsend=0;
                    670: {
                    671:     my $dfh=IO::File->new("$perlvar{'lonDaemons'}/logs/lonnet.perm.log");
                    672:     while ($line=<$dfh>) {
                    673: 	($time,$sdf,$dserv,$dcmd)=split(/:/,$line);
                    674:         if ($sdf eq 'F') { 
                    675: 	    $local=localtime($time);
                    676:             print "<b>Failed: $time, $dserv, $dcmd</b><br>";
                    677:             $warnings++;
                    678:         }
                    679:         if ($sdf eq 'S') { $unsend--; }
                    680:         if ($sdf eq 'D') { $unsend++; }
                    681:     }
                    682: }
                    683: print $fh "Total unsend messages: <b>$unsend</b><p>\n";
                    684: $warnings=$warnings+5*$unsend;
                    685: 
                    686: print $fh "<h3>Outgoing Buffer</h3>";
                    687: 
                    688: open (DFH,"ls -lF $perlvar{'lonSockDir'}/delayed|");
                    689: while ($line=<DFH>) { 
                    690:     print $fh "$line<br>";
                    691: };
                    692: close (DFH);
                    693: 
                    694: # ------------------------------------------------------------------------- End
                    695: print $fh "<a name=errcount>\n";
                    696: $totalcount=$notices+4*$warnings+100*$errors;
                    697: &errout($fh);
                    698: print $fh "<h1>Total Error Count: $totalcount</h1>";
                    699: $now=time;
                    700: $date=localtime($now);
                    701: print $fh "<hr>$date ($now)</body></html>\n";
1.23      www       702: print "writing done\n";
1.1       albertel  703: }
                    704: 
                    705: rename ("$statusdir/newstatus.html","$statusdir/index.html");
                    706: 
                    707: if ($totalcount>200) {
1.23      www       708:    print "mailing\n";
1.1       albertel  709:    $emailto="$perlvar{'lonAdmEMail'},$perlvar{'lonSysEMail'}";
                    710:    $subj="LON: $perlvar{'lonHostID'} E:$errors W:$warnings N:$notices"; 
                    711:    system(
1.24      www       712:  "metasend -b -t $emailto -s '$subj' -f $statusdir/index.html -m text/html");
1.1       albertel  713: }
                    714: 1;
                    715: 
                    716: 
                    717: 
                    718: 
                    719: 
                    720: 
                    721: 
                    722: 

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