File:  [LON-CAPA] / loncom / loncron
Revision 1.50: download - view: text, annotated - select for diffs
Tue May 11 21:14:23 2004 UTC (19 years, 11 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- get rid of old 'new' hack for starting using loncnew and use real cmdline arg

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

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