Annotation of loncom/loncron, revision 1.104
1.1 albertel 1: #!/usr/bin/perl
2:
1.47 albertel 3: # Housekeeping program, started by cron, loncontrol and loncron.pl
4: #
1.104 ! raeburn 5: # $Id: loncron,v 1.103 2015/09/20 18:31:21 raeburn Exp $
1.47 albertel 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/
1.1 albertel 28: #
1.24 www 29:
30: $|=1;
1.48 albertel 31: use strict;
1.1 albertel 32:
1.26 harris41 33: use lib '/home/httpd/lib/perl/';
34: use LONCAPA::Configuration;
1.96 raeburn 35: use LONCAPA::Checksumming;
1.89 raeburn 36: use LONCAPA;
1.72 albertel 37: use Apache::lonnet;
1.79 raeburn 38: use Apache::loncommon;
1.26 harris41 39:
1.1 albertel 40: use IO::File;
41: use IO::Socket;
1.48 albertel 42: use HTML::Entities;
1.49 albertel 43: use Getopt::Long;
1.104 ! raeburn 44: use GDBM_File;
! 45: use Storable qw(thaw);
1.46 albertel 46: #globals
47: use vars qw (%perlvar %simplestatus $errors $warnings $notices $totalcount);
48:
49: my $statusdir="/home/httpd/html/lon-status";
50:
1.1 albertel 51:
52: # --------------------------------------------------------- Output error status
53:
1.46 albertel 54: sub log {
55: my $fh=shift;
56: if ($fh) { print $fh @_ }
57: }
58:
1.1 albertel 59: sub errout {
60: my $fh=shift;
1.46 albertel 61: &log($fh,(<<ENDERROUT));
1.48 albertel 62: <table border="2" bgcolor="#CCCCCC">
1.1 albertel 63: <tr><td>Notices</td><td>$notices</td></tr>
64: <tr><td>Warnings</td><td>$warnings</td></tr>
65: <tr><td>Errors</td><td>$errors</td></tr>
1.48 albertel 66: </table><p><a href="#top">Top</a></p>
1.1 albertel 67: ENDERROUT
68: }
69:
1.73 albertel 70: sub rotate_logfile {
71: my ($file,$fh,$description) = @_;
72: my $size=(stat($file))[7];
73: if ($size>40000) {
74: &log($fh,"<p>Rotating $description ...</p>");
75: rename("$file.2","$file.3");
76: rename("$file.1","$file.2");
77: rename("$file","$file.1");
78: }
79: }
80:
1.42 albertel 81: sub start_daemon {
1.50 albertel 82: my ($fh,$daemon,$pidfile,$args) = @_;
1.44 albertel 83: my $progname=$daemon;
1.71 albertel 84: if ($daemon eq 'lonc') {
1.44 albertel 85: $progname='loncnew';
86: }
1.51 albertel 87: my $error_fname="$perlvar{'lonDaemons'}/logs/${daemon}_errors";
1.73 albertel 88: &rotate_logfile($error_fname,$fh,'error logs');
1.74 albertel 89: if ($daemon eq 'lonc') {
90: &clean_sockets($fh);
91: }
1.51 albertel 92: system("$perlvar{'lonDaemons'}/$progname 2>$perlvar{'lonDaemons'}/logs/${daemon}_errors");
1.60 albertel 93: sleep 1;
1.42 albertel 94: if (-e $pidfile) {
1.48 albertel 95: &log($fh,"<p>Seems like it started ...</p>");
1.42 albertel 96: my $lfh=IO::File->new("$pidfile");
97: my $daemonpid=<$lfh>;
98: chomp($daemonpid);
1.62 albertel 99: if ($daemonpid =~ /^\d+$/ && kill 0 => $daemonpid) {
1.42 albertel 100: return 1;
101: } else {
102: return 0;
103: }
104: }
1.48 albertel 105: &log($fh,"<p>Seems like that did not work!</p>");
1.42 albertel 106: $errors++;
107: return 0;
108: }
109:
110: sub checkon_daemon {
1.59 albertel 111: my ($fh,$daemon,$maxsize,$send,$args)=@_;
1.42 albertel 112:
1.63 albertel 113: my $result;
1.48 albertel 114: &log($fh,'<hr /><a name="'.$daemon.'" /><h2>'.$daemon.'</h2><h3>Log</h3><p style="white-space: pre;"><tt>');
1.57 albertel 115: printf("%-15s ",$daemon);
1.42 albertel 116: if (-e "$perlvar{'lonDaemons'}/logs/$daemon.log"){
117: open (DFH,"tail -n25 $perlvar{'lonDaemons'}/logs/$daemon.log|");
1.46 albertel 118: while (my $line=<DFH>) {
119: &log($fh,"$line");
1.42 albertel 120: if ($line=~/INFO/) { $notices++; }
121: if ($line=~/WARNING/) { $notices++; }
122: if ($line=~/CRITICAL/) { $warnings++; }
123: };
124: close (DFH);
125: }
1.48 albertel 126: &log($fh,"</tt></p>");
1.42 albertel 127:
128: my $pidfile="$perlvar{'lonDaemons'}/logs/$daemon.pid";
129:
130: my $restartflag=1;
1.46 albertel 131: my $daemonpid;
1.42 albertel 132: if (-e $pidfile) {
133: my $lfh=IO::File->new("$pidfile");
1.46 albertel 134: $daemonpid=<$lfh>;
1.42 albertel 135: chomp($daemonpid);
1.62 albertel 136: if ($daemonpid =~ /^\d+$/ && kill 0 => $daemonpid) {
1.46 albertel 137: &log($fh,"<h3>$daemon at pid $daemonpid responding");
1.59 albertel 138: if ($send) { &log($fh,", sending $send"); }
1.46 albertel 139: &log($fh,"</h3>");
1.59 albertel 140: if ($send eq 'USR1') { kill USR1 => $daemonpid; }
141: if ($send eq 'USR2') { kill USR2 => $daemonpid; }
1.42 albertel 142: $restartflag=0;
1.59 albertel 143: if ($send eq 'USR2') {
1.63 albertel 144: $result = 'reloaded';
1.59 albertel 145: print "reloaded\n";
146: } else {
1.63 albertel 147: $result = 'running';
1.59 albertel 148: print "running\n";
149: }
1.42 albertel 150: } else {
151: $errors++;
1.46 albertel 152: &log($fh,"<h3>$daemon at pid $daemonpid not responding</h3>");
1.42 albertel 153: $restartflag=1;
1.46 albertel 154: &log($fh,"<h3>Decided to clean up stale .pid file and restart $daemon</h3>");
1.42 albertel 155: }
156: }
157: if ($restartflag==1) {
158: $simplestatus{$daemon}='off';
159: $errors++;
1.57 albertel 160: my $kadaemon=$daemon;
161: if ($kadaemon eq 'lonmemcached') { $kadaemon='memcached'; }
1.101 raeburn 162: &log($fh,'<br /><font color="red">Killall '.$daemon.': '.
1.57 albertel 163: `killall $kadaemon 2>&1`.' - ');
1.60 albertel 164: sleep 1;
1.46 albertel 165: &log($fh,unlink($pidfile).' - '.
1.57 albertel 166: `killall -9 $kadaemon 2>&1`.
1.101 raeburn 167: '</font><br />');
1.46 albertel 168: &log($fh,"<h3>$daemon not running, trying to start</h3>");
1.42 albertel 169:
1.50 albertel 170: if (&start_daemon($fh,$daemon,$pidfile,$args)) {
1.46 albertel 171: &log($fh,"<h3>$daemon at pid $daemonpid responding</h3>");
1.42 albertel 172: $simplestatus{$daemon}='restarted';
1.63 albertel 173: $result = 'started';
1.42 albertel 174: print "started\n";
175: } else {
176: $errors++;
1.46 albertel 177: &log($fh,"<h3>$daemon at pid $daemonpid not responding</h3>");
1.48 albertel 178: &log($fh,"<p>Give it one more try ...</p>");
1.42 albertel 179: print " ";
1.50 albertel 180: if (&start_daemon($fh,$daemon,$pidfile,$args)) {
1.46 albertel 181: &log($fh,"<h3>$daemon at pid $daemonpid responding</h3>");
1.42 albertel 182: $simplestatus{$daemon}='restarted';
1.63 albertel 183: $result = 'started';
1.42 albertel 184: print "started\n";
185: } else {
1.63 albertel 186: $result = 'failed';
1.42 albertel 187: print " failed\n";
188: $simplestatus{$daemon}='failed';
189: $errors++; $errors++;
1.46 albertel 190: &log($fh,"<h3>$daemon at pid $daemonpid not responding</h3>");
1.48 albertel 191: &log($fh,"<p>Unable to start $daemon</p>");
1.42 albertel 192: }
193: }
194:
195: if (-e "$perlvar{'lonDaemons'}/logs/$daemon.log"){
1.46 albertel 196: &log($fh,"<p><pre>");
1.42 albertel 197: open (DFH,"tail -n100 $perlvar{'lonDaemons'}/logs/$daemon.log|");
1.46 albertel 198: while (my $line=<DFH>) {
199: &log($fh,"$line");
1.42 albertel 200: if ($line=~/WARNING/) { $notices++; }
201: if ($line=~/CRITICAL/) { $notices++; }
202: };
203: close (DFH);
1.48 albertel 204: &log($fh,"</pre></p>");
1.42 albertel 205: }
206: }
207:
1.46 albertel 208: my $fname="$perlvar{'lonDaemons'}/logs/$daemon.log";
1.73 albertel 209: &rotate_logfile($fname,$fh,'logs');
1.42 albertel 210:
211: &errout($fh);
1.63 albertel 212: return $result;
1.42 albertel 213: }
1.1 albertel 214:
1.46 albertel 215: # --------------------------------------------------------------------- Machine
216: sub log_machine_info {
217: my ($fh)=@_;
1.48 albertel 218: &log($fh,'<hr /><a name="machine" /><h2>Machine Information</h2>');
1.46 albertel 219: &log($fh,"<h3>loadavg</h3>");
220:
221: open (LOADAVGH,"/proc/loadavg");
222: my $loadavg=<LOADAVGH>;
223: close (LOADAVGH);
224:
225: &log($fh,"<tt>$loadavg</tt>");
226:
227: my @parts=split(/\s+/,$loadavg);
228: if ($parts[1]>4.0) {
229: $errors++;
230: } elsif ($parts[1]>2.0) {
231: $warnings++;
232: } elsif ($parts[1]>1.0) {
233: $notices++;
234: }
1.13 harris41 235:
1.46 albertel 236: &log($fh,"<h3>df</h3>");
237: &log($fh,"<pre>");
1.14 harris41 238:
1.46 albertel 239: open (DFH,"df|");
240: while (my $line=<DFH>) {
1.48 albertel 241: &log($fh,&encode_entities($line,'<>&"'));
1.46 albertel 242: @parts=split(/\s+/,$line);
243: my $usage=$parts[4];
244: $usage=~s/\W//g;
245: if ($usage>90) {
246: $warnings++;
247: $notices++;
248: } elsif ($usage>80) {
249: $warnings++;
250: } elsif ($usage>60) {
251: $notices++;
1.31 albertel 252: }
1.46 albertel 253: if ($usage>95) { $warnings++; $warnings++; $simplestatus{'diskfull'}++; }
1.1 albertel 254: }
1.46 albertel 255: close (DFH);
256: &log($fh,"</pre>");
1.1 albertel 257:
258:
1.46 albertel 259: &log($fh,"<h3>ps</h3>");
260: &log($fh,"<pre>");
261: my $psproc=0;
1.1 albertel 262:
1.53 albertel 263: open (PSH,"ps aux --cols 140 |");
1.46 albertel 264: while (my $line=<PSH>) {
1.48 albertel 265: &log($fh,&encode_entities($line,'<>&"'));
1.46 albertel 266: $psproc++;
267: }
268: close (PSH);
269: &log($fh,"</pre>");
1.1 albertel 270:
1.46 albertel 271: if ($psproc>200) { $notices++; }
272: if ($psproc>250) { $notices++; }
1.1 albertel 273:
1.61 albertel 274: &log($fh,"<h3>distprobe</h3>");
275: &log($fh,"<pre>");
1.98 raeburn 276: &log($fh,&encode_entities(&LONCAPA::distro(),'<>&"'));
1.61 albertel 277: &log($fh,"</pre>");
278:
1.46 albertel 279: &errout($fh);
280: }
1.1 albertel 281:
1.46 albertel 282: sub start_logging {
1.43 albertel 283: my $fh=IO::File->new(">$statusdir/newstatus.html");
284: my %simplestatus=();
1.46 albertel 285: my $now=time;
286: my $date=localtime($now);
1.43 albertel 287:
1.46 albertel 288:
289: &log($fh,(<<ENDHEADERS));
1.101 raeburn 290: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
291: <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
1.1 albertel 292: <head>
293: <title>LON Status Report $perlvar{'lonHostID'}</title>
1.101 raeburn 294: <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
1.1 albertel 295: </head>
1.3 www 296: <body bgcolor="#AAAAAA">
1.48 albertel 297: <a name="top" />
1.1 albertel 298: <h1>LON Status Report $perlvar{'lonHostID'}</h1>
299: <h2>$date ($now)</h2>
300: <ol>
1.48 albertel 301: <li><a href="#configuration">Configuration</a></li>
302: <li><a href="#machine">Machine Information</a></li>
303: <li><a href="#tmp">Temporary Files</a></li>
304: <li><a href="#tokens">Session Tokens</a></li>
1.102 raeburn 305: <li><a href="#webdav">WebDAV Session Tokens</a></li>
1.48 albertel 306: <li><a href="#httpd">httpd</a></li>
307: <li><a href="#lonsql">lonsql</a></li>
308: <li><a href="#lond">lond</a></li>
309: <li><a href="#lonc">lonc</a></li>
310: <li><a href="#lonnet">lonnet</a></li>
311: <li><a href="#connections">Connections</a></li>
312: <li><a href="#delayed">Delayed Messages</a></li>
313: <li><a href="#errcount">Error Count</a></li>
1.1 albertel 314: </ol>
1.48 albertel 315: <hr />
316: <a name="configuration" />
1.1 albertel 317: <h2>Configuration</h2>
318: <h3>PerlVars</h3>
1.48 albertel 319: <table border="2">
1.1 albertel 320: ENDHEADERS
321:
1.46 albertel 322: foreach my $varname (sort(keys(%perlvar))) {
1.48 albertel 323: &log($fh,"<tr><td>$varname</td><td>".
324: &encode_entities($perlvar{$varname},'<>&"')."</td></tr>\n");
1.43 albertel 325: }
1.48 albertel 326: &log($fh,"</table><h3>Hosts</h3><table border='2'>");
1.72 albertel 327: my %hostname = &Apache::lonnet::all_hostnames();
328: foreach my $id (sort(keys(%hostname))) {
329: my $role = (&Apache::lonnet::is_library($id) ? 'library'
330: : 'access');
1.46 albertel 331: &log($fh,
1.72 albertel 332: "<tr><td>$id</td><td>".&Apache::lonnet::host_domain($id).
333: "</td><td>".$role.
334: "</td><td>".&Apache::lonnet::hostname($id)."</td></tr>\n");
335: }
1.101 raeburn 336: &log($fh,"</table><h3>Spare Hosts</h3>");
337: if (keys(%Apache::lonnet::spareid) > 0) {
338: &log($fh,"<ul>");
339: foreach my $type (sort(keys(%Apache::lonnet::spareid))) {
340: &log($fh,"<li>$type\n<ol>");
341: foreach my $id (@{ $Apache::lonnet::spareid{$type} }) {
342: &log($fh,"<li>$id</li>\n");
343: }
344: &log($fh,"</ol>\n</li>\n");
345: }
346: &log($fh,"</ul>\n");
347: } else {
348: &log($fh,"No spare hosts specified<br />\n");
1.43 albertel 349: }
1.46 albertel 350: return $fh;
351: }
1.11 www 352:
353: # --------------------------------------------------------------- clean out tmp
1.46 albertel 354: sub clean_tmp {
355: my ($fh)=@_;
1.48 albertel 356: &log($fh,'<hr /><a name="tmp" /><h2>Temporary Files</h2>');
1.82 raeburn 357: my ($cleaned,$old,$removed) = (0,0,0);
358: my %errors = (
359: dir => [],
360: file => [],
361: failopen => [],
362: );
363: my %error_titles = (
364: dir => 'failed to remove empty directory:',
365: file => 'failed to unlike stale file',
366: failopen => 'failed to open file or directory'
367: );
368: ($cleaned,$old,$removed) = &recursive_clean_tmp('',$cleaned,$old,$removed,\%errors);
369: &log($fh,"Cleaned up: ".$cleaned." files; removed: $removed empty directories; (found: $old old checkout tokens)");
370: foreach my $key (sort(keys(%errors))) {
371: if (ref($errors{$key}) eq 'ARRAY') {
372: if (@{$errors{$key}} > 0) {
373: &log($fh,"Error during cleanup ($error_titles{$key}):<ul><li>".
374: join('</li><li><tt>',@{$errors{$key}}).'</tt></li></ul><br />');
375: }
376: }
377: }
378: }
379:
380: sub recursive_clean_tmp {
381: my ($subdir,$cleaned,$old,$removed,$errors) = @_;
382: my $base = "$perlvar{'lonDaemons'}/tmp";
383: my $path = $base;
384: next if ($subdir =~ m{\.\./});
385: next unless (ref($errors) eq 'HASH');
386: unless ($subdir eq '') {
387: $path .= '/'.$subdir;
388: }
389: if (opendir(my $dh,"$path")) {
390: while (my $file = readdir($dh)) {
391: next if ($file =~ /^\.\.?$/);
392: my $fname = "$path/$file";
393: if (-d $fname) {
394: my $innerdir;
395: if ($subdir eq '') {
396: $innerdir = $file;
397: } else {
398: $innerdir = $subdir.'/'.$file;
399: }
400: ($cleaned,$old,$removed) =
401: &recursive_clean_tmp($innerdir,$cleaned,$old,$removed,$errors);
402: my @doms = &Apache::lonnet::current_machine_domains();
403:
404: if (open(my $dirhandle,$fname)) {
405: unless (($innerdir eq 'helprequests') ||
406: (($innerdir =~ /^addcourse/) && ($innerdir !~ m{/\d+$}))) {
407: my @contents = grep {!/^\.\.?$/} readdir($dirhandle);
408: join('&&',@contents)."\n";
409: if (scalar(grep {!/^\.\.?$/} readdir($dirhandle)) == 0) {
410: closedir($dirhandle);
411: if ($fname =~ m{^\Q$perlvar{'lonDaemons'}\E/tmp/}) {
412: if (rmdir($fname)) {
413: $removed ++;
414: } elsif (ref($errors->{dir}) eq 'ARRAY') {
415: push(@{$errors->{dir}},$fname);
416: }
417: }
418: }
419: } else {
420: closedir($dirhandle);
421: }
422: }
423: } else {
424: my ($dev,$ino,$mode,$nlink,
425: $uid,$gid,$rdev,$size,
426: $atime,$mtime,$ctime,
427: $blksize,$blocks)=stat($fname);
428: my $now=time;
429: my $since=$now-$mtime;
430: if ($since>$perlvar{'lonExpire'}) {
431: if ($subdir eq '') {
432: my $line='';
433: if ($fname =~ /\.db$/) {
434: if (unlink($fname)) {
435: $cleaned++;
436: } elsif (ref($errors->{file}) eq 'ARRAY') {
437: push(@{$errors->{file}},$fname);
438: }
439: } elsif (open(PROBE,$fname)) {
440: my $line='';
441: $line=<PROBE>;
442: close(PROBE);
443: if ($line=~/^CHECKOUTTOKEN\&/) {
444: if ($since>365*$perlvar{'lonExpire'}) {
445: if (unlink($fname)) {
446: $cleaned++;
447: } elsif (ref($errors->{file}) eq 'ARRAY') {
448: push(@{$errors->{file}},$fname);
449: }
450: } else {
451: $old++;
452: }
453: } else {
454: if (unlink($fname)) {
455: $cleaned++;
456: } elsif (ref($errors->{file}) eq 'ARRAY') {
457: push(@{$errors->{file}},$fname);
458: }
459: }
460: } elsif (ref($errors->{failopen}) eq 'ARRAY') {
461: push(@{$errors->{failopen}},$fname);
462: }
463: } else {
464: if (unlink($fname)) {
465: $cleaned++;
466: } elsif (ref($errors->{file}) eq 'ARRAY') {
467: push(@{$errors->{file}},$fname);
468: }
469: }
470: }
471: }
472: }
473: closedir($dh);
474: } elsif (ref($errors->{failopen}) eq 'ARRAY') {
475: push(@{$errors->{failopen}},$path);
1.43 albertel 476: }
1.82 raeburn 477: return ($cleaned,$old,$removed);
1.46 albertel 478: }
1.11 www 479:
480: # ------------------------------------------------------------ clean out lonIDs
1.46 albertel 481: sub clean_lonIDs {
482: my ($fh)=@_;
1.48 albertel 483: &log($fh,'<hr /><a name="tokens" /><h2>Session Tokens</h2>');
1.46 albertel 484: my $cleaned=0;
485: my $active=0;
486: while (my $fname=<$perlvar{'lonIDsDir'}/*>) {
1.43 albertel 487: my ($dev,$ino,$mode,$nlink,
488: $uid,$gid,$rdev,$size,
489: $atime,$mtime,$ctime,
490: $blksize,$blocks)=stat($fname);
1.46 albertel 491: my $now=time;
492: my $since=$now-$mtime;
1.43 albertel 493: if ($since>$perlvar{'lonExpire'}) {
494: $cleaned++;
1.101 raeburn 495: &log($fh,"Unlinking $fname<br />");
1.43 albertel 496: unlink("$fname");
497: } else {
498: $active++;
499: }
1.46 albertel 500: }
1.48 albertel 501: &log($fh,"<p>Cleaned up ".$cleaned." stale session token(s).</p>");
1.46 albertel 502: &log($fh,"<h3>$active open session(s)</h3>");
503: }
1.43 albertel 504:
1.102 raeburn 505: # ------------------------------------------------ clean out webDAV Session IDs
506: sub clean_webDAV_sessionIDs {
507: my ($fh)=@_;
508: if ($perlvar{'lonRole'} eq 'library') {
509: &log($fh,'<hr /><a name="webdav" /><h2>WebDAV Session Tokens</h2>');
510: my $cleaned=0;
511: my $active=0;
512: my $now = time;
513: if (-d $perlvar{'lonDAVsessDir'}) {
514: while (my $fname=<$perlvar{'lonDAVsessDir'}/*>) {
515: my @stats = stat($fname);
516: my $since=$now-$stats[9];
517: if ($since>$perlvar{'lonExpire'}) {
518: $cleaned++;
519: &log($fh,"Unlinking $fname<br />");
520: unlink("$fname");
521: } else {
522: $active++;
523: }
524: }
525: &log($fh,"<p>Cleaned up ".$cleaned." stale webDAV session token(s).</p>");
526: &log($fh,"<h3>$active open webDAV session(s)</h3>");
527: }
528: }
529: }
530:
1.74 albertel 531: # ----------------------------------------------------------- clean out sockets
532: sub clean_sockets {
533: my ($fh)=@_;
534: my $cleaned=0;
535: opendir(SOCKETS,$perlvar{'lonSockDir'});
536: while (my $fname=readdir(SOCKETS)) {
537: next if (-d $fname
1.80 www 538: || $fname=~/(mysqlsock|maximasock|rsock|\Q$perlvar{'lonSockDir'}\E)/);
1.74 albertel 539: $cleaned++;
540: &log($fh,"Unlinking $fname<br />");
541: unlink("/home/httpd/sockets/$fname");
542: }
543: &log($fh,"<p>Cleaned up ".$cleaned." stale sockets.</p>");
544: }
545:
1.11 www 546:
1.1 albertel 547: # ----------------------------------------------------------------------- httpd
1.46 albertel 548: sub check_httpd_logs {
549: my ($fh)=@_;
1.94 raeburn 550: if (open(PIPE,"./lchttpdlogs|")) {
1.93 raeburn 551: while (my $line=<PIPE>) {
552: &log($fh,$line);
553: if ($line=~/\[error\]/) { $notices++; }
554: }
555: close(PIPE);
1.46 albertel 556: }
1.43 albertel 557: &errout($fh);
1.46 albertel 558: }
1.1 albertel 559:
560: # ---------------------------------------------------------------------- lonnet
561:
1.48 albertel 562: sub rotate_lonnet_logs {
1.46 albertel 563: my ($fh)=@_;
1.48 albertel 564: &log($fh,'<hr /><a name="lonnet" /><h2>lonnet</h2><h3>Temp Log</h3><pre>');
1.100 bisitz 565: print "Checking logs.\n";
1.43 albertel 566: if (-e "$perlvar{'lonDaemons'}/logs/lonnet.log"){
567: open (DFH,"tail -n50 $perlvar{'lonDaemons'}/logs/lonnet.log|");
1.46 albertel 568: while (my $line=<DFH>) {
1.48 albertel 569: &log($fh,&encode_entities($line,'<>&"'));
1.46 albertel 570: }
1.43 albertel 571: close (DFH);
572: }
1.46 albertel 573: &log($fh,"</pre><h3>Perm Log</h3><pre>");
1.43 albertel 574:
575: if (-e "$perlvar{'lonDaemons'}/logs/lonnet.perm.log") {
576: open(DFH,"tail -n10 $perlvar{'lonDaemons'}/logs/lonnet.perm.log|");
1.46 albertel 577: while (my $line=<DFH>) {
1.48 albertel 578: &log($fh,&encode_entities($line,'<>&"'));
1.46 albertel 579: }
1.43 albertel 580: close (DFH);
1.46 albertel 581: } else { &log($fh,"No perm log\n") }
1.43 albertel 582:
1.46 albertel 583: my $fname="$perlvar{'lonDaemons'}/logs/lonnet.log";
1.73 albertel 584: &rotate_logfile($fname,$fh,'lonnet log');
1.1 albertel 585:
1.46 albertel 586: &log($fh,"</pre>");
1.43 albertel 587: &errout($fh);
1.46 albertel 588: }
589:
1.73 albertel 590: sub rotate_other_logs {
591: my ($fh) = @_;
1.83 raeburn 592: my %logs = (
593: autoenroll => 'Auto Enroll log',
594: autocreate => 'Create Course log',
595: searchcat => 'Search Cataloguing log',
596: autoupdate => 'Auto Update log',
597: refreshcourseids_db => 'Refresh CourseIDs db log',
598: );
599: foreach my $item (keys(%logs)) {
600: my $fname=$perlvar{'lonDaemons'}.'/logs/'.$item.'.log';
601: &rotate_logfile($fname,$fh,$logs{$item});
602: }
1.73 albertel 603: }
604:
1.43 albertel 605: # ----------------------------------------------------------------- Connections
1.46 albertel 606: sub test_connections {
1.72 albertel 607: my ($fh)=@_;
1.48 albertel 608: &log($fh,'<hr /><a name="connections" /><h2>Connections</h2>');
1.100 bisitz 609: print "Testing connections.\n";
1.48 albertel 610: &log($fh,"<table border='2'>");
1.49 albertel 611: my ($good,$bad)=(0,0);
1.72 albertel 612: my %hostname = &Apache::lonnet::all_hostnames();
613: foreach my $tryserver (sort(keys(%hostname))) {
1.43 albertel 614: print(".");
1.46 albertel 615: my $result;
1.72 albertel 616: my $answer=&Apache::lonnet::reply("ping",$tryserver);
1.43 albertel 617: if ($answer eq "$tryserver:$perlvar{'lonHostID'}") {
618: $result="<b>ok</b>";
1.49 albertel 619: $good++;
1.43 albertel 620: } else {
621: $result=$answer;
622: $warnings++;
1.49 albertel 623: if ($answer eq 'con_lost') {
624: $bad++;
625: $warnings++;
1.50 albertel 626: } else {
627: $good++; #self connection
1.49 albertel 628: }
1.43 albertel 629: }
630: if ($answer =~ /con_lost/) { print(" $tryserver down\n"); }
1.46 albertel 631: &log($fh,"<tr><td>$tryserver</td><td>$result</td></tr>\n");
1.1 albertel 632: }
1.46 albertel 633: &log($fh,"</table>");
1.49 albertel 634: print "\n$good good, $bad bad connections\n";
1.43 albertel 635: &errout($fh);
1.46 albertel 636: }
637:
638:
1.1 albertel 639: # ------------------------------------------------------------ Delayed messages
1.46 albertel 640: sub check_delayed_msg {
1.72 albertel 641: my ($fh)=@_;
1.48 albertel 642: &log($fh,'<hr /><a name="delayed" /><h2>Delayed Messages</h2>');
1.100 bisitz 643: print "Checking buffers.\n";
1.46 albertel 644:
645: &log($fh,'<h3>Scanning Permanent Log</h3>');
1.1 albertel 646:
1.46 albertel 647: my $unsend=0;
1.1 albertel 648:
1.46 albertel 649: my $dfh=IO::File->new("$perlvar{'lonDaemons'}/logs/lonnet.perm.log");
650: while (my $line=<$dfh>) {
651: my ($time,$sdf,$dserv,$dcmd)=split(/:/,$line);
652: if ($sdf eq 'F') {
653: my $local=localtime($time);
1.101 raeburn 654: &log($fh,"<b>Failed: $time, $dserv, $dcmd</b><br />");
1.46 albertel 655: $warnings++;
1.43 albertel 656: }
1.46 albertel 657: if ($sdf eq 'S') { $unsend--; }
658: if ($sdf eq 'D') { $unsend++; }
1.1 albertel 659: }
1.46 albertel 660:
1.48 albertel 661: &log($fh,"<p>Total unsend messages: <b>$unsend</b></p>\n");
1.95 raeburn 662: if ($unsend > 0) {
663: $warnings=$warnings+5*$unsend;
664: }
1.1 albertel 665:
1.43 albertel 666: if ($unsend) { $simplestatus{'unsend'}=$unsend; }
1.48 albertel 667: &log($fh,"<h3>Outgoing Buffer</h3>\n<pre>");
1.68 www 668: # list directory with delayed messages and remember offline servers
669: my %servers=();
1.43 albertel 670: open (DFH,"ls -lF $perlvar{'lonSockDir'}/delayed|");
1.68 www 671: while (my $line=<DFH>) {
672: my ($server)=($line=~/\.(\w+)$/);
673: if ($server) { $servers{$server}=1; }
1.48 albertel 674: &log($fh,&encode_entities($line,'<>&"'));
1.46 albertel 675: }
1.48 albertel 676: &log($fh,"</pre>\n");
1.43 albertel 677: close (DFH);
1.95 raeburn 678: my %hostname = &Apache::lonnet::all_hostnames();
679: my $numhosts = scalar(keys(%hostname));
1.68 www 680: # pong to all servers that have delayed messages
681: # this will trigger a reverse connection, which should flush the buffers
1.95 raeburn 682: foreach my $tryserver (sort(keys(%servers))) {
683: if ($hostname{$tryserver} || !$numhosts) {
684: my $answer;
685: eval {
686: local $SIG{ ALRM } = sub { die "TIMEOUT" };
687: alarm(20);
688: $answer = &Apache::lonnet::reply("pong",$tryserver);
689: alarm(0);
690: };
691: if ($@ && $@ =~ m/TIMEOUT/) {
692: &log($fh,"Attempted pong to $tryserver timed out<br />");
1.100 bisitz 693: print "Time out while contacting: $tryserver for pong.\n";
1.95 raeburn 694: } else {
695: &log($fh,"Pong to $tryserver: $answer<br />");
696: }
1.91 raeburn 697: } else {
1.95 raeburn 698: &log($fh,"$tryserver has delayed messages, but is not part of the cluster -- skipping 'Pong'.<br />");
1.91 raeburn 699: }
1.68 www 700: }
1.46 albertel 701: }
1.1 albertel 702:
1.46 albertel 703: sub finish_logging {
704: my ($fh)=@_;
1.48 albertel 705: &log($fh,"<a name='errcount' />\n");
1.43 albertel 706: $totalcount=$notices+4*$warnings+100*$errors;
707: &errout($fh);
1.46 albertel 708: &log($fh,"<h1>Total Error Count: $totalcount</h1>");
709: my $now=time;
710: my $date=localtime($now);
1.48 albertel 711: &log($fh,"<hr />$date ($now)</body></html>\n");
1.100 bisitz 712: print "lon-status webpage updated.\n";
1.43 albertel 713: $fh->close();
1.46 albertel 714:
715: if ($errors) { $simplestatus{'errors'}=$errors; }
716: if ($warnings) { $simplestatus{'warnings'}=$warnings; }
717: if ($notices) { $simplestatus{'notices'}=$notices; }
718: $simplestatus{'time'}=time;
1.1 albertel 719: }
720:
1.46 albertel 721: sub log_simplestatus {
1.73 albertel 722: rename("$statusdir/newstatus.html","$statusdir/index.html");
1.46 albertel 723:
1.43 albertel 724: my $sfh=IO::File->new(">$statusdir/loncron_simple.txt");
725: foreach (keys %simplestatus) {
726: print $sfh $_.'='.$simplestatus{$_}.'&';
727: }
728: print $sfh "\n";
729: $sfh->close();
1.41 www 730: }
1.46 albertel 731:
1.84 raeburn 732: sub write_loncaparevs {
1.100 bisitz 733: print "Retrieving LON-CAPA version information.\n";
1.99 raeburn 734: my %hostname = &Apache::lonnet::all_hostnames();
735: my $output;
736: foreach my $id (sort(keys(%hostname))) {
737: if ($id ne '') {
738: my $loncaparev;
739: eval {
740: local $SIG{ ALRM } = sub { die "TIMEOUT" };
741: alarm(10);
742: $loncaparev =
743: &Apache::lonnet::get_server_loncaparev('',$id,1,'loncron');
744: alarm(0);
745: };
746: if ($@ && $@ =~ m/TIMEOUT/) {
1.100 bisitz 747: print "Time out while contacting lonHost: $id for version.\n";
1.99 raeburn 748: }
749: if ($loncaparev =~ /^[\w.\-]+$/) {
750: $output .= $id.':'.$loncaparev."\n";
751: }
752: }
753: }
754: if ($output) {
755: if (open(my $fh,">$perlvar{'lonTabDir'}/loncaparevs.tab")) {
756: print $fh $output;
757: close($fh);
758: &Apache::lonnet::load_loncaparevs();
759: }
760: }
761: return;
762: }
763:
764: sub write_serverhomeIDs {
1.100 bisitz 765: print "Retrieving LON-CAPA lonHostID information.\n";
1.99 raeburn 766: my %name_to_host = &Apache::lonnet::all_names();
767: my $output;
768: foreach my $name (sort(keys(%name_to_host))) {
769: if ($name ne '') {
770: if (ref($name_to_host{$name}) eq 'ARRAY') {
771: my $serverhomeID;
1.90 raeburn 772: eval {
773: local $SIG{ ALRM } = sub { die "TIMEOUT" };
774: alarm(10);
1.99 raeburn 775: $serverhomeID =
776: &Apache::lonnet::get_server_homeID($name,1,'loncron');
1.90 raeburn 777: alarm(0);
778: };
779: if ($@ && $@ =~ m/TIMEOUT/) {
1.99 raeburn 780: print "Time out while contacting server: $name\n";
1.90 raeburn 781: }
1.99 raeburn 782: if ($serverhomeID ne '') {
783: $output .= $name.':'.$serverhomeID."\n";
784: } else {
785: $output .= $name.':'.$name_to_host{$name}->[0]."\n";
1.84 raeburn 786: }
787: }
788: }
789: }
1.99 raeburn 790: if ($output) {
791: if (open(my $fh,">$perlvar{'lonTabDir'}/serverhomeIDs.tab")) {
792: print $fh $output;
793: close($fh);
794: &Apache::lonnet::load_serverhomeIDs();
1.85 raeburn 795: }
796: }
797: return;
798: }
799:
1.96 raeburn 800: sub write_checksums {
1.98 raeburn 801: my $distro = &LONCAPA::distro();
1.96 raeburn 802: if ($distro) {
803: print "Retrieving file version and checksumming.\n";
1.97 raeburn 804: my $numchksums = 0;
1.96 raeburn 805: my ($chksumsref,$versionsref) =
1.97 raeburn 806: &LONCAPA::Checksumming::get_checksums($distro,$perlvar{'lonDaemons'},
807: $perlvar{'lonLib'},
808: $perlvar{'lonIncludes'},
809: $perlvar{'lonTabDir'});
1.96 raeburn 810: if (ref($chksumsref) eq 'HASH') {
811: $numchksums = scalar(keys(%{$chksumsref}));
812: }
813: print "File version retrieved and checksumming completed for $numchksums files.\n";
814: } else {
815: print "File version retrieval and checksumming skipped - could not determine Linux distro.\n";
816: }
1.97 raeburn 817: return;
1.96 raeburn 818: }
819:
1.104 ! raeburn 820: sub write_connection_config {
! 821: my ($isprimary,$domconf,$url,%connectssl);
! 822: my $primaryLibServer = &Apache::lonnet::domain($perlvar{'lonDefDomain'},'primary');
! 823: if ($primaryLibServer eq $perlvar{'lonHostID'}) {
! 824: $isprimary = 1;
! 825: } elsif ($primaryLibServer ne '') {
! 826: my $protocol = $Apache::lonnet::protocol{$primaryLibServer};
! 827: my $hostname = &Apache::lonnet::hostname($primaryLibServer);
! 828: unless ($protocol eq 'https') {
! 829: $protocol = 'http';
! 830: }
! 831: $url = $protocol.'://'.$hostname.'/cgi-bin/listdomconfig.pl';
! 832: }
! 833: my $domconf = &get_domain_config($perlvar{'lonDefDomain'},$primaryLibServer,$isprimary,
! 834: $url);
! 835: if (ref($domconf) eq 'HASH') {
! 836: if (ref($domconf->{'ssl'}) eq 'HASH') {
! 837: foreach my $connect ('connto','connfrom') {
! 838: if (ref($domconf->{'ssl'}->{$connect}) eq 'HASH') {
! 839: my ($sslreq,$sslnoreq,$currsetting);
! 840: my %contypes;
! 841: foreach my $type ('dom','intdom','other') {
! 842: $connectssl{$connect.'_'.$type} = $domconf->{'ssl'}->{$connect}->{$type};
! 843: }
! 844: }
! 845: }
! 846: }
! 847: if (keys(%connectssl)) {
! 848: if (open(my $fh,">$perlvar{'lonTabDir'}/connectionrules.tab")) {
! 849: my $count = 0;
! 850: foreach my $key (sort(keys(%connectssl))) {
! 851: print $fh "$key=$connectssl{$key}\n";
! 852: $count ++;
! 853: }
! 854: close($fh);
! 855: print "Completed writing SSL options for lonc/lond for $count items.\n";
! 856: }
! 857: } else {
! 858: print "Writing of SSL options skipped - no connection rules in domain configuration.\n";
! 859: }
! 860: } else {
! 861: print "Retrieval of SSL options for lonc/lond skipped - no configuration data available for domain.\n";
! 862: }
! 863: }
! 864:
! 865: sub get_domain_config {
! 866: my ($dom,$primlibserv,$isprimary,$url) = @_;
! 867: my %confhash;
! 868: if ($isprimary) {
! 869: my $lonusersdir = $perlvar{'lonUsersDir'};
! 870: my $fname = $lonusersdir.'/'.$dom.'/configuration.db';
! 871: if (-e $fname) {
! 872: my $dbref=&LONCAPA::locking_hash_tie($fname,&GDBM_READER());
! 873: if (ref($dbref) eq 'HASH') {
! 874: foreach my $key (sort(keys(%{$dbref}))) {
! 875: my $value = $dbref->{$key};
! 876: if ($value =~ s/^__FROZEN__//) {
! 877: $value = thaw(&LONCAPA::unescape($value));
! 878: } else {
! 879: $value = &LONCAPA::unescape($value);
! 880: }
! 881: $confhash{$key} = $value;
! 882: }
! 883: &LONCAPA::locking_hash_untie($dbref);
! 884: }
! 885: }
! 886: } else {
! 887: if (open(PIPE,"wget --no-check-certificate '$url?primary=$primlibserv&format=raw' |")) {
! 888: my $config = '';
! 889: while (<PIPE>) {
! 890: $config .= $_;
! 891: }
! 892: close(PIPE);
! 893: if ($config) {
! 894: my @pairs=split(/\&/,$config);
! 895: foreach my $item (@pairs) {
! 896: my ($key,$value)=split(/=/,$item,2);
! 897: my $what = &LONCAPA::unescape($key);
! 898: if ($value =~ s/^__FROZEN__//) {
! 899: $value = thaw(&LONCAPA::unescape($value));
! 900: } else {
! 901: $value = &LONCAPA::unescape($value);
! 902: }
! 903: $confhash{$what}=$value;
! 904: }
! 905: }
! 906: }
! 907: }
! 908: return \%confhash;
! 909: }
! 910:
! 911: sub write_hosttypes {
! 912: my %intdom = &Apache::lonnet::all_host_intdom();
! 913: my %hostdom = &Apache::lonnet::all_host_domain();
! 914: my $dom = $hostdom{$perlvar{'lonHostID'}};
! 915: my $internetdom = $intdom{$perlvar{'lonHostID'}};
! 916: if (($dom ne '') && ($internetdom ne '')) {
! 917: if (keys(%hostdom)) {
! 918: if (open(my $fh,">$perlvar{'lonTabDir'}/hosttypes.tab")) {
! 919: my $count = 0;
! 920: foreach my $lonid (sort(keys(%hostdom))) {
! 921: my $type = 'other';
! 922: if ($hostdom{$lonid} eq $dom) {
! 923: $type = 'dom';
! 924: } elsif ($intdom{$lonid} eq $internetdom) {
! 925: $type = 'intdom';
! 926: }
! 927: print $fh "$lonid:$type\n";
! 928: $count ++;
! 929: }
! 930: close($fh);
! 931: print "Completed writing host type data for $count hosts.\n";
! 932: }
! 933: } else {
! 934: print "Writing of host types skipped - no hosts found.\n";
! 935: }
! 936: } else {
! 937: print "Writing of host types skipped - could not determine this host's LON-CAPA domain or 'internet' domain.\n";
! 938: }
! 939: }
! 940:
1.46 albertel 941: sub send_mail {
1.79 raeburn 942: my $defdom = $perlvar{'lonDefDomain'};
943: my $origmail = $perlvar{'lonAdmEMail'};
1.78 raeburn 944: my $emailto = &Apache::loncommon::build_recipient_list(undef,
945: 'lonstatusmail',$defdom,$origmail);
1.54 www 946: if ($totalcount>2500) {
1.43 albertel 947: $emailto.=",$perlvar{'lonSysEMail'}";
948: }
1.101 raeburn 949: my $from;
950: my $hostname=`/bin/hostname`;
951: chop($hostname);
952: $hostname=~s/[^\w\.]//g;
953: if ($hostname) {
954: $from = 'www@'.$hostname;
955: }
956: my $subj="LON: $perlvar{'lonHostID'} E:$errors W:$warnings N:$notices";
957: my $loncronmail = "To: $emailto\n".
958: "From: $from\n".
959: "Subject: ".$subj."\n".
960: "Content-type: text/html\; charset=UTF-8\n".
961: "MIME-Version: 1.0\n\n";
962: if (open(my $fh,"<$statusdir/index.html")) {
963: while (<$fh>) {
964: $loncronmail .= $_;
965: }
966: close($fh);
967: } else {
968: $loncronmail .= "Failed to read from http://$hostname/lon-status/index.html\n";
969: }
970: $loncronmail .= "\n\n";
971: if (open(my $mailh, "|/usr/lib/sendmail -oi -t -odb")) {
972: print $mailh $loncronmail;
973: close($mailh);
974: print "Sending mail.\n";
975: } else {
976: print "Sending mail failed.\n";
1.52 albertel 977: }
1.1 albertel 978: }
1.46 albertel 979:
1.49 albertel 980: sub usage {
981: print(<<USAGE);
1.100 bisitz 982: loncron - housekeeping program that checks up on various parts of LON-CAPA
1.49 albertel 983:
984: Options:
1.71 albertel 985: --help Display
1.49 albertel 986: --noemail Do not send the status email
987: --justcheckconnections Only check the current status of the lonc/d
988: connections, do not send emails do not
989: check if the daemons are running, do not
990: generate lon-status
991: --justcheckdaemons Only check that all of the Lon-CAPA daemons are
992: running, do not send emails do not
993: check the lonc/d connections, do not
994: generate lon-status
1.59 albertel 995: --justreload Only tell the daemons to reload the config files,
996: do not send emails do not
997: check if the daemons are running, do not
998: generate lon-status
1.49 albertel 999:
1000: USAGE
1001: }
1002:
1.46 albertel 1003: # ================================================================ Main Program
1004: sub main () {
1.71 albertel 1005: my ($help,$justcheckdaemons,$noemail,$justcheckconnections,
1.59 albertel 1006: $justreload);
1.49 albertel 1007: &GetOptions("help" => \$help,
1008: "justcheckdaemons" => \$justcheckdaemons,
1009: "noemail" => \$noemail,
1.59 albertel 1010: "justcheckconnections" => \$justcheckconnections,
1011: "justreload" => \$justreload
1.49 albertel 1012: );
1013: if ($help) { &usage(); return; }
1.46 albertel 1014: # --------------------------------- Read loncapa_apache.conf and loncapa.conf
1015: my $perlvarref=LONCAPA::Configuration::read_conf('loncapa.conf');
1016: %perlvar=%{$perlvarref};
1017: undef $perlvarref;
1018: delete $perlvar{'lonReceipt'}; # remove since sensitive and not needed
1019: delete $perlvar{'lonSqlAccess'}; # remove since sensitive and not needed
1.75 albertel 1020: chdir($perlvar{'lonDaemons'});
1.46 albertel 1021: # --------------------------------------- Make sure that LON-CAPA is configured
1022: # I only test for one thing here (lonHostID). This is just a safeguard.
1023: if ('{[[[[lonHostID]]]]}' eq $perlvar{'lonHostID'}) {
1024: print("Unconfigured machine.\n");
1025: my $emailto=$perlvar{'lonSysEMail'};
1026: my $hostname=`/bin/hostname`;
1027: chop $hostname;
1028: $hostname=~s/[^\w\.]//g; # make sure is safe to pass through shell
1029: my $subj="LON: Unconfigured machine $hostname";
1030: system("echo 'Unconfigured machine $hostname.' |\
1031: mailto $emailto -s '$subj' > /dev/null");
1032: exit 1;
1033: }
1034:
1035: # ----------------------------- Make sure this process is running from user=www
1036: my $wwwid=getpwnam('www');
1037: if ($wwwid!=$<) {
1.100 bisitz 1038: print("User ID mismatch. This program must be run as user 'www'.\n");
1.46 albertel 1039: my $emailto="$perlvar{'lonAdmEMail'},$perlvar{'lonSysEMail'}";
1040: my $subj="LON: $perlvar{'lonHostID'} User ID mismatch";
1.100 bisitz 1041: system("echo 'User ID mismatch. loncron must be run as user www.' |\
1.46 albertel 1042: mailto $emailto -s '$subj' > /dev/null");
1043: exit 1;
1044: }
1045:
1.72 albertel 1046: # -------------------------------------------- Force reload of host information
1.103 raeburn 1047: my $nomemcache;
1048: if ($justcheckdaemons) {
1049: $nomemcache=1;
1050: my $memcachepidfile="$perlvar{'lonDaemons'}/logs/memcached.pid";
1051: my $memcachepid;
1052: if (-e $memcachepidfile) {
1053: my $memfh=IO::File->new($memcachepidfile);
1054: $memcachepid=<$memfh>;
1055: chomp($memcachepid);
1056: if ($memcachepid =~ /^\d+$/ && kill 0 => $memcachepid) {
1057: undef($nomemcache);
1058: }
1059: }
1060: }
1061: &Apache::lonnet::load_hosts_tab(1,$nomemcache);
1062: &Apache::lonnet::load_domain_tab(1,$nomemcache);
1063: &Apache::lonnet::get_iphost(1,$nomemcache);
1.46 albertel 1064:
1.81 raeburn 1065: # ----------------------------------------- Force firewall update for lond port
1066:
1067: if ((!$justcheckdaemons) && (!$justreload)) {
1068: my $now = time;
1069: my $tmpfile = $perlvar{'lonDaemons'}.'/tmp/lciptables_iphost_'.
1070: $now.$$.int(rand(10000));
1071: if (open(my $fh,">$tmpfile")) {
1072: my %iphosts = &Apache::lonnet::get_iphost();
1073: foreach my $key (keys(%iphosts)) {
1074: print $fh "$key\n";
1075: }
1076: close($fh);
1.89 raeburn 1077: if (&LONCAPA::try_to_lock('/tmp/lock_lciptables')) {
1078: my $execpath = $perlvar{'lonDaemons'}.'/lciptables';
1079: system("$execpath $tmpfile");
1080: unlink('/tmp/lock_lciptables'); # Remove the lock file.
1081: }
1.88 raeburn 1082: unlink($tmpfile);
1.81 raeburn 1083: }
1084: }
1085:
1.46 albertel 1086: # ---------------------------------------------------------------- Start report
1087:
1088: $errors=0;
1089: $warnings=0;
1090: $notices=0;
1091:
1092:
1.49 albertel 1093: my $fh;
1.59 albertel 1094: if (!$justcheckdaemons && !$justcheckconnections && !$justreload) {
1.72 albertel 1095: $fh=&start_logging();
1.49 albertel 1096:
1097: &log_machine_info($fh);
1098: &clean_tmp($fh);
1099: &clean_lonIDs($fh);
1.102 raeburn 1100: &clean_webDAV_sessionIDs($fh);
1.49 albertel 1101: &check_httpd_logs($fh);
1102: &rotate_lonnet_logs($fh);
1.73 albertel 1103: &rotate_other_logs($fh);
1.49 albertel 1104: }
1.59 albertel 1105: if (!$justcheckconnections && !$justreload) {
1.76 albertel 1106: &checkon_daemon($fh,'lonmemcached',40000);
1.49 albertel 1107: &checkon_daemon($fh,'lonsql',200000);
1.63 albertel 1108: if ( &checkon_daemon($fh,'lond',40000,'USR1') eq 'running') {
1109: &checkon_daemon($fh,'lond',40000,'USR2');
1110: }
1.71 albertel 1111: &checkon_daemon($fh,'lonc',40000,'USR1');
1.70 raeburn 1112: &checkon_daemon($fh,'lonmaxima',40000);
1.80 www 1113: &checkon_daemon($fh,'lonr',40000);
1.49 albertel 1114: }
1.59 albertel 1115: if ($justreload) {
1.104 ! raeburn 1116: &write_connection_config();
! 1117: &write_hosttypes();
1.59 albertel 1118: &checkon_daemon($fh,'lond',40000,'USR2');
1.71 albertel 1119: &checkon_daemon($fh,'lonc',40000,'USR2');
1.59 albertel 1120: }
1.63 albertel 1121: if ($justcheckconnections) {
1.72 albertel 1122: &test_connections($fh);
1.49 albertel 1123: }
1.59 albertel 1124: if (!$justcheckdaemons && !$justcheckconnections && !$justreload) {
1.72 albertel 1125: &check_delayed_msg($fh);
1.49 albertel 1126: &finish_logging($fh);
1127: &log_simplestatus();
1.87 raeburn 1128: &write_loncaparevs();
1129: &write_serverhomeIDs();
1.97 raeburn 1130: &write_checksums();
1.104 ! raeburn 1131: &write_connection_config();
! 1132: &write_hosttypes();
1.49 albertel 1133: if ($totalcount>200 && !$noemail) { &send_mail(); }
1134: }
1.46 albertel 1135: }
1136:
1137: &main();
1.1 albertel 1138: 1;
1139:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>