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: #
10: # 7/14,7/15,7/19,7/21,7/22,11/18,
11: # 2/8 Gerd Kortemeyer
12: # 12/23 Gerd Kortemeyer
13: # YEAR=2001
14: # 09/04,09/06,11/26 Gerd Kortemeyer
15:
16: $|=1;
17:
18: use lib '/home/httpd/lib/perl/';
19: use LONCAPA::Configuration;
20:
21: use IO::File;
22: use IO::Socket;
23:
24: # -------------------------------------------------- Non-critical communication
25: sub reply {
26: my ($cmd,$server)=@_;
27: my $peerfile="$perlvar{'lonSockDir'}/$server";
28: my $client=IO::Socket::UNIX->new(Peer =>"$peerfile",
29: Type => SOCK_STREAM,
30: Timeout => 10)
31: or return "con_lost";
32: print $client "$cmd\n";
33: my $answer=<$client>;
34: chomp($answer);
35: if (!$answer) { $answer="con_lost"; }
36: return $answer;
37: }
38:
39: # --------------------------------------------------------- Output error status
40:
41: sub errout {
42: my $fh=shift;
43: print $fh (<<ENDERROUT);
44: <p><table border=2 bgcolor="#CCCCCC">
45: <tr><td>Notices</td><td>$notices</td></tr>
46: <tr><td>Warnings</td><td>$warnings</td></tr>
47: <tr><td>Errors</td><td>$errors</td></tr>
48: </table><p><a href="#top">Top</a><p>
49: ENDERROUT
50: }
51:
52: # ================================================================ Main Program
53:
54: # --------------------------------- Read loncapa_apache.conf and loncapa.conf
55: my $perlvarref=LONCAPA::Configuration::read_conf('loncapa.conf');
56: %perlvar=%{$perlvarref};
57: undef $perlvarref;
58: delete $perlvar{'lonReceipt'}; # remove since sensitive and not needed
59: delete $perlvar{'lonSqlAccess'}; # remove since sensitive and not needed
60:
61: # --------------------------------------- Make sure that LON-CAPA is configured
62: # I only test for one thing here (lonHostID). This is just a safeguard.
63: if ('{[[[[lonHostID]]]]}' eq $perlvar{'lonHostID'}) {
64: print("Unconfigured machine.\n");
65: $emailto=$perlvar{'lonSysEMail'};
66: $hostname=`/bin/hostname`;
67: chop $hostname;
68: $hostname=~s/[^\w\.]//g; # make sure is safe to pass through shell
69: $subj="LON: Unconfigured machine $hostname";
70: system("echo 'Unconfigured machine $hostname.' |\
71: mailto $emailto -s '$subj' > /dev/null");
72: exit 1;
73: }
74:
75: # ----------------------------- Make sure this process is running from user=www
76: my $wwwid=getpwnam('www');
77: if ($wwwid!=$<) {
78: print("User ID mismatch. This program must be run as user 'www'\n");
79: $emailto="$perlvar{'lonAdmEMail'},$perlvar{'lonSysEMail'}";
80: $subj="LON: $perlvar{'lonHostID'} User ID mismatch";
81: system("echo 'User ID mismatch. loncron must be run as user www.' |\
82: mailto $emailto -s '$subj' > /dev/null");
83: exit 1;
84: }
85:
86: # ------------------------------------------------------------- Read hosts file
87: {
88: my $config=IO::File->new("$perlvar{'lonTabDir'}/hosts.tab");
89:
90: while (my $configline=<$config>) {
91: my ($id,$domain,$role,$name,$ip,$domdescr)=split(/:/,$configline);
92: if ($id && $domain && $role && $name && $ip) {
93: $hostname{$id}=$name;
94: $hostdom{$id}=$domain;
95: $hostip{$id}=$ip;
96: $hostrole{$id}=$role;
97: if ($domdescr) { $domaindescription{$domain}=$domdescr; }
98: if (($role eq 'library') && ($id ne $perlvar{'lonHostID'})) {
99: $libserv{$id}=$name;
100: }
101: } else {
102: if ($configline) {
103: # &logthis("Skipping hosts.tab line -$configline-");
104: }
105: }
106: }
107: }
108:
109: # ------------------------------------------------------ Read spare server file
110: {
111: my $config=IO::File->new("$perlvar{'lonTabDir'}/spare.tab");
112:
113: while (my $configline=<$config>) {
114: chomp($configline);
115: if (($configline) && ($configline ne $perlvar{'lonHostID'})) {
116: $spareid{$configline}=1;
117: }
118: }
119: }
120:
121: # ---------------------------------------------------------------- Start report
122:
123: $statusdir="/home/httpd/html/lon-status";
124:
125: $errors=0;
126: $warnings=0;
127: $notices=0;
128:
129: $now=time;
130: $date=localtime($now);
131:
132: {
133: my $fh=IO::File->new(">$statusdir/newstatus.html");
134:
135: print $fh (<<ENDHEADERS);
136: <html>
137: <head>
138: <title>LON Status Report $perlvar{'lonHostID'}</title>
139: </head>
140: <body bgcolor="#AAAAAA">
141: <a name="top">
142: <h1>LON Status Report $perlvar{'lonHostID'}</h1>
143: <h2>$date ($now)</h2>
144: <ol>
145: <li><a href="#configuration">Configuration</a>
146: <li><a href="#machine">Machine Information</a>
147: <li><a href="#tmp">Temporary Files</a>
148: <li><a href="#tokens">Session Tokens</a>
149: <li><a href="#httpd">httpd</a>
150: <li><a href="#lonsql">lonsql</a>
151: <li><a href="#lond">lond</a>
152: <li><a href="#lonc">lonc</a>
153: <li><a href="#lonhttpd">lonhttpd</a>
154: <li><a href="#lonnet">lonnet</a>
155: <li><a href="#connections">Connections</a>
156: <li><a href="#delayed">Delayed Messages</a>
157: <li><a href="#errcount">Error Count</a>
158: </ol>
159: <hr>
160: <a name="configuration">
161: <h2>Configuration</h2>
162: <h3>PerlVars</h3>
163: <table border=2>
164: ENDHEADERS
165:
166: foreach $varname (sort(keys(%perlvar))) {
167: print $fh "<tr><td>$varname</td><td>$perlvar{$varname}</td></tr>\n";
168: }
169: print $fh "</table><h3>Hosts</h3><table border=2>";
170: foreach $id (sort(keys(%hostname))) {
171: print $fh
172: "<tr><td>$id</td><td>$hostdom{$id}</td><td>$hostrole{$id}</td>";
173: print $fh "<td>$hostname{$id}</td><td>$hostip{$id}</td></tr>\n";
174: }
175: print $fh "</table><h3>Spare Hosts</h3><ol>";
176: foreach $id (sort(keys(%spareid))) {
177: print $fh "<li>$id\n";
178: }
179:
180: print $fh "</ol>\n";
181:
182: # --------------------------------------------------------------------- Machine
183:
184: print $fh '<hr><a name="machine"><h2>Machine Information</h2>';
185: print $fh "<h3>loadavg</h3>";
186:
187: open (LOADAVGH,"/proc/loadavg");
188: $loadavg=<LOADAVGH>;
189: close (LOADAVGH);
190:
191: print $fh "<tt>$loadavg</tt>";
192:
193: @parts=split(/\s+/,$loadavg);
194: if ($parts[1]>4.0) {
195: $errors++;
196: } elsif ($parts[1]>2.0) {
197: $warnings++;
198: } elsif ($parts[1]>1.0) {
199: $notices++;
200: }
201:
202: print $fh "<h3>df</h3>";
203: print $fh "<pre>";
204:
205: open (DFH,"df|");
206: while ($line=<DFH>) {
207: print $fh "$line";
208: @parts=split(/\s+/,$line);
209: $usage=$parts[4];
210: $usage=~s/\W//g;
211: if ($usage>90) {
212: $warnings++;
213: $notices++;
214: } elsif ($usage>80) {
215: $warnings++;
216: } elsif ($usage>60) {
217: $notices++;
218: }
219: if ($usage>95) { $warnings++; $warnings++ }
220: }
221: close (DFH);
222: print $fh "</pre>";
223:
224:
225: print $fh "<h3>ps</h3>";
226: print $fh "<pre>";
227: $psproc=0;
228:
229: open (PSH,"ps -aux|");
230: while ($line=<PSH>) {
231: print $fh "$line";
232: $psproc++;
233: }
234: close (PSH);
235: print $fh "</pre>";
236:
237: if ($psproc>200) { $notices++; }
238: if ($psproc>250) { $notices++; }
239:
240: &errout($fh);
241:
242: # --------------------------------------------------------------- clean out tmp
243: print $fh '<hr><a name="tmp"><h2>Temporary Files</h2>';
244: $cleaned=0;
245: $old=0;
246: while ($fname=<$perlvar{'lonDaemons'}/tmp/*>) {
247: my ($dev,$ino,$mode,$nlink,
248: $uid,$gid,$rdev,$size,
249: $atime,$mtime,$ctime,
250: $blksize,$blocks)=stat($fname);
251: $now=time;
252: $since=$now-$mtime;
253: if ($since>$perlvar{'lonExpire'}) {
254: $line='';
255: if (open(PROBE,$fname)) {
256: $line=<PROBE>;
257: close(PROBE);
258: }
259: unless ($line=~/^CHECKOUTTOKEN\&/) {
260: $cleaned++;
261: unlink("$fname");
262: } else {
263: if ($since>365*$perlvar{'lonExpire'}) {
264: $cleaned++;
265: unlink("$fname");
266: } else { $old++; }
267: }
268: }
269:
270: }
271: print $fh "Cleaned up ".$cleaned." files (".$old." old checkout tokens).";
272:
273: # ------------------------------------------------------------ clean out lonIDs
274: print $fh '<hr><a name="tokens"><h2>Session Tokens</h2>';
275: $cleaned=0;
276: $active=0;
277: while ($fname=<$perlvar{'lonIDsDir'}/*>) {
278: my ($dev,$ino,$mode,$nlink,
279: $uid,$gid,$rdev,$size,
280: $atime,$mtime,$ctime,
281: $blksize,$blocks)=stat($fname);
282: $now=time;
283: $since=$now-$mtime;
284: if ($since>$perlvar{'lonExpire'}) {
285: $cleaned++;
286: print $fh "Unlinking $fname<br>";
287: unlink("$fname");
288: } else {
289: $active++;
290: }
291:
292: }
293: print $fh "<p>Cleaned up ".$cleaned." stale session token(s).";
294: print $fh "<h3>$active open session(s)</h3>";
295:
296: # ----------------------------------------------------------------------- httpd
297:
298: print $fh '<hr><a name="httpd"><h2>httpd</h2><h3>Access Log</h3><pre>';
299:
300: open (DFH,"tail -n25 /etc/httpd/logs/access_log|");
301: while ($line=<DFH>) { print $fh "$line" };
302: close (DFH);
303:
304: print $fh "</pre><h3>Error Log</h3><pre>";
305:
306: open (DFH,"tail -n25 /etc/httpd/logs/error_log|");
307: while ($line=<DFH>) {
308: print $fh "$line";
309: if ($line=~/\[error\]/) { $notices++; }
310: };
311: close (DFH);
312: print $fh "</pre>";
313: &errout($fh);
314:
315:
316: # ---------------------------------------------------------------------- lonsql
317:
318: my $restartflag=1;
319: print $fh '<hr><a name="lonsql"><h2>lonsql</h2><h3>Log</h3><pre>';
320: print "lonsql\n";
321: if (-e "$perlvar{'lonDaemons'}/logs/lonsql.log"){
322: open (DFH,"tail -n100 $perlvar{'lonDaemons'}/logs/lonsql.log|");
323: while ($line=<DFH>) {
324: print $fh "$line";
325: if ($line=~/INFO/) { $notices++; }
326: if ($line=~/WARNING/) { $notices++; }
327: if ($line=~/CRITICAL/) { $warnings++; }
328: };
329: close (DFH);
330: }
331: print $fh "</pre>";
332:
333: my $lonsqlfile="$perlvar{'lonDaemons'}/logs/lonsql.pid";
334:
335: $restartflag=1;
336:
337: if (-e $lonsqlfile) {
338: my $lfh=IO::File->new("$lonsqlfile");
339: my $lonsqlpid=<$lfh>;
340: chomp($lonsqlpid);
341: if (kill 0 => $lonsqlpid) {
342: print $fh "<h3>lonsql at pid $lonsqlpid responding</h3>";
343: $restartflag=0;
344: } else {
345: $errors++; $errors++;
346: print $fh "<h3>lonsql at pid $lonsqlpid not responding</h3>";
347: $restartflag=1;
348: print $fh
349: "<h3>Decided to clean up stale .pid file and restart lonsql</h3>";
350: }
351: }
352: if ($restartflag==1) {
353: $errors++;
354: print $fh '<br><font color="red">Killall lonsql: '.
355: system('killall lonsql').' - ';
356: sleep 2;
357: print $fh unlink($lonsqlfile).' - '.
358: system('killall -9 lonsql').
359: '</font><br>';
360: print $fh "<h3>lonsql not running, trying to start</h3>";
361: system(
362: "$perlvar{'lonDaemons'}/lonsql 2>>$perlvar{'lonDaemons'}/logs/lonsql_errors");
363: sleep 2;
364: if (-e $lonsqlfile) {
365: print $fh "Seems like it started ...<p>";
366: my $lfh=IO::File->new("$lonsqlfile");
367: my $lonsqlpid=<$lfh>;
368: chomp($lonsqlpid);
369: sleep 2;
370: if (kill 0 => $lonsqlpid) {
371: print $fh "<h3>lonsql at pid $lonsqlpid responding</h3>";
372: } else {
373: $errors++; $errors++;
374: print $fh "<h3>lonsql at pid $lonsqlpid not responding</h3>";
375: print $fh "Give it one more try ...<p>";
376: system(
377: "$perlvar{'lonDaemons'}/lonsql 2>>$perlvar{'lonDaemons'}/logs/lonsql_errors");
378: sleep 2;
379: }
380: } else {
381: print $fh "Seems like that did not work!<p>";
382: $errors++;
383: }
384: if (-e "$perlvar{'lonDaemons'}/logs/lonsql.log"){
385: print $fh "<p><pre>";
386: open (DFH,"tail -n100 $perlvar{'lonDaemons'}/logs/lonsql.log|");
387: while ($line=<DFH>) {
388: print $fh "$line";
389: if ($line=~/WARNING/) { $notices++; }
390: if ($line=~/CRITICAL/) { $notices++; }
391: };
392: close (DFH);
393: print $fh "</pre>";
394: }
395: }
396:
397: $fname="$perlvar{'lonDaemons'}/logs/lonsql.log";
398:
399: my ($dev,$ino,$mode,$nlink,
400: $uid,$gid,$rdev,$size,
401: $atime,$mtime,$ctime,
402: $blksize,$blocks)=stat($fname);
403:
404: if ($size>200000) {
405: print $fh "Rotating logs ...<p>";
406: rename("$fname.2","$fname.3");
407: rename("$fname.1","$fname.2");
408: rename("$fname","$fname.1");
409: }
410:
411: &errout($fh);
412: # ------------------------------------------------------------------------ lond
413:
414: print $fh '<hr><a name="lond"><h2>lond</h2><h3>Log</h3><pre>';
415: print "lond\n";
416:
417: if (-e "$perlvar{'lonDaemons'}/logs/lond.log"){
418: open (DFH,"tail -n25 $perlvar{'lonDaemons'}/logs/lond.log|");
419: while ($line=<DFH>) {
420: print $fh "$line";
421: if ($line=~/INFO/) { $notices++; }
422: if ($line=~/WARNING/) { $notices++; }
423: if ($line=~/CRITICAL/) { $warnings++; }
424: };
425: close (DFH);
426: }
427: print $fh "</pre>";
428:
429: my $londfile="$perlvar{'lonDaemons'}/logs/lond.pid";
430:
431: $restartflag=1;
432: if (-e $londfile) {
433: my $lfh=IO::File->new("$londfile");
434: my $londpid=<$lfh>;
435: chomp($londpid);
436: if (kill 0 => $londpid) {
437: print $fh "<h3>lond at pid $londpid responding, sending USR1</h3>";
438: kill USR1 => $londpid;
439: $restartflag=0;
440: } else {
441: $errors++;
442: print $fh "<h3>lond at pid $londpid not responding</h3>";
443: $restartflag=1;
444: print $fh
445: "<h3>Decided to clean up stale .pid file and restart lond</h3>";
446: }
447: }
448: if ($restartflag==1) {
449: $errors++;
450: print $fh '<br><font color="red">Killall lond: '.
451: system('killall lond').' - ';
452: sleep 2;
453: print $fh unlink($londfile).' - '.system('killall -9 lond').
454: '</font><br>';
455: print $fh "<h3>lond not running, trying to start</h3>";
456: system(
457: "$perlvar{'lonDaemons'}/lond 2>>$perlvar{'lonDaemons'}/logs/lond_errors");
458: sleep 2;
459: if (-e $londfile) {
460: print $fh "Seems like it started ...<p>";
461: my $lfh=IO::File->new("$londfile");
462: my $londpid=<$lfh>;
463: chomp($londpid);
464: sleep 2;
465: if (kill 0 => $londpid) {
466: print $fh "<h3>lond at pid $londpid responding</h3>";
467: } else {
468: $errors++; $errors++;
469: print $fh "<h3>lond at pid $londpid not responding</h3>";
470: print $fh "Give it one more try ...<p>";
471: system(
472: "$perlvar{'lonDaemons'}/lond 2>>$perlvar{'lonDaemons'}/logs/lond_errors");
473: sleep 2;
474: }
475: } else {
476: print $fh "Seems like that did not work!<p>";
477: $errors++;
478: }
479: if (-e "$perlvar{'lonDaemons'}/logs/lond.log"){
480: print $fh "<p><pre>";
481: open (DFH,"tail -n100 $perlvar{'lonDaemons'}/logs/lond.log|");
482: while ($line=<DFH>) {
483: print $fh "$line";
484: if ($line=~/WARNING/) { $notices++; }
485: if ($line=~/CRITICAL/) { $notices++; }
486: };
487: close (DFH);
488: print $fh "</pre>";
489: }
490: }
491:
492: $fname="$perlvar{'lonDaemons'}/logs/lond.log";
493:
494: my ($dev,$ino,$mode,$nlink,
495: $uid,$gid,$rdev,$size,
496: $atime,$mtime,$ctime,
497: $blksize,$blocks)=stat($fname);
498:
499: if ($size>40000) {
500: print $fh "Rotating logs ...<p>";
501: rename("$fname.2","$fname.3");
502: rename("$fname.1","$fname.2");
503: rename("$fname","$fname.1");
504: }
505:
506: &errout($fh);
507: # ------------------------------------------------------------------------ lonc
508:
509: print $fh '<hr><a name="lonc"><h2>lonc</h2><h3>Log</h3><pre>';
510: print "lonc\n";
511:
512: if (-e "$perlvar{'lonDaemons'}/logs/lonc.log"){
513: open (DFH,"tail -n25 $perlvar{'lonDaemons'}/logs/lonc.log|");
514: while ($line=<DFH>) {
515: print $fh "$line";
516: if ($line=~/INFO/) { $notices++; }
517: if ($line=~/WARNING/) { $notices++; }
518: if ($line=~/CRITICAL/) { $warnings++; }
519: };
520: close (DFH);
521: }
522: print $fh "</pre>";
523:
524: my $loncfile="$perlvar{'lonDaemons'}/logs/lonc.pid";
525:
526: $restartflag=1;
527: if (-e $loncfile) {
528: my $lfh=IO::File->new("$loncfile");
529: my $loncpid=<$lfh>;
530: chomp($loncpid);
531: if (kill 0 => $loncpid) {
532: print $fh "<h3>lonc at pid $loncpid responding, sending USR1</h3>";
533: kill USR1 => $loncpid;
534: $restartflag=0;
535: } else {
536: $errors++;
537: print $fh "<h3>lonc at pid $loncpid not responding</h3>";
538: # Solution: kill parent and children processes, remove .pid and restart
539: $restartflag=1;
540: print $fh
541: "<h3>Decided to clean up stale .pid file and restart lonc</h3>";
542: }
543: }
544: if ($restartflag==1) {
545: $errors++;
546: print $fh '<br><font color="red">Killall lonc: '.
547: system('killall lonc').' - ';
548: sleep 2;
549: print $fh unlink($loncfile).' - '.system('killall -9 lonc').
550: '</font><br>';
551: print $fh "<h3>lonc not running, trying to start</h3>";
552: system(
553: "$perlvar{'lonDaemons'}/lonc 2>>$perlvar{'lonDaemons'}/logs/lonc_errors");
554: sleep 2;
555: if (-e $loncfile) {
556: print $fh "Seems like it started ...<p>";
557: my $lfh=IO::File->new("$loncfile");
558: my $loncpid=<$lfh>;
559: chomp($loncpid);
560: sleep 2;
561: if (kill 0 => $loncpid) {
562: print $fh "<h3>lonc at pid $loncpid responding</h3>";
563: } else {
564: $errors++; $errors++;
565: print $fh "<h3>lonc at pid $loncpid not responding</h3>";
566: print $fh "Give it one more try ...<p>";
567: system(
568: "$perlvar{'lonDaemons'}/lonc 2>>$perlvar{'lonDaemons'}/logs/lonc_errors");
569: sleep 2;
570: }
571: } else {
572: print $fh "Seems like that did not work!<p>";
573: $errors++;
574: }
575: if (-e "$perlvar{'lonDaemons'}/logs/lonc.log") {
576: print $fh "<p><pre>";
577: open (DFH,"tail -n100 $perlvar{'lonDaemons'}/logs/lonc.log|");
578: while ($line=<DFH>) {
579: print $fh "$line";
580: if ($line=~/WARNING/) { $notices++; }
581: if ($line=~/CRITICAL/) { $notices++; }
582: };
583: close (DFH);
584: print $fh "</pre>";
585: }
586: }
587:
588: $fname="$perlvar{'lonDaemons'}/logs/lonc.log";
589:
590: my ($dev,$ino,$mode,$nlink,
591: $uid,$gid,$rdev,$size,
592: $atime,$mtime,$ctime,
593: $blksize,$blocks)=stat($fname);
594:
595: if ($size>40000) {
596: print $fh "Rotating logs ...<p>";
597: rename("$fname.2","$fname.3");
598: rename("$fname.1","$fname.2");
599: rename("$fname","$fname.1");
600: }
601:
602:
603: &errout($fh);
604: # -------------------------------------------------------------------- lonhttpd
605:
606: print $fh '<hr><a name="lonhttpd"><h2>lonhttpd</h2><h3>Log</h3><pre>';
607: print "lonhttpd\n";
608:
609: if (-e "$perlvar{'lonDaemons'}/logs/lonhttpd.log"){
610: open (DFH,"tail -n25 $perlvar{'lonDaemons'}/logs/lonhttpd.log|");
611: while ($line=<DFH>) {
612: print $fh "$line";
613: if ($line=~/INFO/) { $notices++; }
614: if ($line=~/WARNING/) { $notices++; }
615: if ($line=~/CRITICAL/) { $warnings++; }
616: };
617: close (DFH);
618: }
619: print $fh "</pre>";
620:
621: my $lonhttpdfile="$perlvar{'lonDaemons'}/logs/lonhttpd.pid";
622:
623: $restartflag=1;
624: if (-e $lonhttpdfile) {
625: my $lfh=IO::File->new("$lonhttpdfile");
626: my $lonhttpdpid=<$lfh>;
627: chomp($lonhttpdpid);
628: if (kill 0 => $lonhttpdpid) {
629: print $fh "<h3>lonhttpd at pid $lonhttpdpid responding</h3>";
630: $restartflag=0;
631: } else {
632: $errors++;
633: print $fh "<h3>lonhttpd at pid $lonhttpdpid not responding</h3>";
634: # Solution: kill parent and children processes, remove .pid and restart
635: $restartflag=1;
636: print $fh
637: "<h3>Decided to clean up stale .pid file and restart lonhttpd</h3>";
638: }
639: }
640: if ($restartflag==1) {
641: $errors++;
642: print $fh '<br><font color="red">Killall lonhttpd: '.
643: system('killall lonhttpd').' - ';
644: sleep 2;
645: print $fh unlink($lonhttpdfile).' - '.system('killall -9 lonhttpd').
646: '</font><br>';
647: print $fh "<h3>lonhttpd not running, trying to start</h3>";
648: system(
649: "$perlvar{'lonDaemons'}/lonhttpd 2>>$perlvar{'lonDaemons'}/logs/lonhttpd_errors");
650: sleep 2;
651: if (-e $lonhttpdfile) {
652: print $fh "Seems like it started ...<p>";
653: my $lfh=IO::File->new("$lonhttpdfile");
654: my $lonhttpdpid=<$lfh>;
655: chomp($lonhttpdpid);
656: sleep 2;
657: if (kill 0 => $lonhttpdpid) {
658: print $fh "<h3>lonhttpd at pid $lonhttpdpid responding</h3>";
659: } else {
660: $errors++; $errors++;
661: print $fh "<h3>lonhttpd at pid $lonhttpdpid not responding</h3>";
662: print $fh "Give it one more try ...<p>";
663: system(
664: "$perlvar{'lonDaemons'}/lonhttpd 2>>$perlvar{'lonDaemons'}/logs/lonhttpd_errors");
665: sleep 2;
666: }
667: } else {
668: print $fh "Seems like that did not work!<p>";
669: $errors++;
670: }
671: if (-e "$perlvar{'lonDaemons'}/logs/lonhttpd.log") {
672: print $fh "<p><pre>";
673: open (DFH,"tail -n100 $perlvar{'lonDaemons'}/logs/lonhttpd.log|");
674: while ($line=<DFH>) {
675: print $fh "$line";
676: if ($line=~/WARNING/) { $notices++; }
677: if ($line=~/CRITICAL/) { $notices++; }
678: };
679: close (DFH);
680: print $fh "</pre>";
681: }
682: }
683:
684: $fname="$perlvar{'lonDaemons'}/logs/lonhttpd.log";
685:
686: my ($dev,$ino,$mode,$nlink,
687: $uid,$gid,$rdev,$size,
688: $atime,$mtime,$ctime,
689: $blksize,$blocks)=stat($fname);
690:
691: if ($size>40000) {
692: print $fh "Rotating logs ...<p>";
693: rename("$fname.2","$fname.3");
694: rename("$fname.1","$fname.2");
695: rename("$fname","$fname.1");
696: }
697:
698:
699: &errout($fh);
700: # ---------------------------------------------------------------------- lonnet
701:
702: print $fh '<hr><a name="lonnet"><h2>lonnet</h2><h3>Temp Log</h3><pre>';
703: print "lonnet\n";
704: if (-e "$perlvar{'lonDaemons'}/logs/lonnet.log"){
705: open (DFH,"tail -n50 $perlvar{'lonDaemons'}/logs/lonnet.log|");
706: while ($line=<DFH>) {
707: print $fh "$line";
708: };
709: close (DFH);
710: }
711: print $fh "</pre><h3>Perm Log</h3><pre>";
712:
713: if (-e "$perlvar{'lonDaemons'}/logs/lonnet.perm.log") {
714: open(DFH,"tail -n10 $perlvar{'lonDaemons'}/logs/lonnet.perm.log|");
715: while ($line=<DFH>) {
716: print $fh "$line";
717: };
718: close (DFH);
719: } else { print $fh "No perm log\n" }
720:
721: $fname="$perlvar{'lonDaemons'}/logs/lonnet.log";
722:
723: my ($dev,$ino,$mode,$nlink,
724: $uid,$gid,$rdev,$size,
725: $atime,$mtime,$ctime,
726: $blksize,$blocks)=stat($fname);
727:
728: if ($size>40000) {
729: print $fh "Rotating logs ...<p>";
730: rename("$fname.2","$fname.3");
731: rename("$fname.1","$fname.2");
732: rename("$fname","$fname.1");
733: }
734:
735: print $fh "</pre>";
736: &errout($fh);
737: # ----------------------------------------------------------------- Connections
738:
739: print $fh '<hr><a name="connections"><h2>Connections</h2>';
740:
741: print $fh "<table border=2>";
742: foreach $tryserver (sort(keys(%hostname))) {
743:
744: $answer=reply("pong",$tryserver);
745: if ($answer eq "$tryserver:$perlvar{'lonHostID'}") {
746: $result="<b>ok</b>";
747: } else {
748: $result=$answer;
749: $warnings++;
750: if ($answer eq 'con_lost') { $warnings++; }
751: }
752: print $fh "<tr><td>$tryserver</td><td>$result</td></tr>\n";
753:
754: }
755: print $fh "</table>";
756:
757: &errout($fh);
758: # ------------------------------------------------------------ Delayed messages
759:
760: print $fh '<hr><a name="delayed"><h2>Delayed Messages</h2>';
761: print "buffers\n";
762:
763: print $fh '<h3>Scanning Permanent Log</h3>';
764:
765: $unsend=0;
766: {
767: my $dfh=IO::File->new("$perlvar{'lonDaemons'}/logs/lonnet.perm.log");
768: while ($line=<$dfh>) {
769: ($time,$sdf,$dserv,$dcmd)=split(/:/,$line);
770: if ($sdf eq 'F') {
771: $local=localtime($time);
772: print "<b>Failed: $time, $dserv, $dcmd</b><br>";
773: $warnings++;
774: }
775: if ($sdf eq 'S') { $unsend--; }
776: if ($sdf eq 'D') { $unsend++; }
777: }
778: }
779: print $fh "Total unsend messages: <b>$unsend</b><p>\n";
780: $warnings=$warnings+5*$unsend;
781:
782: print $fh "<h3>Outgoing Buffer</h3>";
783:
784: open (DFH,"ls -lF $perlvar{'lonSockDir'}/delayed|");
785: while ($line=<DFH>) {
786: print $fh "$line<br>";
787: };
788: close (DFH);
789:
790: # ------------------------------------------------------------------------- End
791: print $fh "<a name=errcount>\n";
792: $totalcount=$notices+4*$warnings+100*$errors;
793: &errout($fh);
794: print $fh "<h1>Total Error Count: $totalcount</h1>";
795: $now=time;
796: $date=localtime($now);
797: print $fh "<hr>$date ($now)</body></html>\n";
798: print "writing done\n";
799: }
800:
801: rename ("$statusdir/newstatus.html","$statusdir/index.html");
802:
803: if ($totalcount>200) {
804: print "mailing\n";
805: $emailto="$perlvar{'lonAdmEMail'}";
806: if ($totalcount>600) {
807: $emailto.=",$perlvar{'lonSysEMail'}";
808: }
809: $subj="LON: $perlvar{'lonHostID'} E:$errors W:$warnings N:$notices";
810: system(
811: "metasend -b -t $emailto -s '$subj' -f $statusdir/index.html -m text/html");
812: }
813: 1;
814:
815:
816:
817:
818:
819:
820:
821:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>