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