File:  [LON-CAPA] / loncom / loncron
Revision 1.103.2.4: download - view: text, annotated - select for diffs
Sun Jul 7 16:15:24 2019 UTC (4 years, 9 months ago) by raeburn
Branches: version_2_11_X
Diff to branchpoint 1.103: preferred, unified
- For 2.11
  - Backport 1.118

    1: #!/usr/bin/perl
    2: 
    3: # Housekeeping program, started by cron, loncontrol and loncron.pl
    4: #
    5: # $Id: loncron,v 1.103.2.4 2019/07/07 16:15:24 raeburn Exp $
    6: #
    7: # Copyright Michigan State University Board of Trustees
    8: #
    9: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
   10: #
   11: # LON-CAPA is free software; you can redistribute it and/or modify
   12: # it under the terms of the GNU General Public License as published by
   13: # the Free Software Foundation; either version 2 of the License, or
   14: # (at your option) any later version.
   15: #
   16: # LON-CAPA is distributed in the hope that it will be useful,
   17: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   18: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   19: # GNU General Public License for more details.
   20: #
   21: # You should have received a copy of the GNU General Public License
   22: # along with LON-CAPA; if not, write to the Free Software
   23: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   24: #
   25: # /home/httpd/html/adm/gpl.txt
   26: #
   27: # http://www.lon-capa.org/
   28: #
   29: 
   30: $|=1;
   31: use strict;
   32: 
   33: use lib '/home/httpd/lib/perl/';
   34: use LONCAPA::Configuration;
   35: use LONCAPA::Checksumming;
   36: use LONCAPA;
   37: use Apache::lonnet;
   38: use Apache::loncommon;
   39: 
   40: use IO::File;
   41: use IO::Socket;
   42: use HTML::Entities;
   43: use Getopt::Long;
   44: use File::Copy;
   45: #globals
   46: use vars qw (%perlvar %simplestatus $errors $warnings $notices $totalcount);
   47: 
   48: my $statusdir="/home/httpd/html/lon-status";
   49: 
   50: 
   51: # --------------------------------------------------------- Output error status
   52: 
   53: sub log {
   54:     my $fh=shift;
   55:     if ($fh) {	print $fh @_  }
   56: }
   57: 
   58: sub errout {
   59:    my $fh=shift;
   60:    &log($fh,(<<ENDERROUT));
   61:      <table border="2" bgcolor="#CCCCCC">
   62:      <tr><td>Notices</td><td>$notices</td></tr>
   63:      <tr><td>Warnings</td><td>$warnings</td></tr>
   64:      <tr><td>Errors</td><td>$errors</td></tr>
   65:      </table><p><a href="#top">Top</a></p>
   66: ENDERROUT
   67: }
   68: 
   69: sub rotate_logfile {
   70:     my ($file,$fh,$description) = @_;
   71:     my $size=(stat($file))[7];
   72:     if ($size>40000) {
   73: 	&log($fh,"<p>Rotating $description ...</p>");
   74: 	rename("$file.2","$file.3");
   75: 	rename("$file.1","$file.2");
   76: 	rename("$file","$file.1");
   77:     } 
   78: }
   79: 
   80: sub start_daemon {
   81:     my ($fh,$daemon,$pidfile,$args) = @_;
   82:     my $progname=$daemon;
   83:     if ($daemon eq 'lonc') {
   84: 	$progname='loncnew'; 
   85:     }
   86:     my $error_fname="$perlvar{'lonDaemons'}/logs/${daemon}_errors";
   87:     &rotate_logfile($error_fname,$fh,'error logs');
   88:     if ($daemon eq 'lonc') {
   89: 	&clean_sockets($fh);
   90:     }
   91:     system("$perlvar{'lonDaemons'}/$progname 2>$perlvar{'lonDaemons'}/logs/${daemon}_errors");
   92:     sleep 1;
   93:     if (-e $pidfile) {
   94: 	&log($fh,"<p>Seems like it started ...</p>");
   95: 	my $lfh=IO::File->new("$pidfile");
   96: 	my $daemonpid=<$lfh>;
   97: 	chomp($daemonpid);
   98: 	if ($daemonpid =~ /^\d+$/ && kill 0 => $daemonpid) {
   99: 	    return 1;
  100: 	} else {
  101: 	    return 0;
  102: 	}
  103:     }
  104:     &log($fh,"<p>Seems like that did not work!</p>");
  105:     $errors++;
  106:     return 0;
  107: }
  108: 
  109: sub checkon_daemon {
  110:     my ($fh,$daemon,$maxsize,$send,$args)=@_;
  111: 
  112:     my $result;
  113:     &log($fh,'<hr /><a name="'.$daemon.'" /><h2>'.$daemon.'</h2><h3>Log</h3><p style="white-space: pre;"><tt>');
  114:     printf("%-15s ",$daemon);
  115:     if ($fh) {
  116:         if (-e "$perlvar{'lonDaemons'}/logs/$daemon.log"){
  117: 	    if (open(DFH,"tail -n25 $perlvar{'lonDaemons'}/logs/$daemon.log|")) {
  118: 	        while (my $line=<DFH>) {
  119: 	            &log($fh,"$line");
  120: 	            if ($line=~/INFO/) { $notices++; }
  121: 	            if ($line=~/WARNING/) { $notices++; }
  122: 	            if ($line=~/CRITICAL/) { $warnings++; }
  123: 	        }
  124: 	        close (DFH);
  125:             }
  126:         }
  127:         &log($fh,"</tt></p>");
  128:     }
  129:    
  130:     my $pidfile="$perlvar{'lonDaemons'}/logs/$daemon.pid";
  131:     
  132:     my $restartflag=1;
  133:     my $daemonpid;
  134:     if (-e $pidfile) {
  135: 	my $lfh=IO::File->new("$pidfile");
  136: 	$daemonpid=<$lfh>;
  137: 	chomp($daemonpid);
  138: 	if ($daemonpid =~ /^\d+$/ && kill 0 => $daemonpid) {
  139: 	    &log($fh,"<h3>$daemon at pid $daemonpid responding");
  140: 	    if ($send) { &log($fh,", sending $send"); }
  141: 	    &log($fh,"</h3>");
  142: 	    if ($send eq 'USR1') { kill USR1 => $daemonpid; }
  143: 	    if ($send eq 'USR2') { kill USR2 => $daemonpid; }
  144: 	    $restartflag=0;
  145: 	    if ($send eq 'USR2') {
  146: 		$result = 'reloaded';
  147: 		print "reloaded\n";
  148: 	    } else {
  149: 		$result = 'running';
  150: 		print "running\n";
  151: 	    }
  152: 	} else {
  153: 	    $errors++;
  154: 	    &log($fh,"<h3>$daemon at pid $daemonpid not responding</h3>");
  155: 	    $restartflag=1;
  156: 	    &log($fh,"<h3>Decided to clean up stale .pid file and restart $daemon</h3>");
  157: 	}
  158:     }
  159:     if ($restartflag==1) {
  160: 	$simplestatus{$daemon}='off';
  161: 	$errors++;
  162: 	my $kadaemon=$daemon;
  163: 	if ($kadaemon eq 'lonmemcached') { $kadaemon='memcached'; }
  164: 	&log($fh,'<br /><font color="red">Killall '.$daemon.': '.
  165: 	    `killall $kadaemon 2>&1`.' - ');
  166: 	sleep 1;
  167: 	&log($fh,unlink($pidfile).' - '.
  168: 	    `killall -9 $kadaemon 2>&1`.
  169: 	    '</font><br />');
  170: 	&log($fh,"<h3>$daemon not running, trying to start</h3>");
  171: 
  172: 	if (&start_daemon($fh,$daemon,$pidfile,$args)) {
  173: 	    &log($fh,"<h3>$daemon at pid $daemonpid responding</h3>");
  174: 	    $simplestatus{$daemon}='restarted';
  175: 	    $result = 'started';
  176: 	    print "started\n";
  177: 	} else {
  178: 	    $errors++;
  179: 	    &log($fh,"<h3>$daemon at pid $daemonpid not responding</h3>");
  180: 	    &log($fh,"<p>Give it one more try ...</p>");
  181: 	    print " ";
  182: 	    if (&start_daemon($fh,$daemon,$pidfile,$args)) {
  183: 		&log($fh,"<h3>$daemon at pid $daemonpid responding</h3>");
  184: 		$simplestatus{$daemon}='restarted';
  185: 		$result = 'started';
  186: 		print "started\n";
  187: 	    } else {
  188: 		$result = 'failed';
  189: 		print " failed\n";
  190: 		$simplestatus{$daemon}='failed';
  191: 		$errors++; $errors++;
  192: 		&log($fh,"<h3>$daemon at pid $daemonpid not responding</h3>");
  193: 		&log($fh,"<p>Unable to start $daemon</p>");
  194: 	    }
  195: 	}
  196:         if ($fh) {
  197: 	    if (-e "$perlvar{'lonDaemons'}/logs/$daemon.log"){
  198: 	        &log($fh,"<p><pre>");
  199: 	        if (open(DFH,"tail -n100 $perlvar{'lonDaemons'}/logs/$daemon.log|")) {
  200: 	            while (my $line=<DFH>) { 
  201: 		        &log($fh,"$line");
  202: 		        if ($line=~/WARNING/) { $notices++; }
  203: 		        if ($line=~/CRITICAL/) { $notices++; }
  204: 	            }
  205: 	            close (DFH);
  206:                 }
  207: 	        &log($fh,"</pre></p>");
  208: 	    }
  209:         }
  210:     }
  211:     
  212:     my $fname="$perlvar{'lonDaemons'}/logs/$daemon.log";
  213:     &rotate_logfile($fname,$fh,'logs');
  214: 
  215:     &errout($fh);
  216:     return $result;
  217: }
  218: 
  219: # --------------------------------------------------------------------- Machine
  220: sub log_machine_info {
  221:     my ($fh)=@_;
  222:     &log($fh,'<hr /><a name="machine" /><h2>Machine Information</h2>');
  223:     &log($fh,"<h3>loadavg</h3>");
  224: 	
  225:     open (LOADAVGH,"/proc/loadavg");
  226:     my $loadavg=<LOADAVGH>;
  227:     close (LOADAVGH);
  228:     
  229:     &log($fh,"<tt>$loadavg</tt>");
  230:     
  231:     my @parts=split(/\s+/,$loadavg);
  232:     if ($parts[1]>4.0) {
  233: 	$errors++;
  234:     } elsif ($parts[1]>2.0) {
  235: 	$warnings++;
  236:     } elsif ($parts[1]>1.0) {
  237: 	$notices++;
  238:     }
  239: 
  240:     &log($fh,"<h3>df</h3>");
  241:     &log($fh,"<pre>");
  242: 
  243:     open (DFH,"df|");
  244:     while (my $line=<DFH>) { 
  245: 	&log($fh,&encode_entities($line,'<>&"')); 
  246: 	@parts=split(/\s+/,$line);
  247: 	my $usage=$parts[4];
  248: 	$usage=~s/\W//g;
  249: 	if ($usage>90) { 
  250: 	    $warnings++;
  251: 	    $notices++; 
  252: 	} elsif ($usage>80) {
  253: 	    $warnings++;
  254: 	} elsif ($usage>60) {
  255: 	    $notices++;
  256: 	}
  257: 	if ($usage>95) { $warnings++; $warnings++; $simplestatus{'diskfull'}++; }
  258:     }
  259:     close (DFH);
  260:     &log($fh,"</pre>");
  261: 
  262: 
  263:     &log($fh,"<h3>ps</h3>");
  264:     &log($fh,"<pre>");
  265:     my $psproc=0;
  266: 
  267:     open (PSH,"ps aux --cols 140 |");
  268:     while (my $line=<PSH>) { 
  269: 	&log($fh,&encode_entities($line,'<>&"')); 
  270: 	$psproc++;
  271:     }
  272:     close (PSH);
  273:     &log($fh,"</pre>");
  274: 
  275:     if ($psproc>200) { $notices++; }
  276:     if ($psproc>250) { $notices++; }
  277: 
  278:     &log($fh,"<h3>distprobe</h3>");
  279:     &log($fh,"<pre>");
  280:     &log($fh,&encode_entities(&LONCAPA::distro(),'<>&"'));
  281:     &log($fh,"</pre>");
  282: 
  283:     &errout($fh);
  284: }
  285: 
  286: sub start_logging {
  287:     my $fh=IO::File->new(">$statusdir/newstatus.html");
  288:     my %simplestatus=();
  289:     my $now=time;
  290:     my $date=localtime($now);
  291:     
  292: 
  293:     &log($fh,(<<ENDHEADERS));
  294: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  295: <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  296: <head>
  297: <title>LON Status Report $perlvar{'lonHostID'}</title>
  298: <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  299: </head>
  300: <body bgcolor="#AAAAAA">
  301: <a name="top" />
  302: <h1>LON Status Report $perlvar{'lonHostID'}</h1>
  303: <h2>$date ($now)</h2>
  304: <ol>
  305: <li><a href="#configuration">Configuration</a></li>
  306: <li><a href="#machine">Machine Information</a></li>
  307: <li><a href="#tmp">Temporary Files</a></li>
  308: <li><a href="#tokens">Session Tokens</a></li>
  309: <li><a href="#webdav">WebDAV Session Tokens</a></li>
  310: <li><a href="#httpd">httpd</a></li>
  311: <li><a href="#lonsql">lonsql</a></li>
  312: <li><a href="#lond">lond</a></li>
  313: <li><a href="#lonc">lonc</a></li>
  314: <li><a href="#lonnet">lonnet</a></li>
  315: <li><a href="#connections">Connections</a></li>
  316: <li><a href="#delayed">Delayed Messages</a></li>
  317: <li><a href="#errcount">Error Count</a></li>
  318: </ol>
  319: <hr />
  320: <a name="configuration" />
  321: <h2>Configuration</h2>
  322: <h3>PerlVars</h3>
  323: <table border="2">
  324: ENDHEADERS
  325: 
  326:     foreach my $varname (sort(keys(%perlvar))) {
  327: 	&log($fh,"<tr><td>$varname</td><td>".
  328: 	     &encode_entities($perlvar{$varname},'<>&"')."</td></tr>\n");
  329:     }
  330:     &log($fh,"</table><h3>Hosts</h3><table border='2'>");
  331:     my %hostname = &Apache::lonnet::all_hostnames();
  332:     foreach my $id (sort(keys(%hostname))) {
  333: 	my $role = (&Apache::lonnet::is_library($id) ? 'library'
  334: 		                                     : 'access');
  335: 	&log($fh,
  336: 	    "<tr><td>$id</td><td>".&Apache::lonnet::host_domain($id).
  337: 	    "</td><td>".$role.
  338: 	    "</td><td>".&Apache::lonnet::hostname($id)."</td></tr>\n");
  339:     }
  340:     &log($fh,"</table><h3>Spare Hosts</h3>");
  341:     if (keys(%Apache::lonnet::spareid) > 0) {
  342:         &log($fh,"<ul>");
  343:         foreach my $type (sort(keys(%Apache::lonnet::spareid))) {
  344: 	    &log($fh,"<li>$type\n<ol>");
  345: 	    foreach my $id (@{ $Apache::lonnet::spareid{$type} }) {
  346: 	        &log($fh,"<li>$id</li>\n");
  347: 	    }
  348: 	    &log($fh,"</ol>\n</li>\n");
  349:         }
  350:         &log($fh,"</ul>\n");
  351:     } else {
  352:         &log($fh,"No spare hosts specified<br />\n");
  353:     }
  354:     return $fh;
  355: }
  356: 
  357: # --------------------------------------------------------------- clean out tmp
  358: sub clean_tmp {
  359:     my ($fh)=@_;
  360:     &log($fh,'<hr /><a name="tmp" /><h2>Temporary Files</h2>');
  361:     my ($cleaned,$old,$removed) = (0,0,0);
  362:     my %errors = (
  363:                      dir       => [],
  364:                      file      => [],
  365:                      failopen  => [],
  366:                  );
  367:     my %error_titles = (
  368:                          dir       => 'failed to remove empty directory:',
  369:                          file      => 'failed to unlike stale file',
  370:                          failopen  => 'failed to open file or directory'
  371:                        );
  372:     ($cleaned,$old,$removed) = &recursive_clean_tmp('',$cleaned,$old,$removed,\%errors);
  373:     &log($fh,"Cleaned up: ".$cleaned." files; removed: $removed empty directories; (found: $old old checkout tokens)");
  374:     foreach my $key (sort(keys(%errors))) {
  375:         if (ref($errors{$key}) eq 'ARRAY') {
  376:             if (@{$errors{$key}} > 0) {
  377:                 &log($fh,"Error during cleanup ($error_titles{$key}):<ul><li>".
  378:                      join('</li><li><tt>',@{$errors{$key}}).'</tt></li></ul><br />');
  379:             }
  380:         }
  381:     }
  382: }
  383: 
  384: sub recursive_clean_tmp {
  385:     my ($subdir,$cleaned,$old,$removed,$errors) = @_;
  386:     my $base = "$perlvar{'lonDaemons'}/tmp";
  387:     my $path = $base;
  388:     next if ($subdir =~ m{\.\./});
  389:     next unless (ref($errors) eq 'HASH');
  390:     unless ($subdir eq '') {
  391:         $path .= '/'.$subdir;
  392:     }
  393:     if (opendir(my $dh,"$path")) {
  394:         while (my $file = readdir($dh)) {
  395:             next if ($file =~ /^\.\.?$/);
  396:             my $fname = "$path/$file";
  397:             if (-d $fname) {
  398:                 my $innerdir;
  399:                 if ($subdir eq '') {
  400:                     $innerdir = $file;
  401:                 } else {
  402:                     $innerdir = $subdir.'/'.$file;
  403:                 }
  404:                 ($cleaned,$old,$removed) = 
  405:                      &recursive_clean_tmp($innerdir,$cleaned,$old,$removed,$errors);
  406:                 my @doms = &Apache::lonnet::current_machine_domains();
  407:                 
  408:                 if (open(my $dirhandle,$fname)) {
  409:                     unless (($innerdir eq 'helprequests') ||
  410:                             (($innerdir =~ /^addcourse/) && ($innerdir !~ m{/\d+$}))) {
  411:                         my @contents = grep {!/^\.\.?$/} readdir($dirhandle);
  412:                                       join('&&',@contents)."\n";    
  413:                         if (scalar(grep {!/^\.\.?$/} readdir($dirhandle)) == 0) {
  414:                             closedir($dirhandle);
  415:                             if ($fname =~ m{^\Q$perlvar{'lonDaemons'}\E/tmp/}) {
  416:                                 if (rmdir($fname)) {
  417:                                     $removed ++;
  418:                                 } elsif (ref($errors->{dir}) eq 'ARRAY') {
  419:                                     push(@{$errors->{dir}},$fname);
  420:                                 }
  421:                             }
  422:                         }
  423:                     } else {
  424:                         closedir($dirhandle);
  425:                     }
  426:                 }
  427:             } else {
  428:                 my ($dev,$ino,$mode,$nlink,
  429:                     $uid,$gid,$rdev,$size,
  430:                     $atime,$mtime,$ctime,
  431:                     $blksize,$blocks)=stat($fname);
  432:                 my $now=time;
  433:                 my $since=$now-$mtime;
  434:                 if ($since>$perlvar{'lonExpire'}) {
  435:                     if ($subdir eq '') {
  436:                         my $line='';
  437:                         if ($fname =~ /\.db$/) {
  438:                             if (unlink($fname)) {
  439:                                 $cleaned++;
  440:                             } elsif (ref($errors->{file}) eq 'ARRAY') {
  441:                                 push(@{$errors->{file}},$fname);
  442:                             }
  443:                         } elsif (open(PROBE,$fname)) {
  444:                             my $line='';
  445:                             $line=<PROBE>;
  446:                             close(PROBE);
  447:                             if ($line=~/^CHECKOUTTOKEN\&/) {
  448:                                 if ($since>365*$perlvar{'lonExpire'}) {
  449:                                     if (unlink($fname)) {
  450:                                         $cleaned++; 
  451:                                     } elsif (ref($errors->{file}) eq 'ARRAY') {
  452:                                         push(@{$errors->{file}},$fname);
  453:                                     }
  454:                                 } else {
  455:                                     $old++;
  456:                                 }
  457:                             } else {
  458:                                 if (unlink($fname)) {
  459:                                     $cleaned++;
  460:                                 } elsif (ref($errors->{file}) eq 'ARRAY') {
  461:                                     push(@{$errors->{file}},$fname);
  462:                                 }
  463:                             }
  464:                         } elsif (ref($errors->{failopen}) eq 'ARRAY') {
  465:                             push(@{$errors->{failopen}},$fname); 
  466:                         }
  467:                     } else {
  468:                         if (unlink($fname)) {
  469:                             $cleaned++;
  470:                         } elsif (ref($errors->{file}) eq 'ARRAY') {
  471:                             push(@{$errors->{file}},$fname);
  472:                         }
  473:                     }
  474:                 }
  475:             }
  476:         }
  477:         closedir($dh);
  478:     } elsif (ref($errors->{failopen}) eq 'ARRAY') {
  479:         push(@{$errors->{failopen}},$path);
  480:     }
  481:     return ($cleaned,$old,$removed);
  482: }
  483: 
  484: # ------------------------------------------------------------ clean out lonIDs
  485: sub clean_lonIDs {
  486:     my ($fh)=@_;
  487:     &log($fh,'<hr /><a name="tokens" /><h2>Session Tokens</h2>');
  488:     my $cleaned=0;
  489:     my $active=0;
  490:     while (my $fname=<$perlvar{'lonIDsDir'}/*>) {
  491: 	my ($dev,$ino,$mode,$nlink,
  492: 	    $uid,$gid,$rdev,$size,
  493: 	    $atime,$mtime,$ctime,
  494: 	    $blksize,$blocks)=stat($fname);
  495: 	my $now=time;
  496: 	my $since=$now-$mtime;
  497: 	if ($since>$perlvar{'lonExpire'}) {
  498: 	    $cleaned++;
  499: 	    &log($fh,"Unlinking $fname<br />");
  500: 	    unlink("$fname");
  501: 	} else {
  502: 	    $active++;
  503: 	}
  504:     }
  505:     &log($fh,"<p>Cleaned up ".$cleaned." stale session token(s).</p>");
  506:     &log($fh,"<h3>$active open session(s)</h3>");
  507: }
  508: 
  509: # ------------------------------------------------ clean out webDAV Session IDs
  510: sub clean_webDAV_sessionIDs {
  511:     my ($fh)=@_;
  512:     if ($perlvar{'lonRole'} eq 'library') {
  513:         &log($fh,'<hr /><a name="webdav" /><h2>WebDAV Session Tokens</h2>');
  514:         my $cleaned=0;
  515:         my $active=0;
  516:         my $now = time;
  517:         if (-d $perlvar{'lonDAVsessDir'}) {
  518:             while (my $fname=<$perlvar{'lonDAVsessDir'}/*>) {
  519:                 my @stats = stat($fname);
  520:                 my $since=$now-$stats[9];
  521:                 if ($since>$perlvar{'lonExpire'}) {
  522:                     $cleaned++;
  523:                     &log($fh,"Unlinking $fname<br />");
  524:                     unlink("$fname");
  525:                 } else {
  526:                     $active++;
  527:                 }
  528:             }
  529:             &log($fh,"<p>Cleaned up ".$cleaned." stale webDAV session token(s).</p>");
  530:             &log($fh,"<h3>$active open webDAV session(s)</h3>");
  531:         }
  532:     }
  533: }
  534: 
  535: # ----------------------------------------------------------- clean out sockets
  536: sub clean_sockets {
  537:     my ($fh)=@_;
  538:     my $cleaned=0;
  539:     opendir(SOCKETS,$perlvar{'lonSockDir'});
  540:     while (my $fname=readdir(SOCKETS)) {
  541: 	next if (-d $fname 
  542: 		 || $fname=~/(mysqlsock|maximasock|rsock|\Q$perlvar{'lonSockDir'}\E)/);
  543: 	$cleaned++;
  544: 	&log($fh,"Unlinking $fname<br />");
  545: 	unlink("/home/httpd/sockets/$fname");
  546:     }
  547:     &log($fh,"<p>Cleaned up ".$cleaned." stale sockets.</p>");
  548: }
  549: 
  550: 
  551: # ----------------------------------------------------------------------- httpd
  552: sub check_httpd_logs {
  553:     my ($fh)=@_;
  554:     if (open(PIPE,"./lchttpdlogs|")) {
  555:         while (my $line=<PIPE>) {
  556:             &log($fh,$line);
  557:             if ($line=~/\[error\]/) { $notices++; }
  558:         }
  559:         close(PIPE);
  560:     }
  561:     &errout($fh);
  562: }
  563: 
  564: # ---------------------------------------------------------------------- lonnet
  565: 
  566: sub rotate_lonnet_logs {
  567:     my ($fh)=@_;
  568:     &log($fh,'<hr /><a name="lonnet" /><h2>lonnet</h2><h3>Temp Log</h3><pre>');
  569:     print "Checking logs.\n";
  570:     if (-e "$perlvar{'lonDaemons'}/logs/lonnet.log"){
  571: 	open (DFH,"tail -n50 $perlvar{'lonDaemons'}/logs/lonnet.log|");
  572: 	while (my $line=<DFH>) { 
  573: 	    &log($fh,&encode_entities($line,'<>&"'));
  574: 	}
  575: 	close (DFH);
  576:     }
  577:     &log($fh,"</pre><h3>Perm Log</h3><pre>");
  578:     
  579:     if (-e "$perlvar{'lonDaemons'}/logs/lonnet.perm.log") {
  580: 	open(DFH,"tail -n10 $perlvar{'lonDaemons'}/logs/lonnet.perm.log|");
  581: 	while (my $line=<DFH>) { 
  582: 	    &log($fh,&encode_entities($line,'<>&"'));
  583: 	}
  584: 	close (DFH);
  585:     } else { &log($fh,"No perm log\n") }
  586: 
  587:     my $fname="$perlvar{'lonDaemons'}/logs/lonnet.log";
  588:     &rotate_logfile($fname,$fh,'lonnet log');
  589: 
  590:     &log($fh,"</pre>");
  591:     &errout($fh);
  592: }
  593: 
  594: sub rotate_other_logs {
  595:     my ($fh) = @_;
  596:     my %logs = (
  597:                   autoenroll          => 'Auto Enroll log',
  598:                   autocreate          => 'Create Course log',
  599:                   searchcat           => 'Search Cataloguing log',
  600:                   autoupdate          => 'Auto Update log',
  601:                   refreshcourseids_db => 'Refresh CourseIDs db log',
  602:                );
  603:     foreach my $item (keys(%logs)) {
  604:         my $fname=$perlvar{'lonDaemons'}.'/logs/'.$item.'.log';
  605:         &rotate_logfile($fname,$fh,$logs{$item});
  606:     }
  607: }
  608: 
  609: # ----------------------------------------------------------------- Connections
  610: sub test_connections {
  611:     my ($fh)=@_;
  612:     &log($fh,'<hr /><a name="connections" /><h2>Connections</h2>');
  613:     print "Testing connections.\n";
  614:     &log($fh,"<table border='2'>");
  615:     my ($good,$bad)=(0,0);
  616:     my %hostname = &Apache::lonnet::all_hostnames();
  617:     foreach my $tryserver (sort(keys(%hostname))) {
  618: 	print(".");
  619: 	my $result;
  620: 	my $answer=&Apache::lonnet::reply("ping",$tryserver);
  621: 	if ($answer eq "$tryserver:$perlvar{'lonHostID'}") {
  622: 	    $result="<b>ok</b>";
  623: 	    $good++;
  624: 	} else {
  625: 	    $result=$answer;
  626: 	    $warnings++;
  627: 	    if ($answer eq 'con_lost') {
  628: 		$bad++;
  629: 		$warnings++;
  630: 	    } else {
  631: 		$good++; #self connection
  632: 	    }
  633: 	}
  634: 	if ($answer =~ /con_lost/) { print(" $tryserver down\n"); }
  635: 	&log($fh,"<tr><td>$tryserver</td><td>$result</td></tr>\n");
  636:     }
  637:     &log($fh,"</table>");
  638:     print "\n$good good, $bad bad connections\n";
  639:     &errout($fh);
  640: }
  641: 
  642: 
  643: # ------------------------------------------------------------ Delayed messages
  644: sub check_delayed_msg {
  645:     my ($fh)=@_;
  646:     &log($fh,'<hr /><a name="delayed" /><h2>Delayed Messages</h2>');
  647:     print "Checking buffers.\n";
  648:     
  649:     &log($fh,'<h3>Scanning Permanent Log</h3>');
  650: 
  651:     my $unsend=0;
  652: 
  653:     my %hostname = &Apache::lonnet::all_hostnames();
  654:     my $numhosts = scalar(keys(%hostname));
  655: 
  656:     my $dfh=IO::File->new("$perlvar{'lonDaemons'}/logs/lonnet.perm.log");
  657:     while (my $line=<$dfh>) {
  658: 	my ($time,$sdf,$dserv,$dcmd)=split(/:/,$line);
  659:         if ($numhosts) {
  660:             next unless ($hostname{$dserv});
  661:         }
  662: 	if ($sdf eq 'F') { 
  663: 	    my $local=localtime($time);
  664: 	    &log($fh,"<b>Failed: $time, $dserv, $dcmd</b><br />");
  665: 	    $warnings++;
  666: 	}
  667: 	if ($sdf eq 'S') { $unsend--; }
  668: 	if ($sdf eq 'D') { $unsend++; }
  669:     }
  670: 
  671:     &log($fh,"<p>Total unsend messages: <b>$unsend</b></p>\n");
  672:     if ($unsend > 0) {
  673:         $warnings=$warnings+5*$unsend;
  674:     }
  675: 
  676:     if ($unsend) { $simplestatus{'unsend'}=$unsend; }
  677:     &log($fh,"<h3>Outgoing Buffer</h3>\n<pre>");
  678: # list directory with delayed messages and remember offline servers
  679:     my %servers=();
  680:     open (DFH,"ls -lF $perlvar{'lonSockDir'}/delayed|");
  681:     while (my $line=<DFH>) {
  682:         my ($server)=($line=~/\.(\w+)$/);
  683:         if ($server) { $servers{$server}=1; }
  684: 	&log($fh,&encode_entities($line,'<>&"'));
  685:     }
  686:     &log($fh,"</pre>\n");
  687:     close (DFH);
  688: # pong to all servers that have delayed messages
  689: # this will trigger a reverse connection, which should flush the buffers
  690:     foreach my $tryserver (sort(keys(%servers))) {
  691:         if ($hostname{$tryserver} || !$numhosts) {
  692:             my $answer;
  693:             eval {
  694:                 local $SIG{ ALRM } = sub { die "TIMEOUT" };
  695:                 alarm(20);
  696:                 $answer = &Apache::lonnet::reply("pong",$tryserver);
  697:                 alarm(0);
  698:             };
  699:             if ($@ && $@ =~ m/TIMEOUT/) {
  700:                 &log($fh,"Attempted pong to $tryserver timed out<br />");
  701:                 print "Time out while contacting: $tryserver for pong.\n";
  702:             } else {
  703:                 &log($fh,"Pong to $tryserver: $answer<br />");
  704:             }
  705:         } else {
  706:             &log($fh,"$tryserver has delayed messages, but is not part of the cluster -- skipping 'Pong'.<br />");
  707:         }
  708:     }
  709: }
  710: 
  711: sub finish_logging {
  712:     my ($fh)=@_;
  713:     &log($fh,"<a name='errcount' />\n");
  714:     $totalcount=$notices+4*$warnings+100*$errors;
  715:     &errout($fh);
  716:     &log($fh,"<h1>Total Error Count: $totalcount</h1>");
  717:     my $now=time;
  718:     my $date=localtime($now);
  719:     &log($fh,"<hr />$date ($now)</body></html>\n");
  720:     print "lon-status webpage updated.\n";
  721:     $fh->close();
  722: 
  723:     if ($errors) { $simplestatus{'errors'}=$errors; }
  724:     if ($warnings) { $simplestatus{'warnings'}=$warnings; }
  725:     if ($notices) { $simplestatus{'notices'}=$notices; }
  726:     $simplestatus{'time'}=time;
  727: }
  728: 
  729: sub log_simplestatus {
  730:     rename("$statusdir/newstatus.html","$statusdir/index.html");
  731:     
  732:     my $sfh=IO::File->new(">$statusdir/loncron_simple.txt");
  733:     foreach (keys %simplestatus) {
  734: 	print $sfh $_.'='.$simplestatus{$_}.'&';
  735:     }
  736:     print $sfh "\n";
  737:     $sfh->close();
  738: }
  739: 
  740: sub write_loncaparevs {
  741:     print "Retrieving LON-CAPA version information.\n";
  742:     my %hostname = &Apache::lonnet::all_hostnames();
  743:     my $output;
  744:     foreach my $id (sort(keys(%hostname))) {
  745:         if ($id ne '') {
  746:             my $loncaparev;
  747:             eval {
  748:                 local $SIG{ ALRM } = sub { die "TIMEOUT" };
  749:                 alarm(10);
  750:                 $loncaparev =
  751:                     &Apache::lonnet::get_server_loncaparev('',$id,1,'loncron');
  752:                 alarm(0);
  753:             };
  754:             if ($@ && $@ =~ m/TIMEOUT/) {
  755:                 print "Time out while contacting lonHost: $id for version.\n";   
  756:             }
  757:             if ($loncaparev =~ /^[\w.\-]+$/) {
  758:                 $output .= $id.':'.$loncaparev."\n";
  759:             }
  760:         }
  761:     }
  762:     if ($output) {
  763:         if (open(my $fh,">$perlvar{'lonTabDir'}/loncaparevs.tab")) {
  764:             print $fh $output;
  765:             close($fh);
  766:             &Apache::lonnet::load_loncaparevs();
  767:         }
  768:     }
  769:     return;
  770: }
  771: 
  772: sub write_serverhomeIDs {
  773:     print "Retrieving LON-CAPA lonHostID information.\n";
  774:     my %name_to_host = &Apache::lonnet::all_names();
  775:     my $output;
  776:     foreach my $name (sort(keys(%name_to_host))) {
  777:         if ($name ne '') {
  778:             if (ref($name_to_host{$name}) eq 'ARRAY') {
  779:                 my $serverhomeID;
  780:                 eval {
  781:                     local $SIG{ ALRM } = sub { die "TIMEOUT" };
  782:                     alarm(10);
  783:                     $serverhomeID = 
  784:                         &Apache::lonnet::get_server_homeID($name,1,'loncron');
  785:                     alarm(0);
  786:                 };
  787:                 if ($@ && $@ =~ m/TIMEOUT/) {
  788:                     print "Time out while contacting server: $name\n"; 
  789:                 }
  790:                 if ($serverhomeID ne '') {
  791:                     $output .= $name.':'.$serverhomeID."\n";
  792:                 } else {
  793:                     $output .= $name.':'.$name_to_host{$name}->[0]."\n";
  794:                 }
  795:             }
  796:         }
  797:     }
  798:     if ($output) {
  799:         if (open(my $fh,">$perlvar{'lonTabDir'}/serverhomeIDs.tab")) {
  800:             print $fh $output;
  801:             close($fh);
  802:             &Apache::lonnet::load_serverhomeIDs();
  803:         }
  804:     }
  805:     return;
  806: }
  807: 
  808: sub write_checksums {
  809:     my $distro = &LONCAPA::distro();
  810:     if ($distro) {
  811:         print "Retrieving file version and checksumming.\n";
  812:         my $numchksums = 0;
  813:         my ($chksumsref,$versionsref) =
  814:             &LONCAPA::Checksumming::get_checksums($distro,$perlvar{'lonDaemons'},
  815:                                                   $perlvar{'lonLib'},
  816:                                                   $perlvar{'lonIncludes'},
  817:                                                   $perlvar{'lonTabDir'});
  818:         if (ref($chksumsref) eq 'HASH') {
  819:             $numchksums = scalar(keys(%{$chksumsref}));
  820:         }
  821:         print "File version retrieved and checksumming completed for $numchksums files.\n";
  822:     } else {
  823:         print "File version retrieval and checksumming skipped - could not determine Linux distro.\n"; 
  824:     }
  825:     return;
  826: }
  827: 
  828: sub write_hostips {
  829:     my $lontabdir = $perlvar{'lonTabDir'};
  830:     my $defdom = $perlvar{'lonDefDomain'};
  831:     my $lonhost = $perlvar{'lonHostID'};
  832:     my $newfile = "$lontabdir/currhostips.tab";
  833:     my $oldfile = "$lontabdir/prevhostips.tab";
  834:     my (%prevhosts,%currhosts,%ipchange);
  835:     if ((-e $newfile) && (-s $newfile)) {
  836:         move($newfile,$oldfile);
  837:         chmod(0644,$oldfile);
  838:         if (open(my $fh,'<',$oldfile)) {
  839:             while (my $line=<$fh>) {
  840:                 chomp($line);
  841:                 if ($line =~ /^([^:]+):([\d.]+)$/) {
  842:                     $prevhosts{$1} = $2;
  843:                 }
  844:             }
  845:             close($fh);
  846:         }
  847:     }
  848:     my ($ip_info,$cached) =
  849:         &Apache::lonnet::is_cached_new('iphost','iphost');
  850:     if (!$cached) {
  851:         &Apache::lonnet::get_iphost();
  852:         ($ip_info,$cached) =
  853:         &Apache::lonnet::is_cached_new('iphost','iphost');
  854:     }
  855:     if (ref($ip_info) eq 'ARRAY') {
  856:         %currhosts = %{$ip_info->[1]};
  857:         if (open(my $fh,'>',$newfile)) {
  858:             foreach my $key (keys(%currhosts)) {
  859:                 print $fh "$key:$currhosts{$key}\n";
  860:             }
  861:             close($fh);
  862:             chmod(0644,$newfile);
  863:         }
  864:     }
  865:     if (keys(%prevhosts) && keys(%currhosts)) {
  866:         foreach my $key (keys(%prevhosts)) {
  867:             unless ($currhosts{$key} eq $prevhosts{$key}) {
  868:                 $ipchange{$key} = $prevhosts{$key}.'|'.$currhosts{$key};
  869:             }
  870:         }
  871:         foreach my $key (keys(%currhosts)) {
  872:             unless ($currhosts{$key} eq $prevhosts{$key}) {
  873:                 $ipchange{$key} = $prevhosts{$key}.' | '.$currhosts{$key};
  874:             }
  875:         }
  876:     }
  877:     if (&Apache::lonnet::domain($defdom,'primary') eq $lonhost) {
  878:         if (keys(%ipchange)) {
  879:             if (open(my $fh,'>>',$perlvar{'lonDaemons'}.'/logs/hostip.log')) {
  880:                print $fh "********************\n".localtime(time).' Changes --'."\n".
  881:                          "Hostname | Previous IP | New IP\n".
  882:                          "--------------------------------\n";
  883:                foreach my $hostname (sort(keys(%ipchange))) {
  884:                     print $fh "$hostname | $ipchange{$hostname}\n";
  885:                 }
  886:                 print $fh "\n*******************\n\n";
  887:                 close($fh);
  888:             }
  889:             my $emailto = &Apache::loncommon::build_recipient_list(undef,
  890:                                    'hostipmail',$defdom);
  891:             if ($emailto) {
  892:                 my $subject = "LON-CAPA Hostname to IP change ($perlvar{'lonHostID'})";
  893:                 my $chgmail = "To: $emailto\n".
  894:                               "Subject: $subject\n".
  895:                               "Content-type: text/plain\; charset=UTF-8\n".
  896:                               "MIME-Version: 1.0\n\n".
  897:                               "Host/IP changes\n".
  898:                               " \n".
  899:                               "Hostname | Previous IP | New IP\n".
  900:                               "--------------------------------\n";
  901:                 foreach my $hostname (sort(keys(%ipchange))) {
  902:                     $chgmail .= "$hostname | $ipchange{$hostname}\n";
  903:                 }
  904:                 $chgmail .= "\n\n";
  905:                 if (open(my $mailh, "|/usr/lib/sendmail -oi -t -odb")) {
  906:                     print $mailh $chgmail;
  907:                     close($mailh);
  908:                     print "Sending mail notification of hostname/IP changes.\n";
  909:                 }
  910:             }
  911:         }
  912:     }
  913:     return;
  914: }
  915: 
  916: sub send_mail {
  917:     my $defdom = $perlvar{'lonDefDomain'};
  918:     my $origmail = $perlvar{'lonAdmEMail'};
  919:     my $emailto = &Apache::loncommon::build_recipient_list(undef,
  920:                                    'lonstatusmail',$defdom,$origmail);
  921:     if ($totalcount>2500) {
  922: 	$emailto.=",$perlvar{'lonSysEMail'}";
  923:     }
  924:     my $from;
  925:     my $hostname=`/bin/hostname`;
  926:     chop($hostname);
  927:     $hostname=~s/[^\w\.]//g;
  928:     if ($hostname) {
  929:         $from = 'www@'.$hostname;
  930:     }
  931:     my $subj="LON: $perlvar{'lonHostID'} E:$errors W:$warnings N:$notices";
  932:     my $loncronmail = "To: $emailto\n".
  933:                       "From: $from\n".
  934:                       "Subject: ".$subj."\n".
  935:                       "Content-type: text/html\; charset=UTF-8\n".
  936:                       "MIME-Version: 1.0\n\n";
  937:     if (open(my $fh,"<$statusdir/index.html")) {
  938:         while (<$fh>) {
  939:             $loncronmail .= $_;
  940:         }
  941:         close($fh);
  942:     } else {
  943:         $loncronmail .= "Failed to read from http://$hostname/lon-status/index.html\n";
  944:     }
  945:     $loncronmail .= "\n\n";
  946:     if (open(my $mailh, "|/usr/lib/sendmail -oi -t -odb")) {
  947:         print $mailh $loncronmail;
  948:         close($mailh);
  949:         print "Sending mail.\n";
  950:     } else {
  951:         print "Sending mail failed.\n";
  952:     }
  953: }
  954: 
  955: sub usage {
  956:     print(<<USAGE);
  957: loncron - housekeeping program that checks up on various parts of LON-CAPA
  958: 
  959: Options:
  960:    --help     Display 
  961:    --noemail  Do not send the status email
  962:    --justcheckconnections  Only check the current status of the lonc/d
  963:                                 connections, do not send emails do not
  964:                                 check if the daemons are running, do not
  965:                                 generate lon-status
  966:    --justcheckdaemons      Only check that all of the Lon-CAPA daemons are
  967:                                 running, do not send emails do not
  968:                                 check the lonc/d connections, do not
  969:                                 generate lon-status
  970:    --justreload            Only tell the daemons to reload the config files,
  971: 				do not send emails do not
  972:                                 check if the daemons are running, do not
  973:                                 generate lon-status
  974:    --justiptables          Only update the dynamic iptables rules for the
  975:                                 lond port; do not send emails, do not
  976:                                 check if the daemons are running, do not
  977:                                 generate lon-status
  978: USAGE
  979: }
  980: 
  981: # ================================================================ Main Program
  982: sub main () {
  983:     my ($help,$justcheckdaemons,$noemail,$justcheckconnections,
  984: 	$justreload,$justiptables);
  985:     &GetOptions("help"                 => \$help,
  986: 		"justcheckdaemons"     => \$justcheckdaemons,
  987: 		"noemail"              => \$noemail,
  988: 		"justcheckconnections" => \$justcheckconnections,
  989: 		"justreload"           => \$justreload,
  990:                 "justiptables"         => \$justiptables
  991: 		);
  992:     if ($help) { &usage(); return; }
  993: # --------------------------------- Read loncapa_apache.conf and loncapa.conf
  994:     my $perlvarref=LONCAPA::Configuration::read_conf('loncapa.conf');
  995:     %perlvar=%{$perlvarref};
  996:     undef $perlvarref;
  997:     delete $perlvar{'lonReceipt'}; # remove since sensitive and not needed
  998:     delete $perlvar{'lonSqlAccess'}; # remove since sensitive and not needed
  999:     chdir($perlvar{'lonDaemons'});
 1000: # --------------------------------------- Make sure that LON-CAPA is configured
 1001: # I only test for one thing here (lonHostID).  This is just a safeguard.
 1002:     if ('{[[[[lonHostID]]]]}' eq $perlvar{'lonHostID'}) {
 1003: 	print("Unconfigured machine.\n");
 1004: 	my $emailto=$perlvar{'lonSysEMail'};
 1005: 	my $hostname=`/bin/hostname`;
 1006: 	chop $hostname;
 1007: 	$hostname=~s/[^\w\.]//g; # make sure is safe to pass through shell
 1008: 	my $subj="LON: Unconfigured machine $hostname";
 1009: 	system("echo 'Unconfigured machine $hostname.' |".
 1010:                " mail -s '$subj' $emailto > /dev/null");
 1011: 	exit 1;
 1012:     }
 1013: 
 1014: # ----------------------------- Make sure this process is running from user=www
 1015:     my $wwwid=getpwnam('www');
 1016:     if ($wwwid!=$<) {
 1017: 	print("User ID mismatch. This program must be run as user 'www'.\n");
 1018: 	my $emailto="$perlvar{'lonAdmEMail'},$perlvar{'lonSysEMail'}";
 1019: 	my $subj="LON: $perlvar{'lonHostID'} User ID mismatch";
 1020: 	system("echo 'User ID mismatch. loncron must be run as user www.' |".
 1021:                " mail -s '$subj' $emailto > /dev/null");
 1022: 	exit 1;
 1023:     }
 1024: 
 1025: # -------------------------------------------- Force reload of host information
 1026:     my $nomemcache;
 1027:     if ($justcheckdaemons) {
 1028:         $nomemcache=1;
 1029:         my $memcachepidfile="$perlvar{'lonDaemons'}/logs/memcached.pid";
 1030:         my $memcachepid;
 1031:         if (-e $memcachepidfile) {
 1032:             my $memfh=IO::File->new($memcachepidfile);
 1033:             $memcachepid=<$memfh>;
 1034:             chomp($memcachepid);
 1035:             if ($memcachepid =~ /^\d+$/ && kill 0 => $memcachepid) {
 1036:                 undef($nomemcache);
 1037:             }
 1038:         }
 1039:     }
 1040:     if (!$justiptables) {
 1041:         &Apache::lonnet::load_hosts_tab(1,$nomemcache);
 1042:         &Apache::lonnet::load_domain_tab(1,$nomemcache);
 1043:         &Apache::lonnet::get_iphost(1,$nomemcache);
 1044:     }
 1045: 
 1046: # ----------------------------------------- Force firewall update for lond port  
 1047: 
 1048:     if ((!$justcheckdaemons) && (!$justreload)) {
 1049:         my $now = time;
 1050:         my $tmpfile = $perlvar{'lonDaemons'}.'/tmp/lciptables_iphost_'.
 1051:                       $now.$$.int(rand(10000));
 1052:         if (open(my $fh,">$tmpfile")) {
 1053:             my %iphosts = &Apache::lonnet::get_iphost();
 1054:             foreach my $key (keys(%iphosts)) {
 1055:                 print $fh "$key\n";
 1056:             }
 1057:             close($fh);
 1058:             if (&LONCAPA::try_to_lock('/tmp/lock_lciptables')) {
 1059:                 my $execpath = $perlvar{'lonDaemons'}.'/lciptables';
 1060:                 system("$execpath $tmpfile");
 1061:                 unlink('/tmp/lock_lciptables');  # Remove the lock file. 
 1062:             }
 1063:             unlink($tmpfile);
 1064:         }
 1065:     }
 1066: 
 1067: # ---------------------------------------------------------------- Start report
 1068: 
 1069:     $errors=0;
 1070:     $warnings=0;
 1071:     $notices=0;
 1072: 
 1073: 	
 1074:     my $fh;
 1075:     if (!$justcheckdaemons && !$justcheckconnections && !$justreload && !$justiptables) {
 1076: 	$fh=&start_logging();
 1077: 
 1078: 	&log_machine_info($fh);
 1079: 	&clean_tmp($fh);
 1080: 	&clean_lonIDs($fh);
 1081:         &clean_webDAV_sessionIDs($fh);
 1082: 	&check_httpd_logs($fh);
 1083: 	&rotate_lonnet_logs($fh);
 1084: 	&rotate_other_logs($fh);
 1085:     }
 1086:     if (!$justcheckconnections && !$justreload && !$justiptables) {
 1087: 	&checkon_daemon($fh,'lonmemcached',40000);
 1088: 	&checkon_daemon($fh,'lonsql',200000);
 1089: 	if ( &checkon_daemon($fh,'lond',40000,'USR1') eq 'running') {
 1090: 	    &checkon_daemon($fh,'lond',40000,'USR2');
 1091: 	}
 1092: 	&checkon_daemon($fh,'lonc',40000,'USR1');
 1093:         &checkon_daemon($fh,'lonmaxima',40000);
 1094:         &checkon_daemon($fh,'lonr',40000);
 1095:     }
 1096:     if ($justreload) {
 1097: 	&checkon_daemon($fh,'lond',40000,'USR2');
 1098: 	&checkon_daemon($fh,'lonc',40000,'USR2');
 1099:     }
 1100:     if ($justcheckconnections) {
 1101: 	&test_connections($fh);
 1102:     }
 1103:     if (!$justcheckdaemons && !$justcheckconnections && !$justreload && !$justiptables) {
 1104: 	&check_delayed_msg($fh);
 1105: 	&finish_logging($fh);
 1106: 	&log_simplestatus();
 1107:         &write_loncaparevs();
 1108:         &write_serverhomeIDs();
 1109: 	&write_checksums();
 1110:         &write_hostips();
 1111: 	if ($totalcount>200 && !$noemail) { &send_mail(); }
 1112:     }
 1113: }
 1114: 
 1115: &main();
 1116: 1;
 1117: 

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