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