File:  [LON-CAPA] / loncom / loncron
Revision 1.104: download - view: text, annotated - select for diffs
Tue Feb 28 05:42:06 2017 UTC (7 years, 1 month ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Use of LON-CAPA SSL certificates to create secure channel for exchange of
  encryption key between LON-CAPA nodes can be set to: "no", "yes", "req"
  (i.e., required) separately for outbound (i.e., lonc) and inbound connections
  (i.e., lond) in domain config (default domain only on a multi-domain server).
- Can differentiate between connections between nodes in same domain, nodes
  in same "internet" domain. and nodes in neither.
- Supercedes use of loncAllowInsecure and londAllowInsecure from loncapa.conf
  on each node.
- Run /home/httpd/perl/loncron --justreload (as www) after changing domain config

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

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