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