Annotation of loncom/loncron, revision 1.21

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.20      harris41   14: # 1/10/2001, 2/12/, 2/26, 3/15, 04/11, 04/21 Scott Harrison
1.1       albertel   15: 
                     16: use IO::File;
                     17: use IO::Socket;
                     18: 
1.20      harris41   19: my $qflag=0;
                     20: if (@ARGV) {
                     21:     my $arg=shift @ARGV;
                     22:     $qflag=1 if $arg eq 'quick';
                     23: }
                     24: 
1.1       albertel   25: # -------------------------------------------------- Non-critical communication
                     26: sub reply {
                     27:     my ($cmd,$server)=@_;
                     28:     my $peerfile="$perlvar{'lonSockDir'}/$server";
                     29:     my $client=IO::Socket::UNIX->new(Peer    =>"$peerfile",
                     30:                                      Type    => SOCK_STREAM,
                     31:                                      Timeout => 10)
                     32:        or return "con_lost";
                     33:     print $client "$cmd\n";
                     34:     my $answer=<$client>;
                     35:     chomp($answer);
                     36:     if (!$answer) { $answer="con_lost"; }
                     37:     return $answer;
                     38: }
                     39: 
                     40: # --------------------------------------------------------- Output error status
                     41: 
                     42: sub errout {
                     43:    my $fh=shift;
                     44:    print $fh (<<ENDERROUT);
                     45:      <p><table border=2 bgcolor="#CCCCCC">
                     46:      <tr><td>Notices</td><td>$notices</td></tr>
                     47:      <tr><td>Warnings</td><td>$warnings</td></tr>
                     48:      <tr><td>Errors</td><td>$errors</td></tr>
                     49:      </table><p><a href="#top">Top</a><p>
                     50: ENDERROUT
                     51: }
                     52: 
                     53: # ================================================================ Main Program
                     54: 
                     55: # ------------------------------------------------------------ Read access.conf
                     56: {
                     57:     my $config=IO::File->new("/etc/httpd/conf/access.conf");
                     58: 
                     59:     while (my $configline=<$config>) {
                     60:         if ($configline =~ /PerlSetVar/) {
                     61: 	   my ($dummy,$varname,$varvalue)=split(/\s+/,$configline);
                     62:            $perlvar{$varname}=$varvalue;
                     63:         }
                     64:     }
1.19      harris41   65:     delete $perlvar{'lonReceipt'}; # remove since sensitive and not needed
                     66:     delete $perlvar{'lonSqlAccess'}; # remove since sensitive and not needed
1.13      harris41   67: }
                     68: 
1.14      harris41   69: # --------------------------------------- Make sure that LON-CAPA is configured
                     70: # I only test for one thing here (lonHostID).  This is just a safeguard.
                     71: if ('{[[[[lonHostID]]]]}' eq $perlvar{'lonHostID'}) {
1.15      harris41   72:    print("Unconfigured machine.\n");
1.14      harris41   73:    $emailto=$perlvar{'lonSysEMail'};
                     74:    $hostname=`/bin/hostname`;
                     75:    chop $hostname;
                     76:    $hostname=~s/[^\w\.]//g; # make sure is safe to pass through shell
                     77:    $subj="LON: Unconfigured machine $hostname";
                     78:    system("echo 'Unconfigured machine $hostname.' |\
                     79:  mailto $emailto -s '$subj' > /dev/null");
                     80:     exit 1;
                     81: }
                     82: 
1.13      harris41   83: # ----------------------------- Make sure this process is running from user=www
                     84: my $wwwid=getpwnam('www');
                     85: if ($wwwid!=$<) {
1.14      harris41   86:    print("User ID mismatch.  This program must be run as user 'www'\n");
1.13      harris41   87:    $emailto="$perlvar{'lonAdmEMail'},$perlvar{'lonSysEMail'}";
                     88:    $subj="LON: $perlvar{'lonHostID'} User ID mismatch";
                     89:    system("echo 'User ID mismatch.  loncron must be run as user www.' |\
                     90:  mailto $emailto -s '$subj' > /dev/null");
1.14      harris41   91:    exit 1;
1.1       albertel   92: }
                     93: 
                     94: # ------------------------------------------------------------- Read hosts file
                     95: {
                     96:     my $config=IO::File->new("$perlvar{'lonTabDir'}/hosts.tab");
                     97: 
                     98:     while (my $configline=<$config>) {
                     99:        my ($id,$domain,$role,$name,$ip)=split(/:/,$configline);
                    100:        $hostname{$id}=$name;
                    101:        $hostdom{$id}=$domain;
                    102:        $hostrole{$id}=$role;
                    103:        $hostip{$id}=$ip;
                    104:        if (($role eq 'library') && ($id ne $perlvar{'lonHostID'})) {
                    105: 	   $libserv{$id}=$name;
                    106:        }
                    107:     }
                    108: }
                    109: 
                    110: # ------------------------------------------------------ Read spare server file
                    111: {
                    112:     my $config=IO::File->new("$perlvar{'lonTabDir'}/spare.tab");
                    113: 
                    114:     while (my $configline=<$config>) {
                    115:        chomp($configline);
                    116:        if (($configline) && ($configline ne $perlvar{'lonHostID'})) {
                    117:           $spareid{$configline}=1;
                    118:        }
                    119:     }
                    120: }
                    121: 
                    122: # ---------------------------------------------------------------- Start report
                    123: 
                    124: $statusdir="/home/httpd/html/lon-status";
                    125: 
                    126: $errors=0;
                    127: $warnings=0;
                    128: $notices=0;
                    129: 
                    130: $now=time;
                    131: $date=localtime($now);
                    132: 
                    133: {
                    134: my $fh=IO::File->new(">$statusdir/newstatus.html");
                    135: 
                    136: print $fh (<<ENDHEADERS);
                    137: <html>
                    138: <head>
                    139: <title>LON Status Report $perlvar{'lonHostID'}</title>
                    140: </head>
1.3       www       141: <body bgcolor="#AAAAAA">
1.1       albertel  142: <a name="top">
                    143: <h1>LON Status Report $perlvar{'lonHostID'}</h1>
                    144: <h2>$date ($now)</h2>
                    145: <ol>
                    146: <li><a href="#configuration">Configuration</a>
                    147: <li><a href="#machine">Machine Information</a>
1.11      www       148: <li><a href="#tmp">Temporary Files</a>
                    149: <li><a href="#tokens">Session Tokens</a>
1.1       albertel  150: <li><a href="#httpd">httpd</a>
1.11      www       151: <li><a href="#lonsql">lonsql</a>
1.1       albertel  152: <li><a href="#lond">lond</a>
                    153: <li><a href="#lonc">lonc</a>
                    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: 
                    166: foreach $varname (keys %perlvar) {
                    167:     print $fh "<tr><td>$varname</td><td>$perlvar{$varname}</td></tr>\n";
                    168: }
                    169: print $fh "</table><h3>Hosts</h3><table border=2>";
                    170: foreach $id (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";
                    174: }
                    175: print $fh "</table><h3>Spare Hosts</h3><ol>";
                    176: foreach $id (keys %spareid) {
                    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.4       www       212:       $warnings++; 
1.1       albertel  213:    } elsif ($usage>80) {
                    214:       $warnings++;
                    215:    } elsif ($usage>60) {
                    216:       $notices++;
                    217:    }
1.4       www       218:    if ($usage>95) { $warnings++; $warnings++ }
1.1       albertel  219: }
                    220: close (DFH);
                    221: print $fh "</pre>";
                    222: &errout($fh);
1.11      www       223: 
                    224: # --------------------------------------------------------------- clean out tmp
                    225: print $fh '<hr><a name="tmp"><h2>Temporary Files</h2>';
                    226: $cleaned=0;
                    227: while ($fname=<$perlvar{'lonDaemons'}/tmp/*>) {
                    228:                           my ($dev,$ino,$mode,$nlink,
                    229:                               $uid,$gid,$rdev,$size,
                    230:                               $atime,$mtime,$ctime,
                    231:                               $blksize,$blocks)=stat($fname);
                    232:                           $now=time;
                    233:                           $since=$now-$mtime;
                    234:                           if ($since>$perlvar{'lonExpire'}) {
                    235:                               $cleaned++;
                    236:                               unlink("$fname");
                    237:                           }
                    238:     
                    239: }
                    240: print $fh "Cleaned up ".$cleaned." files.";
                    241: 
                    242: # ------------------------------------------------------------ clean out lonIDs
                    243: print $fh '<hr><a name="tokens"><h2>Session Tokens</h2>';
                    244: $cleaned=0;
                    245: $active=0;
                    246: while ($fname=<$perlvar{'lonIDsDir'}/*>) {
                    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'}) {
                    254:                               $cleaned++;
                    255:                               print $fh "Unlinking $fname<br>";
                    256:                               unlink("$fname");
                    257:                           } else {
                    258:                               $active++;
                    259:                           }
                    260:     
                    261: }
                    262: print $fh "<p>Cleaned up ".$cleaned." stale session token(s).";
                    263: print $fh "<h3>$active open session(s)</h3>";
                    264: 
1.1       albertel  265: # ----------------------------------------------------------------------- httpd
                    266: 
                    267: print $fh '<hr><a name="httpd"><h2>httpd</h2><h3>Access Log</h3><pre>';
                    268: 
                    269: open (DFH,"tail -n40 /etc/httpd/logs/access_log|");
                    270: while ($line=<DFH>) { print $fh "$line" };
                    271: close (DFH);
                    272: 
                    273: print $fh "</pre><h3>Error Log</h3><pre>";
                    274: 
                    275: open (DFH,"tail -n50 /etc/httpd/logs/error_log|");
                    276: while ($line=<DFH>) { 
                    277:    print $fh "$line";
                    278:    if ($line=~/\[error\]/) { $notices++; } 
                    279: };
                    280: close (DFH);
                    281: print $fh "</pre>";
                    282: &errout($fh);
1.5       harris41  283: 
                    284: 
1.11      www       285: # ---------------------------------------------------------------------- lonsql
                    286: #
                    287: # Do not run for now
                    288: #
1.18      harris41  289: if ($perlvar{'lonRole'} eq "library") {
1.5       harris41  290: 
1.11      www       291:     print $fh '<hr><a name="lonsql"><h2>lonsql</h2><h3>Log</h3><pre>';
1.5       harris41  292:     
                    293:     if (-e "$perlvar{'lonDaemons'}/logs/lonsql.log"){
                    294: 	open (DFH,"tail -n100 $perlvar{'lonDaemons'}/logs/lonsql.log|");
                    295: 	while ($line=<DFH>) { 
                    296: 	    print $fh "$line";
                    297: 	    if ($line=~/INFO/) { $notices++; }
                    298: 	    if ($line=~/WARNING/) { $notices++; }
                    299: 	    if ($line=~/CRITICAL/) { $warnings++; }
                    300: 	};
                    301: 	close (DFH);
                    302:     }
                    303:     print $fh "</pre>";
                    304:     
                    305:     my $lonsqlfile="$perlvar{'lonDaemons'}/logs/lonsql.pid";
                    306:     
                    307:     if (-e $lonsqlfile) {
                    308: 	my $lfh=IO::File->new("$lonsqlfile");
                    309: 	my $lonsqlpid=<$lfh>;
                    310: 	chomp($lonsqlpid);
                    311: 	if (kill 0 => $lonsqlpid) {
                    312: 	    print $fh "<h3>lonsql at pid $lonsqlpid responding</h3>";
                    313: 	} else {
                    314: 	    $errors++; $errors++;
                    315: 	    print $fh "<h3>lonsql at pid $lonsqlpid not responding</h3>";
                    316: 	}
                    317:     } else {
                    318: 	$errors++;
                    319: 	print $fh "<h3>lonsql not running, trying to start</h3>";
1.16      harris41  320: 	system(
                    321:  "$perlvar{'lonDaemons'}/lonsql 2>>$perlvar{'lonDaemons'}/logs/lonsql_errors");
1.20      harris41  322: 	sleep 120 unless $qflag;
1.5       harris41  323: 	if (-e $lonsqlfile) {
                    324: 	    print $fh "Seems like it started ...<p>";
                    325: 	    my $lfh=IO::File->new("$lonsqlfile");
                    326: 	    my $lonsqlpid=<$lfh>;
                    327: 	    chomp($lonsqlpid);
1.20      harris41  328: 	    sleep 30 unless $qflag;
1.5       harris41  329: 	    if (kill 0 => $lonsqlpid) {
                    330: 		print $fh "<h3>lonsql at pid $lonsqlpid responding</h3>";
                    331: 	    } else {
                    332: 		$errors++; $errors++;
                    333: 		print $fh "<h3>lonsql at pid $lonsqlpid not responding</h3>";
                    334: 		print $fh "Give it one more try ...<p>";
1.16      harris41  335: 		system(
                    336:  "$perlvar{'lonDaemons'}/lonsql 2>>$perlvar{'lonDaemons'}/logs/lonsql_errors");
1.20      harris41  337: 		sleep 120 unless $qflag;
1.5       harris41  338: 	    }
                    339: 	} else {
                    340: 	    print $fh "Seems like that did not work!<p>";
                    341: 	    $errors++;
                    342: 	}
                    343: 	if (-e "$perlvar{'lonDaemons'}/logs/lonsql.log"){
                    344: 	    print $fh "<p><pre>";
                    345: 	    open (DFH,"tail -n100 $perlvar{'lonDaemons'}/logs/lonsql.log|");
                    346: 	    while ($line=<DFH>) { 
                    347: 		print $fh "$line";
                    348: 		if ($line=~/WARNING/) { $notices++; }
                    349: 		if ($line=~/CRITICAL/) { $notices++; }
                    350: 	    };
                    351: 	    close (DFH);
                    352: 	    print $fh "</pre>";
                    353: 	}
                    354:     }
                    355: 
                    356:     $fname="$perlvar{'lonDaemons'}/logs/lonsql.log";
                    357: 
                    358:     my ($dev,$ino,$mode,$nlink,
                    359: 	$uid,$gid,$rdev,$size,
                    360: 	$atime,$mtime,$ctime,
                    361: 	$blksize,$blocks)=stat($fname);
                    362: 
                    363:     if ($size>40000) {
                    364: 	print $fh "Rotating logs ...<p>";
                    365: 	rename("$fname.2","$fname.3");
                    366: 	rename("$fname.1","$fname.2");
                    367: 	rename("$fname","$fname.1");
                    368:     }
                    369: 
                    370:     &errout($fh);
                    371: }
1.1       albertel  372: # ------------------------------------------------------------------------ lond
                    373: 
                    374: print $fh '<hr><a name="lond"><h2>lond</h2><h3>Log</h3><pre>';
                    375: 
                    376: if (-e "$perlvar{'lonDaemons'}/logs/lond.log"){
1.3       www       377: open (DFH,"tail -n100 $perlvar{'lonDaemons'}/logs/lond.log|");
1.1       albertel  378: while ($line=<DFH>) { 
                    379:    print $fh "$line";
1.3       www       380:    if ($line=~/INFO/) { $notices++; }
1.4       www       381:    if ($line=~/WARNING/) { $notices++; }
                    382:    if ($line=~/CRITICAL/) { $warnings++; }
1.1       albertel  383: };
                    384: close (DFH);
                    385: }
                    386: print $fh "</pre>";
                    387: 
                    388: my $londfile="$perlvar{'lonDaemons'}/logs/lond.pid";
                    389: 
1.7       harris41  390: my $restartflag=1;
                    391: if (-e $londfile) {    
1.1       albertel  392:    my $lfh=IO::File->new("$londfile");
                    393:    my $londpid=<$lfh>;
                    394:    chomp($londpid);
                    395:    if (kill 0 => $londpid) {
                    396:       print $fh "<h3>lond at pid $londpid responding</h3>";
1.7       harris41  397:       $restartflag=0;
1.1       albertel  398:    } else {
1.8       harris41  399:       $errors++;
1.1       albertel  400:       print $fh "<h3>lond at pid $londpid not responding</h3>";
1.7       harris41  401:       # Intelligently handle this.
                    402:       # Possibility #1: there is no process
                    403:       # Solution: remove .pid file and restart
                    404:       if (getpgrp($londpid)==-1) {
                    405: 	  unlink($londfile);
                    406: 	  $restartflag=1;
                    407:       }
1.8       harris41  408:       else {
1.10      harris41  409:       # Possibility #2: there is a live process that is not responding
1.7       harris41  410:       #                 for an unknown reason
1.10      harris41  411:       # Solution: kill parent and children processes, remove .pid and restart
1.9       harris41  412: 	  `killall -9 lond`;
1.8       harris41  413: 	  unlink($londfile);
                    414: 	  $restartflag=1;
                    415:       }
                    416:       print $fh 
                    417: 	  "<h3>Deciding to clean up stale .pid file and restart lond</h3>";
1.1       albertel  418:    }
1.7       harris41  419: } 
                    420: if ($restartflag==1) {
1.1       albertel  421:    $errors++;
                    422:    print $fh "<h3>lond not running, trying to start</h3>";
1.16      harris41  423:    system(
                    424:      "$perlvar{'lonDaemons'}/lond 2>>$perlvar{'lonDaemons'}/logs/lond_errors");
1.20      harris41  425:    sleep 120 unless $qflag;
1.1       albertel  426:    if (-e $londfile) {
                    427:        print $fh "Seems like it started ...<p>";
                    428:        my $lfh=IO::File->new("$londfile");
                    429:        my $londpid=<$lfh>;
                    430:        chomp($londpid);
1.20      harris41  431:        sleep 30 unless $qflag;
1.1       albertel  432:        if (kill 0 => $londpid) {
                    433:           print $fh "<h3>lond at pid $londpid responding</h3>";
                    434:        } else {
                    435:           $errors++; $errors++;
                    436:           print $fh "<h3>lond at pid $londpid not responding</h3>";
                    437:           print $fh "Give it one more try ...<p>";
1.16      harris41  438: 	  system(
                    439:  "$perlvar{'lonDaemons'}/lond 2>>$perlvar{'lonDaemons'}/logs/lond_errors");
1.20      harris41  440:           sleep 120 unless $qflag;
1.1       albertel  441:        }
                    442:    } else {
                    443:        print $fh "Seems like that did not work!<p>";
                    444:        $errors++;
                    445:    }
1.3       www       446:    if (-e "$perlvar{'lonDaemons'}/logs/lond.log"){
                    447:     print $fh "<p><pre>";
                    448:     open (DFH,"tail -n100 $perlvar{'lonDaemons'}/logs/lond.log|");
                    449:     while ($line=<DFH>) { 
                    450:       print $fh "$line";
1.4       www       451:       if ($line=~/WARNING/) { $notices++; }
                    452:       if ($line=~/CRITICAL/) { $notices++; }
1.3       www       453:     };
                    454:     close (DFH);
                    455:     print $fh "</pre>";
                    456:    }
1.1       albertel  457: }
                    458: 
                    459: $fname="$perlvar{'lonDaemons'}/logs/lond.log";
                    460: 
                    461:                           my ($dev,$ino,$mode,$nlink,
                    462:                               $uid,$gid,$rdev,$size,
                    463:                               $atime,$mtime,$ctime,
                    464:                               $blksize,$blocks)=stat($fname);
                    465: 
                    466: if ($size>40000) {
                    467:     print $fh "Rotating logs ...<p>";
                    468:     rename("$fname.2","$fname.3");
                    469:     rename("$fname.1","$fname.2");
                    470:     rename("$fname","$fname.1");
                    471: }
                    472: 
                    473: &errout($fh);
                    474: # ------------------------------------------------------------------------ lonc
                    475: 
                    476: print $fh '<hr><a name="lonc"><h2>lonc</h2><h3>Log</h3><pre>';
                    477: 
                    478: if (-e "$perlvar{'lonDaemons'}/logs/lonc.log"){
1.3       www       479: open (DFH,"tail -n100 $perlvar{'lonDaemons'}/logs/lonc.log|");
1.1       albertel  480: while ($line=<DFH>) { 
                    481:    print $fh "$line";
1.3       www       482:    if ($line=~/INFO/) { $notices++; }
1.4       www       483:    if ($line=~/WARNING/) { $notices++; }
                    484:    if ($line=~/CRITICAL/) { $warnings++; }
1.1       albertel  485: };
                    486: close (DFH);
                    487: }
                    488: print $fh "</pre>";
                    489: 
                    490: my $loncfile="$perlvar{'lonDaemons'}/logs/lonc.pid";
                    491: 
1.7       harris41  492: $restartflag=1;
1.1       albertel  493: if (-e $loncfile) {
                    494:    my $lfh=IO::File->new("$loncfile");
                    495:    my $loncpid=<$lfh>;
                    496:    chomp($loncpid);
                    497:    if (kill 0 => $loncpid) {
                    498:       print $fh "<h3>lonc at pid $loncpid responding, sending USR1</h3>";
                    499:       kill USR1 => $loncpid;
1.7       harris41  500:       $restartflag=0;
1.1       albertel  501:    } else {
1.8       harris41  502:       $errors++;
1.1       albertel  503:       print $fh "<h3>lonc at pid $loncpid not responding</h3>";
1.7       harris41  504:       # Intelligently handle this.
                    505:       # Possibility #1: there is no process
                    506:       # Solution: remove .pid file and restart
                    507:       if (getpgrp($loncpid)==-1) {
                    508: 	  unlink($loncfile);
                    509: 	  $restartflag=1;
                    510:       }
1.8       harris41  511:       else {
1.10      harris41  512:       # Possibility #2: there is a live process that is not responding
1.7       harris41  513:       #                 for an unknown reason
1.10      harris41  514:       # Solution: kill parent and children processes, remove .pid and restart
1.9       harris41  515: 	  `killall -9 lonc`;
1.8       harris41  516: 	  unlink($loncfile);
                    517: 	  $restartflag=1;
                    518:       }
                    519:       print $fh 
                    520: 	  "<h3>Deciding to clean up stale .pid file and restart lonc</h3>";
1.1       albertel  521:    }
1.7       harris41  522: } 
                    523: if ($restartflag==1) {
1.1       albertel  524:    $errors++;
                    525:    print $fh "<h3>lonc not running, trying to start</h3>";
1.16      harris41  526: 	system(
1.17      harris41  527:  "$perlvar{'lonDaemons'}/lonc 2>>$perlvar{'lonDaemons'}/logs/lonc_errors");
1.20      harris41  528:    sleep 120 unless $qflag;
1.1       albertel  529:    if (-e $loncfile) {
                    530:        print $fh "Seems like it started ...<p>";
                    531:        my $lfh=IO::File->new("$loncfile");
                    532:        my $loncpid=<$lfh>;
                    533:        chomp($loncpid);
1.20      harris41  534:        sleep 30 unless $qflag;
1.1       albertel  535:        if (kill 0 => $loncpid) {
                    536:           print $fh "<h3>lonc at pid $loncpid responding</h3>";
                    537:        } else {
                    538:           $errors++; $errors++;
                    539:           print $fh "<h3>lonc at pid $loncpid not responding</h3>";
                    540:           print $fh "Give it one more try ...<p>";
1.16      harris41  541:  	  system(
1.17      harris41  542:  "$perlvar{'lonDaemons'}/lonc 2>>$perlvar{'lonDaemons'}/logs/lonc_errors");
1.20      harris41  543:           sleep 120 unless $qflag;
1.1       albertel  544:        }
                    545:    } else {
                    546:        print $fh "Seems like that did not work!<p>";
                    547:        $errors++;
                    548:    }
1.3       www       549:    if (-e "$perlvar{'lonDaemons'}/logs/lonc.log") {
                    550:     print $fh "<p><pre>";
                    551:     open (DFH,"tail -n100 $perlvar{'lonDaemons'}/logs/lonc.log|");
                    552:     while ($line=<DFH>) { 
                    553:       print $fh "$line";
1.4       www       554:       if ($line=~/WARNING/) { $notices++; }
                    555:       if ($line=~/CRITICAL/) { $notices++; }
1.3       www       556:     };
                    557:     close (DFH);
                    558:     print $fh "</pre>";
                    559:    }
1.1       albertel  560: }
                    561: 
                    562: $fname="$perlvar{'lonDaemons'}/logs/lonc.log";
                    563: 
                    564:                           my ($dev,$ino,$mode,$nlink,
                    565:                               $uid,$gid,$rdev,$size,
                    566:                               $atime,$mtime,$ctime,
                    567:                               $blksize,$blocks)=stat($fname);
                    568: 
                    569: if ($size>40000) {
                    570:     print $fh "Rotating logs ...<p>";
                    571:     rename("$fname.2","$fname.3");
                    572:     rename("$fname.1","$fname.2");
                    573:     rename("$fname","$fname.1");
                    574: }
                    575: 
                    576:    
                    577: &errout($fh);
                    578: # ---------------------------------------------------------------------- lonnet
                    579: 
                    580: print $fh '<hr><a name="lonnet"><h2>lonnet</h2><h3>Temp Log</h3><pre>';
                    581: if (-e "$perlvar{'lonDaemons'}/logs/lonnet.log"){
                    582: open (DFH,"tail -n50 $perlvar{'lonDaemons'}/logs/lonnet.log|");
                    583: while ($line=<DFH>) { 
                    584:     print $fh "$line";
                    585: };
                    586: close (DFH);
                    587: }
1.11      www       588: print $fh "</pre><h3>Perm Log</h3><pre>";
1.1       albertel  589: 
                    590: if (-e "$perlvar{'lonDaemons'}/logs/lonnet.perm.log") {
                    591:     open(DFH,"tail -n10 $perlvar{'lonDaemons'}/logs/lonnet.perm.log|");
                    592: while ($line=<DFH>) { 
                    593:    print $fh "$line";
                    594: };
                    595: close (DFH);
                    596: } else { print $fh "No perm log\n" }
                    597: 
                    598: $fname="$perlvar{'lonDaemons'}/logs/lonnet.log";
                    599: 
                    600:                           my ($dev,$ino,$mode,$nlink,
                    601:                               $uid,$gid,$rdev,$size,
                    602:                               $atime,$mtime,$ctime,
                    603:                               $blksize,$blocks)=stat($fname);
                    604: 
                    605: if ($size>40000) {
                    606:     print $fh "Rotating logs ...<p>";
                    607:     rename("$fname.2","$fname.3");
                    608:     rename("$fname.1","$fname.2");
                    609:     rename("$fname","$fname.1");
                    610: }
                    611: 
                    612: print $fh "</pre>";
                    613: &errout($fh);
                    614: # ----------------------------------------------------------------- Connections
                    615: 
                    616: print $fh '<hr><a name="connections"><h2>Connections</h2>';
                    617: 
                    618: print $fh "<table border=2>";
                    619: foreach $tryserver (keys %hostname) {
                    620: 
                    621:     $answer=reply("pong",$tryserver);
                    622:     if ($answer eq "$tryserver:$perlvar{'lonHostID'}") {
                    623: 	$result="<b>ok</b>";
                    624:     } else {
                    625:         $result=$answer;
                    626:         $warnings++;
                    627:         if ($answer eq 'con_lost') { $warnings++; }
                    628:     }
                    629:     print $fh "<tr><td>$tryserver</td><td>$result</td></tr>\n";
                    630: 
                    631: }
                    632: print $fh "</table>";
                    633: 
                    634: &errout($fh);
                    635: # ------------------------------------------------------------ Delayed messages
                    636: 
                    637: print $fh '<hr><a name="delayed"><h2>Delayed Messages</h2>';
                    638: 
                    639: print $fh '<h3>Scanning Permanent Log</h3>';
                    640: 
                    641: $unsend=0;
                    642: {
                    643:     my $dfh=IO::File->new("$perlvar{'lonDaemons'}/logs/lonnet.perm.log");
                    644:     while ($line=<$dfh>) {
                    645: 	($time,$sdf,$dserv,$dcmd)=split(/:/,$line);
                    646:         if ($sdf eq 'F') { 
                    647: 	    $local=localtime($time);
                    648:             print "<b>Failed: $time, $dserv, $dcmd</b><br>";
                    649:             $warnings++;
                    650:         }
                    651:         if ($sdf eq 'S') { $unsend--; }
                    652:         if ($sdf eq 'D') { $unsend++; }
                    653:     }
                    654: }
                    655: print $fh "Total unsend messages: <b>$unsend</b><p>\n";
                    656: $warnings=$warnings+5*$unsend;
                    657: 
                    658: print $fh "<h3>Outgoing Buffer</h3>";
                    659: 
                    660: open (DFH,"ls -lF $perlvar{'lonSockDir'}/delayed|");
                    661: while ($line=<DFH>) { 
                    662:     print $fh "$line<br>";
                    663: };
                    664: close (DFH);
                    665: 
                    666: # ------------------------------------------------------------------------- End
                    667: print $fh "<a name=errcount>\n";
                    668: $totalcount=$notices+4*$warnings+100*$errors;
                    669: &errout($fh);
                    670: print $fh "<h1>Total Error Count: $totalcount</h1>";
                    671: $now=time;
                    672: $date=localtime($now);
                    673: print $fh "<hr>$date ($now)</body></html>\n";
                    674: 
                    675: }
                    676: 
                    677: rename ("$statusdir/newstatus.html","$statusdir/index.html");
                    678: 
                    679: if ($totalcount>200) {
                    680:    $emailto="$perlvar{'lonAdmEMail'},$perlvar{'lonSysEMail'}";
                    681:    $subj="LON: $perlvar{'lonHostID'} E:$errors W:$warnings N:$notices"; 
                    682:    system(
1.21    ! harris41  683:  "metasend -b -t $emailto -s '$subj' -f $statusdir/index.html -m text/html")
        !           684:     unless $qflag;
1.1       albertel  685: }
                    686: 1;
                    687: 
                    688: 
                    689: 
                    690: 
                    691: 
                    692: 
                    693: 
                    694: 

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