Annotation of loncom/loncron, revision 1.16

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

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