Annotation of loncom/loncron, revision 1.127
1.1 albertel 1: #!/usr/bin/perl
2:
1.47 albertel 3: # Housekeeping program, started by cron, loncontrol and loncron.pl
4: #
1.127 ! raeburn 5: # $Id: loncron,v 1.126 2021/02/01 01:24:09 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.116 raeburn 37: use LONCAPA::LWPReq;
1.72 albertel 38: use Apache::lonnet;
1.79 raeburn 39: use Apache::loncommon;
1.26 harris41 40:
1.1 albertel 41: use IO::File;
42: use IO::Socket;
1.48 albertel 43: use HTML::Entities;
1.49 albertel 44: use Getopt::Long;
1.104 raeburn 45: use GDBM_File;
46: use Storable qw(thaw);
1.114 raeburn 47: use File::ReadBackwards;
1.117 raeburn 48: use File::Copy;
1.127 ! raeburn 49: use GDBM_File qw(GDBM_READER);
! 50: use Storable qw(thaw nfreeze);
1.123 raeburn 51: use Sys::Hostname::FQDN();
52:
1.46 albertel 53: #globals
54: use vars qw (%perlvar %simplestatus $errors $warnings $notices $totalcount);
55:
56: my $statusdir="/home/httpd/html/lon-status";
57:
1.1 albertel 58:
59: # --------------------------------------------------------- Output error status
60:
1.46 albertel 61: sub log {
62: my $fh=shift;
63: if ($fh) { print $fh @_ }
64: }
65:
1.1 albertel 66: sub errout {
67: my $fh=shift;
1.46 albertel 68: &log($fh,(<<ENDERROUT));
1.48 albertel 69: <table border="2" bgcolor="#CCCCCC">
1.1 albertel 70: <tr><td>Notices</td><td>$notices</td></tr>
71: <tr><td>Warnings</td><td>$warnings</td></tr>
72: <tr><td>Errors</td><td>$errors</td></tr>
1.48 albertel 73: </table><p><a href="#top">Top</a></p>
1.1 albertel 74: ENDERROUT
75: }
76:
1.73 albertel 77: sub rotate_logfile {
78: my ($file,$fh,$description) = @_;
79: my $size=(stat($file))[7];
80: if ($size>40000) {
81: &log($fh,"<p>Rotating $description ...</p>");
82: rename("$file.2","$file.3");
83: rename("$file.1","$file.2");
84: rename("$file","$file.1");
1.125 raeburn 85: }
1.73 albertel 86: }
87:
1.42 albertel 88: sub start_daemon {
1.50 albertel 89: my ($fh,$daemon,$pidfile,$args) = @_;
1.44 albertel 90: my $progname=$daemon;
1.71 albertel 91: if ($daemon eq 'lonc') {
1.125 raeburn 92: $progname='loncnew';
1.44 albertel 93: }
1.51 albertel 94: my $error_fname="$perlvar{'lonDaemons'}/logs/${daemon}_errors";
1.73 albertel 95: &rotate_logfile($error_fname,$fh,'error logs');
1.74 albertel 96: if ($daemon eq 'lonc') {
97: &clean_sockets($fh);
98: }
1.51 albertel 99: system("$perlvar{'lonDaemons'}/$progname 2>$perlvar{'lonDaemons'}/logs/${daemon}_errors");
1.60 albertel 100: sleep 1;
1.42 albertel 101: if (-e $pidfile) {
1.48 albertel 102: &log($fh,"<p>Seems like it started ...</p>");
1.42 albertel 103: my $lfh=IO::File->new("$pidfile");
104: my $daemonpid=<$lfh>;
105: chomp($daemonpid);
1.62 albertel 106: if ($daemonpid =~ /^\d+$/ && kill 0 => $daemonpid) {
1.42 albertel 107: return 1;
108: } else {
109: return 0;
110: }
111: }
1.48 albertel 112: &log($fh,"<p>Seems like that did not work!</p>");
1.42 albertel 113: $errors++;
114: return 0;
115: }
116:
117: sub checkon_daemon {
1.59 albertel 118: my ($fh,$daemon,$maxsize,$send,$args)=@_;
1.42 albertel 119:
1.63 albertel 120: my $result;
1.48 albertel 121: &log($fh,'<hr /><a name="'.$daemon.'" /><h2>'.$daemon.'</h2><h3>Log</h3><p style="white-space: pre;"><tt>');
1.57 albertel 122: printf("%-15s ",$daemon);
1.110 raeburn 123: if ($fh) {
124: if (-e "$perlvar{'lonDaemons'}/logs/$daemon.log"){
125: if (open(DFH,"tail -n25 $perlvar{'lonDaemons'}/logs/$daemon.log|")) {
1.125 raeburn 126: while (my $line=<DFH>) {
1.110 raeburn 127: &log($fh,"$line");
128: if ($line=~/INFO/) { $notices++; }
129: if ($line=~/WARNING/) { $notices++; }
130: if ($line=~/CRITICAL/) { $warnings++; }
131: }
132: close (DFH);
133: }
134: }
135: &log($fh,"</tt></p>");
1.42 albertel 136: }
1.125 raeburn 137:
1.42 albertel 138: my $pidfile="$perlvar{'lonDaemons'}/logs/$daemon.pid";
1.125 raeburn 139:
1.42 albertel 140: my $restartflag=1;
1.46 albertel 141: my $daemonpid;
1.42 albertel 142: if (-e $pidfile) {
143: my $lfh=IO::File->new("$pidfile");
1.46 albertel 144: $daemonpid=<$lfh>;
1.42 albertel 145: chomp($daemonpid);
1.62 albertel 146: if ($daemonpid =~ /^\d+$/ && kill 0 => $daemonpid) {
1.46 albertel 147: &log($fh,"<h3>$daemon at pid $daemonpid responding");
1.59 albertel 148: if ($send) { &log($fh,", sending $send"); }
1.46 albertel 149: &log($fh,"</h3>");
1.59 albertel 150: if ($send eq 'USR1') { kill USR1 => $daemonpid; }
151: if ($send eq 'USR2') { kill USR2 => $daemonpid; }
1.42 albertel 152: $restartflag=0;
1.59 albertel 153: if ($send eq 'USR2') {
1.63 albertel 154: $result = 'reloaded';
1.59 albertel 155: print "reloaded\n";
156: } else {
1.63 albertel 157: $result = 'running';
1.59 albertel 158: print "running\n";
159: }
1.42 albertel 160: } else {
161: $errors++;
1.46 albertel 162: &log($fh,"<h3>$daemon at pid $daemonpid not responding</h3>");
1.42 albertel 163: $restartflag=1;
1.46 albertel 164: &log($fh,"<h3>Decided to clean up stale .pid file and restart $daemon</h3>");
1.42 albertel 165: }
166: }
167: if ($restartflag==1) {
168: $simplestatus{$daemon}='off';
169: $errors++;
1.57 albertel 170: my $kadaemon=$daemon;
171: if ($kadaemon eq 'lonmemcached') { $kadaemon='memcached'; }
1.101 raeburn 172: &log($fh,'<br /><font color="red">Killall '.$daemon.': '.
1.57 albertel 173: `killall $kadaemon 2>&1`.' - ');
1.60 albertel 174: sleep 1;
1.46 albertel 175: &log($fh,unlink($pidfile).' - '.
1.57 albertel 176: `killall -9 $kadaemon 2>&1`.
1.101 raeburn 177: '</font><br />');
1.107 raeburn 178: if ($kadaemon eq 'loncnew') {
179: &clean_lonc_childpids();
180: }
1.46 albertel 181: &log($fh,"<h3>$daemon not running, trying to start</h3>");
1.110 raeburn 182:
1.50 albertel 183: if (&start_daemon($fh,$daemon,$pidfile,$args)) {
1.46 albertel 184: &log($fh,"<h3>$daemon at pid $daemonpid responding</h3>");
1.42 albertel 185: $simplestatus{$daemon}='restarted';
1.63 albertel 186: $result = 'started';
1.42 albertel 187: print "started\n";
188: } else {
189: $errors++;
1.46 albertel 190: &log($fh,"<h3>$daemon at pid $daemonpid not responding</h3>");
1.48 albertel 191: &log($fh,"<p>Give it one more try ...</p>");
1.42 albertel 192: print " ";
1.50 albertel 193: if (&start_daemon($fh,$daemon,$pidfile,$args)) {
1.46 albertel 194: &log($fh,"<h3>$daemon at pid $daemonpid responding</h3>");
1.42 albertel 195: $simplestatus{$daemon}='restarted';
1.63 albertel 196: $result = 'started';
1.42 albertel 197: print "started\n";
198: } else {
1.63 albertel 199: $result = 'failed';
1.42 albertel 200: print " failed\n";
201: $simplestatus{$daemon}='failed';
202: $errors++; $errors++;
1.46 albertel 203: &log($fh,"<h3>$daemon at pid $daemonpid not responding</h3>");
1.48 albertel 204: &log($fh,"<p>Unable to start $daemon</p>");
1.42 albertel 205: }
206: }
1.110 raeburn 207: if ($fh) {
208: if (-e "$perlvar{'lonDaemons'}/logs/$daemon.log"){
209: &log($fh,"<p><pre>");
210: if (open(DFH,"tail -n100 $perlvar{'lonDaemons'}/logs/$daemon.log|")) {
211: while (my $line=<DFH>) {
212: &log($fh,"$line");
213: if ($line=~/WARNING/) { $notices++; }
214: if ($line=~/CRITICAL/) { $notices++; }
215: }
216: close (DFH);
217: }
218: &log($fh,"</pre></p>");
219: }
1.42 albertel 220: }
221: }
1.125 raeburn 222:
1.46 albertel 223: my $fname="$perlvar{'lonDaemons'}/logs/$daemon.log";
1.73 albertel 224: &rotate_logfile($fname,$fh,'logs');
1.42 albertel 225:
226: &errout($fh);
1.63 albertel 227: return $result;
1.42 albertel 228: }
1.1 albertel 229:
1.46 albertel 230: # --------------------------------------------------------------------- Machine
231: sub log_machine_info {
232: my ($fh)=@_;
1.48 albertel 233: &log($fh,'<hr /><a name="machine" /><h2>Machine Information</h2>');
1.46 albertel 234: &log($fh,"<h3>loadavg</h3>");
1.125 raeburn 235:
1.126 raeburn 236: my $cpucount;
237: if (open(PIPE,"lscpu |grep '^CPU(s)' 2>&1 |")) {
238: my $info = <PIPE>;
239: chomp($info);
240: ($cpucount) = ($info =~ /^\QCPU(s):\E\s+(\d+)$/);
241: close(PIPE);
242: }
243: if (!$cpucount) {
244: $cpucount = 1;
245: }
246: my %loadtarget = (
247: error => 4.0*$cpucount,
248: warn => 2.0*$cpucount,
249: note => 1.0*$cpucount,
250: );
1.46 albertel 251: open (LOADAVGH,"/proc/loadavg");
252: my $loadavg=<LOADAVGH>;
253: close (LOADAVGH);
1.125 raeburn 254:
1.46 albertel 255: &log($fh,"<tt>$loadavg</tt>");
1.125 raeburn 256:
1.46 albertel 257: my @parts=split(/\s+/,$loadavg);
1.126 raeburn 258: if ($parts[1]>$loadtarget{'error'}) {
1.46 albertel 259: $errors++;
1.126 raeburn 260: } elsif ($parts[1]>$loadtarget{'warn'}) {
1.46 albertel 261: $warnings++;
1.126 raeburn 262: } elsif ($parts[1]>$loadtarget{'note'}) {
1.46 albertel 263: $notices++;
264: }
1.13 harris41 265:
1.46 albertel 266: &log($fh,"<h3>df</h3>");
267: &log($fh,"<pre>");
1.14 harris41 268:
1.46 albertel 269: open (DFH,"df|");
1.125 raeburn 270: while (my $line=<DFH>) {
271: &log($fh,&encode_entities($line,'<>&"'));
1.46 albertel 272: @parts=split(/\s+/,$line);
273: my $usage=$parts[4];
274: $usage=~s/\W//g;
1.125 raeburn 275: if ($usage>90) {
1.46 albertel 276: $warnings++;
1.125 raeburn 277: $notices++;
1.46 albertel 278: } elsif ($usage>80) {
279: $warnings++;
280: } elsif ($usage>60) {
281: $notices++;
1.31 albertel 282: }
1.46 albertel 283: if ($usage>95) { $warnings++; $warnings++; $simplestatus{'diskfull'}++; }
1.1 albertel 284: }
1.46 albertel 285: close (DFH);
286: &log($fh,"</pre>");
1.1 albertel 287:
288:
1.46 albertel 289: &log($fh,"<h3>ps</h3>");
290: &log($fh,"<pre>");
291: my $psproc=0;
1.1 albertel 292:
1.53 albertel 293: open (PSH,"ps aux --cols 140 |");
1.125 raeburn 294: while (my $line=<PSH>) {
295: &log($fh,&encode_entities($line,'<>&"'));
1.46 albertel 296: $psproc++;
297: }
298: close (PSH);
299: &log($fh,"</pre>");
1.1 albertel 300:
1.46 albertel 301: if ($psproc>200) { $notices++; }
302: if ($psproc>250) { $notices++; }
1.1 albertel 303:
1.61 albertel 304: &log($fh,"<h3>distprobe</h3>");
305: &log($fh,"<pre>");
1.98 raeburn 306: &log($fh,&encode_entities(&LONCAPA::distro(),'<>&"'));
1.61 albertel 307: &log($fh,"</pre>");
308:
1.46 albertel 309: &errout($fh);
310: }
1.1 albertel 311:
1.46 albertel 312: sub start_logging {
1.43 albertel 313: my $fh=IO::File->new(">$statusdir/newstatus.html");
314: my %simplestatus=();
1.46 albertel 315: my $now=time;
316: my $date=localtime($now);
1.125 raeburn 317:
1.46 albertel 318:
319: &log($fh,(<<ENDHEADERS));
1.101 raeburn 320: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
321: <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
1.1 albertel 322: <head>
323: <title>LON Status Report $perlvar{'lonHostID'}</title>
1.101 raeburn 324: <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
1.1 albertel 325: </head>
1.3 www 326: <body bgcolor="#AAAAAA">
1.48 albertel 327: <a name="top" />
1.1 albertel 328: <h1>LON Status Report $perlvar{'lonHostID'}</h1>
329: <h2>$date ($now)</h2>
330: <ol>
1.48 albertel 331: <li><a href="#configuration">Configuration</a></li>
332: <li><a href="#machine">Machine Information</a></li>
333: <li><a href="#tmp">Temporary Files</a></li>
334: <li><a href="#tokens">Session Tokens</a></li>
1.102 raeburn 335: <li><a href="#webdav">WebDAV Session Tokens</a></li>
1.48 albertel 336: <li><a href="#httpd">httpd</a></li>
337: <li><a href="#lonsql">lonsql</a></li>
338: <li><a href="#lond">lond</a></li>
339: <li><a href="#lonc">lonc</a></li>
340: <li><a href="#lonnet">lonnet</a></li>
341: <li><a href="#connections">Connections</a></li>
342: <li><a href="#delayed">Delayed Messages</a></li>
343: <li><a href="#errcount">Error Count</a></li>
1.1 albertel 344: </ol>
1.48 albertel 345: <hr />
346: <a name="configuration" />
1.1 albertel 347: <h2>Configuration</h2>
348: <h3>PerlVars</h3>
1.48 albertel 349: <table border="2">
1.1 albertel 350: ENDHEADERS
351:
1.46 albertel 352: foreach my $varname (sort(keys(%perlvar))) {
1.48 albertel 353: &log($fh,"<tr><td>$varname</td><td>".
354: &encode_entities($perlvar{$varname},'<>&"')."</td></tr>\n");
1.43 albertel 355: }
1.48 albertel 356: &log($fh,"</table><h3>Hosts</h3><table border='2'>");
1.72 albertel 357: my %hostname = &Apache::lonnet::all_hostnames();
358: foreach my $id (sort(keys(%hostname))) {
359: my $role = (&Apache::lonnet::is_library($id) ? 'library'
360: : 'access');
1.46 albertel 361: &log($fh,
1.72 albertel 362: "<tr><td>$id</td><td>".&Apache::lonnet::host_domain($id).
363: "</td><td>".$role.
364: "</td><td>".&Apache::lonnet::hostname($id)."</td></tr>\n");
365: }
1.101 raeburn 366: &log($fh,"</table><h3>Spare Hosts</h3>");
367: if (keys(%Apache::lonnet::spareid) > 0) {
368: &log($fh,"<ul>");
369: foreach my $type (sort(keys(%Apache::lonnet::spareid))) {
370: &log($fh,"<li>$type\n<ol>");
371: foreach my $id (@{ $Apache::lonnet::spareid{$type} }) {
372: &log($fh,"<li>$id</li>\n");
373: }
374: &log($fh,"</ol>\n</li>\n");
375: }
376: &log($fh,"</ul>\n");
377: } else {
378: &log($fh,"No spare hosts specified<br />\n");
1.43 albertel 379: }
1.46 albertel 380: return $fh;
381: }
1.11 www 382:
383: # --------------------------------------------------------------- clean out tmp
1.46 albertel 384: sub clean_tmp {
385: my ($fh)=@_;
1.48 albertel 386: &log($fh,'<hr /><a name="tmp" /><h2>Temporary Files</h2>');
1.82 raeburn 387: my ($cleaned,$old,$removed) = (0,0,0);
388: my %errors = (
389: dir => [],
390: file => [],
391: failopen => [],
392: );
393: my %error_titles = (
394: dir => 'failed to remove empty directory:',
395: file => 'failed to unlike stale file',
396: failopen => 'failed to open file or directory'
397: );
398: ($cleaned,$old,$removed) = &recursive_clean_tmp('',$cleaned,$old,$removed,\%errors);
399: &log($fh,"Cleaned up: ".$cleaned." files; removed: $removed empty directories; (found: $old old checkout tokens)");
400: foreach my $key (sort(keys(%errors))) {
401: if (ref($errors{$key}) eq 'ARRAY') {
402: if (@{$errors{$key}} > 0) {
403: &log($fh,"Error during cleanup ($error_titles{$key}):<ul><li>".
404: join('</li><li><tt>',@{$errors{$key}}).'</tt></li></ul><br />');
405: }
406: }
407: }
408: }
409:
410: sub recursive_clean_tmp {
411: my ($subdir,$cleaned,$old,$removed,$errors) = @_;
412: my $base = "$perlvar{'lonDaemons'}/tmp";
413: my $path = $base;
414: next if ($subdir =~ m{\.\./});
415: next unless (ref($errors) eq 'HASH');
416: unless ($subdir eq '') {
417: $path .= '/'.$subdir;
418: }
419: if (opendir(my $dh,"$path")) {
420: while (my $file = readdir($dh)) {
421: next if ($file =~ /^\.\.?$/);
422: my $fname = "$path/$file";
423: if (-d $fname) {
424: my $innerdir;
425: if ($subdir eq '') {
426: $innerdir = $file;
427: } else {
428: $innerdir = $subdir.'/'.$file;
429: }
430: ($cleaned,$old,$removed) =
431: &recursive_clean_tmp($innerdir,$cleaned,$old,$removed,$errors);
432: my @doms = &Apache::lonnet::current_machine_domains();
1.125 raeburn 433:
1.82 raeburn 434: if (open(my $dirhandle,$fname)) {
435: unless (($innerdir eq 'helprequests') ||
436: (($innerdir =~ /^addcourse/) && ($innerdir !~ m{/\d+$}))) {
437: my @contents = grep {!/^\.\.?$/} readdir($dirhandle);
1.125 raeburn 438: join('&&',@contents)."\n";
1.82 raeburn 439: if (scalar(grep {!/^\.\.?$/} readdir($dirhandle)) == 0) {
440: closedir($dirhandle);
441: if ($fname =~ m{^\Q$perlvar{'lonDaemons'}\E/tmp/}) {
442: if (rmdir($fname)) {
443: $removed ++;
444: } elsif (ref($errors->{dir}) eq 'ARRAY') {
445: push(@{$errors->{dir}},$fname);
446: }
447: }
448: }
449: } else {
450: closedir($dirhandle);
451: }
452: }
453: } else {
454: my ($dev,$ino,$mode,$nlink,
455: $uid,$gid,$rdev,$size,
456: $atime,$mtime,$ctime,
457: $blksize,$blocks)=stat($fname);
458: my $now=time;
459: my $since=$now-$mtime;
460: if ($since>$perlvar{'lonExpire'}) {
461: if ($subdir eq '') {
462: my $line='';
463: if ($fname =~ /\.db$/) {
464: if (unlink($fname)) {
465: $cleaned++;
466: } elsif (ref($errors->{file}) eq 'ARRAY') {
467: push(@{$errors->{file}},$fname);
468: }
469: } elsif (open(PROBE,$fname)) {
470: my $line='';
471: $line=<PROBE>;
472: close(PROBE);
473: if ($line=~/^CHECKOUTTOKEN\&/) {
474: if ($since>365*$perlvar{'lonExpire'}) {
475: if (unlink($fname)) {
476: $cleaned++;
477: } elsif (ref($errors->{file}) eq 'ARRAY') {
478: push(@{$errors->{file}},$fname);
479: }
480: } else {
481: $old++;
482: }
483: } else {
484: if (unlink($fname)) {
485: $cleaned++;
486: } elsif (ref($errors->{file}) eq 'ARRAY') {
487: push(@{$errors->{file}},$fname);
488: }
489: }
490: } elsif (ref($errors->{failopen}) eq 'ARRAY') {
1.125 raeburn 491: push(@{$errors->{failopen}},$fname);
1.82 raeburn 492: }
493: } else {
494: if (unlink($fname)) {
495: $cleaned++;
496: } elsif (ref($errors->{file}) eq 'ARRAY') {
497: push(@{$errors->{file}},$fname);
498: }
499: }
500: }
501: }
502: }
503: closedir($dh);
504: } elsif (ref($errors->{failopen}) eq 'ARRAY') {
505: push(@{$errors->{failopen}},$path);
1.43 albertel 506: }
1.82 raeburn 507: return ($cleaned,$old,$removed);
1.46 albertel 508: }
1.11 www 509:
510: # ------------------------------------------------------------ clean out lonIDs
1.46 albertel 511: sub clean_lonIDs {
512: my ($fh)=@_;
1.48 albertel 513: &log($fh,'<hr /><a name="tokens" /><h2>Session Tokens</h2>');
1.46 albertel 514: my $cleaned=0;
515: my $active=0;
516: while (my $fname=<$perlvar{'lonIDsDir'}/*>) {
1.122 raeburn 517: my $now=time;
518: if (-l $fname) {
519: my $linkfname = readlink($fname);
520: if (-f $linkfname) {
521: if ($linkfname =~ m{^$perlvar{'lonIDsDir'}/[^/]+\.id$}) {
522: my @data = stat($linkfname);
523: my $mtime = $data[9];
524: my $since=$now-$mtime;
525: if ($since>$perlvar{'lonExpire'}) {
526: if (unlink($linkfname)) {
527: $cleaned++;
528: &log($fh,"Unlinking $linkfname<br />");
529: unlink($fname);
530: }
531: }
532: }
533: } else {
534: unlink($fname);
535: }
536: } elsif (-f $fname) {
537: my @data = stat($fname);
538: my $mtime = $data[9];
539: my $since=$now-$mtime;
540: if ($since>$perlvar{'lonExpire'}) {
541: if (unlink($fname)) {
542: $cleaned++;
543: &log($fh,"Unlinking $fname<br />");
544: }
545: } else {
546: $active++;
547: }
548: }
1.46 albertel 549: }
1.48 albertel 550: &log($fh,"<p>Cleaned up ".$cleaned." stale session token(s).</p>");
1.46 albertel 551: &log($fh,"<h3>$active open session(s)</h3>");
552: }
1.43 albertel 553:
1.115 raeburn 554: # -------------------------------------------------------- clean out balanceIDs
555:
556: sub clean_balanceIDs {
557: my ($fh)=@_;
558: &log($fh,'<hr /><a name="balcookies" /><h2>Session Tokens</h2>');
559: my $cleaned=0;
560: my $active=0;
561: if (-d $perlvar{'lonBalanceDir'}) {
1.124 raeburn 562: while (my $fname=<$perlvar{'lonBalanceDir'}/*.id>) {
1.115 raeburn 563: my ($dev,$ino,$mode,$nlink,
564: $uid,$gid,$rdev,$size,
565: $atime,$mtime,$ctime,
566: $blksize,$blocks)=stat($fname);
567: my $now=time;
568: my $since=$now-$mtime;
569: if ($since>$perlvar{'lonExpire'}) {
570: $cleaned++;
571: &log($fh,"Unlinking $fname<br />");
572: unlink("$fname");
573: } else {
574: $active++;
575: }
576: }
577: }
578: &log($fh,"<p>Cleaned up ".$cleaned." stale balancer files</p>");
579: &log($fh,"<h3>$active unexpired balancer files</h3>");
580: }
581:
1.102 raeburn 582: # ------------------------------------------------ clean out webDAV Session IDs
583: sub clean_webDAV_sessionIDs {
584: my ($fh)=@_;
585: if ($perlvar{'lonRole'} eq 'library') {
586: &log($fh,'<hr /><a name="webdav" /><h2>WebDAV Session Tokens</h2>');
587: my $cleaned=0;
588: my $active=0;
589: my $now = time;
590: if (-d $perlvar{'lonDAVsessDir'}) {
591: while (my $fname=<$perlvar{'lonDAVsessDir'}/*>) {
592: my @stats = stat($fname);
593: my $since=$now-$stats[9];
594: if ($since>$perlvar{'lonExpire'}) {
595: $cleaned++;
596: &log($fh,"Unlinking $fname<br />");
597: unlink("$fname");
598: } else {
599: $active++;
600: }
601: }
602: &log($fh,"<p>Cleaned up ".$cleaned." stale webDAV session token(s).</p>");
603: &log($fh,"<h3>$active open webDAV session(s)</h3>");
604: }
605: }
606: }
607:
1.119 raeburn 608: # ------------------------------------------------------------ clean out ltiIDs
609:
610: sub clean_ltiIDs {
611: my ($fh)=@_;
612: &log($fh,'<hr /><a name="ltisessions" /><h2>LTI Session Pointers</h2>');
613: my $cleaned=0;
614: my $active=0;
615: if (-d $perlvar{'ltiIDsDir'}) {
616: while (my $fname=<$perlvar{'ltiIDsDir'}/*>) {
617: my ($dev,$ino,$mode,$nlink,
618: $uid,$gid,$rdev,$size,
619: $atime,$mtime,$ctime,
620: $blksize,$blocks)=stat($fname);
621: my $now=time;
622: my $since=$now-$mtime;
623: if ($since>$perlvar{'lonExpire'}) {
624: $cleaned++;
625: &log($fh,"Unlinking $fname<br />");
626: unlink("$fname");
627: } else {
628: $active++;
629: }
630: }
631: }
632: &log($fh,"<p>Cleaned up ".$cleaned." old LTI session pointers.</p>");
633: &log($fh,"<h3>$active unexpired LTI session pointers</h3>");
634: }
635:
1.74 albertel 636: # ----------------------------------------------------------- clean out sockets
637: sub clean_sockets {
638: my ($fh)=@_;
639: my $cleaned=0;
640: opendir(SOCKETS,$perlvar{'lonSockDir'});
641: while (my $fname=readdir(SOCKETS)) {
642: next if (-d $fname
1.80 www 643: || $fname=~/(mysqlsock|maximasock|rsock|\Q$perlvar{'lonSockDir'}\E)/);
1.74 albertel 644: $cleaned++;
645: &log($fh,"Unlinking $fname<br />");
646: unlink("/home/httpd/sockets/$fname");
647: }
648: &log($fh,"<p>Cleaned up ".$cleaned." stale sockets.</p>");
649: }
650:
1.11 www 651:
1.1 albertel 652: # ----------------------------------------------------------------------- httpd
1.46 albertel 653: sub check_httpd_logs {
654: my ($fh)=@_;
1.94 raeburn 655: if (open(PIPE,"./lchttpdlogs|")) {
1.93 raeburn 656: while (my $line=<PIPE>) {
657: &log($fh,$line);
658: if ($line=~/\[error\]/) { $notices++; }
659: }
660: close(PIPE);
1.46 albertel 661: }
1.43 albertel 662: &errout($fh);
1.46 albertel 663: }
1.1 albertel 664:
665: # ---------------------------------------------------------------------- lonnet
666:
1.48 albertel 667: sub rotate_lonnet_logs {
1.46 albertel 668: my ($fh)=@_;
1.48 albertel 669: &log($fh,'<hr /><a name="lonnet" /><h2>lonnet</h2><h3>Temp Log</h3><pre>');
1.100 bisitz 670: print "Checking logs.\n";
1.43 albertel 671: if (-e "$perlvar{'lonDaemons'}/logs/lonnet.log"){
672: open (DFH,"tail -n50 $perlvar{'lonDaemons'}/logs/lonnet.log|");
1.125 raeburn 673: while (my $line=<DFH>) {
1.48 albertel 674: &log($fh,&encode_entities($line,'<>&"'));
1.46 albertel 675: }
1.43 albertel 676: close (DFH);
677: }
1.46 albertel 678: &log($fh,"</pre><h3>Perm Log</h3><pre>");
1.125 raeburn 679:
1.43 albertel 680: if (-e "$perlvar{'lonDaemons'}/logs/lonnet.perm.log") {
681: open(DFH,"tail -n10 $perlvar{'lonDaemons'}/logs/lonnet.perm.log|");
1.125 raeburn 682: while (my $line=<DFH>) {
1.48 albertel 683: &log($fh,&encode_entities($line,'<>&"'));
1.46 albertel 684: }
1.43 albertel 685: close (DFH);
1.46 albertel 686: } else { &log($fh,"No perm log\n") }
1.43 albertel 687:
1.46 albertel 688: my $fname="$perlvar{'lonDaemons'}/logs/lonnet.log";
1.73 albertel 689: &rotate_logfile($fname,$fh,'lonnet log');
1.1 albertel 690:
1.46 albertel 691: &log($fh,"</pre>");
1.43 albertel 692: &errout($fh);
1.46 albertel 693: }
694:
1.73 albertel 695: sub rotate_other_logs {
696: my ($fh) = @_;
1.83 raeburn 697: my %logs = (
698: autoenroll => 'Auto Enroll log',
699: autocreate => 'Create Course log',
700: searchcat => 'Search Cataloguing log',
701: autoupdate => 'Auto Update log',
702: refreshcourseids_db => 'Refresh CourseIDs db log',
703: );
704: foreach my $item (keys(%logs)) {
705: my $fname=$perlvar{'lonDaemons'}.'/logs/'.$item.'.log';
706: &rotate_logfile($fname,$fh,$logs{$item});
707: }
1.73 albertel 708: }
709:
1.43 albertel 710: # ----------------------------------------------------------------- Connections
1.46 albertel 711: sub test_connections {
1.72 albertel 712: my ($fh)=@_;
1.48 albertel 713: &log($fh,'<hr /><a name="connections" /><h2>Connections</h2>');
1.100 bisitz 714: print "Testing connections.\n";
1.48 albertel 715: &log($fh,"<table border='2'>");
1.49 albertel 716: my ($good,$bad)=(0,0);
1.72 albertel 717: my %hostname = &Apache::lonnet::all_hostnames();
718: foreach my $tryserver (sort(keys(%hostname))) {
1.43 albertel 719: print(".");
1.46 albertel 720: my $result;
1.72 albertel 721: my $answer=&Apache::lonnet::reply("ping",$tryserver);
1.43 albertel 722: if ($answer eq "$tryserver:$perlvar{'lonHostID'}") {
723: $result="<b>ok</b>";
1.49 albertel 724: $good++;
1.43 albertel 725: } else {
726: $result=$answer;
727: $warnings++;
1.49 albertel 728: if ($answer eq 'con_lost') {
729: $bad++;
730: $warnings++;
1.50 albertel 731: } else {
732: $good++; #self connection
1.49 albertel 733: }
1.43 albertel 734: }
735: if ($answer =~ /con_lost/) { print(" $tryserver down\n"); }
1.46 albertel 736: &log($fh,"<tr><td>$tryserver</td><td>$result</td></tr>\n");
1.1 albertel 737: }
1.46 albertel 738: &log($fh,"</table>");
1.49 albertel 739: print "\n$good good, $bad bad connections\n";
1.43 albertel 740: &errout($fh);
1.46 albertel 741: }
742:
743:
1.1 albertel 744: # ------------------------------------------------------------ Delayed messages
1.46 albertel 745: sub check_delayed_msg {
1.114 raeburn 746: my ($fh,$weightsref,$exclusionsref)=@_;
1.48 albertel 747: &log($fh,'<hr /><a name="delayed" /><h2>Delayed Messages</h2>');
1.100 bisitz 748: print "Checking buffers.\n";
1.46 albertel 749:
750: &log($fh,'<h3>Scanning Permanent Log</h3>');
1.1 albertel 751:
1.46 albertel 752: my $unsend=0;
1.114 raeburn 753: my $ignored=0;
1.1 albertel 754:
1.105 raeburn 755: my %hostname = &Apache::lonnet::all_hostnames();
756: my $numhosts = scalar(keys(%hostname));
1.114 raeburn 757: my $checkbackwards = 0;
758: my $checkfrom = 0;
759: my $checkexcluded = 0;
760: my (%bymachine,%weights,%exclusions,%serverhomes);
761: if (ref($weightsref) eq 'HASH') {
762: %weights = %{$weightsref};
763: }
764: if (ref($exclusionsref) eq 'HASH') {
765: %exclusions = %{$exclusionsref};
766: if (keys(%exclusions)) {
767: $checkexcluded = 1;
768: %serverhomes = &read_serverhomeIDs();
769: }
770: }
1.105 raeburn 771:
1.114 raeburn 772: #
773: # For LON-CAPA 1.2.0 to 2.1.3 (release dates: 8/31/2004 and 3/31/2006) any
774: # entry logged in lonnet.perm.log for completion of a delayed (critical)
775: # transaction lacked the hostID for the remote node to which the command
776: # to be completed was sent.
777: #
778: # Because of this, exclusion of items in lonnet.perm.log for nodes which are
779: # no longer part of the cluster from adding to the overall "unsend" count
780: # needs additional effort besides the changes made in loncron rev. 1.105.
781: #
782: # For "S" (completion) events logging in LON-CAPA 1.2.0 through 2.1.3 included
783: # "LondTransaction=HASH(hexadecimal)->getClient() :$cmd, where the hexadecimal
784: # is a memory location, and $cmd is the command sent to the remote node.
785: #
786: # Starting with 2.2.0 (released 8/21/2006) logging for "S" (completion) events
787: # had sethost:$host_id:$cmd after LondTransaction=HASH(hexadecimal)->getClient()
788: #
789: # Starting with 2.4.1 (released 6/13/2007) logging for "S" replaced echoing the
790: # getClient() call with the result of the Transaction->getClient() call itself
791: # undef for completion of delivery of a delayed message.
792: #
793: # The net effect of these changes is that lonnet.perm.log is now accessed three
794: # times: (a) oldest record is checked, if earlier than release date for 2.5.0
795: # then (b) file is read backwards, with timestamp recorded for most recent
796: # instance of logged "S" event for "update" command without "sethost:$host_id:"
797: # then (c) file is read forward with records ignored which predate the timestamp
798: # recorded in (b), if one was found.
799: #
800: # In (c), when calculating the unsend total, i.e., the difference between delayed
801: # transactions ("D") and sent transactions ("S"), transactions are ignored if the
802: # target node is no longer in the cluster, and also (for "update" commands), if
803: # the target node is in the list of nodes excluded from the count, in the domain
804: # configuration for this machine's default domain. The idea here is to remove
805: # delayed "update" commands for nodes for which inbound access to port 5663,
806: # is blocked, but are still part of the LON-CAPA network, (i.e., they can still
807: # replicate content from other nodes).
808: #
809:
810: my $dfh=IO::File->new("$perlvar{'lonDaemons'}/logs/lonnet.perm.log","r");
811: if (defined($dfh)) {
812: while (my $line=<$dfh>) {
813: my ($time,$sdf,$rest)=split(/:/,$line,3);
814: if ($time < 1541185772) {
815: $checkbackwards = 1;
816: }
817: last;
818: }
819: undef $dfh;
820: }
821:
822: if ($checkbackwards) {
823: if (tie *BW, 'File::ReadBackwards', "$perlvar{'lonDaemons'}/logs/lonnet.perm.log") {
824: while(my $line=<BW>) {
825: if ($line =~ /\QLondTransaction=HASH\E[^:]+:update:/) {
826: ($checkfrom) = split(/:/,$line,2);
827: last;
828: }
829: }
830: close(BW);
831: }
1.1 albertel 832: }
1.114 raeburn 833: $dfh=IO::File->new("$perlvar{'lonDaemons'}/logs/lonnet.perm.log","r");
834: if (defined($dfh)) {
835: while (my $line=<$dfh>) {
836: my ($time,$sdf,$rest)=split(/:/,$line,3);
837: next unless (($sdf eq 'F') || ($sdf eq 'S') || ($sdf eq 'D'));
838: next if (($checkfrom) && ($time <= $checkfrom));
839: my ($dserv,$dcmd);
840: if ($sdf eq 'S') {
841: my ($serva,$cmda,$servb,$cmdb) = split(/:/,$rest);
842: if ($cmda eq 'sethost') {
843: chomp($cmdb);
844: $dcmd = $cmdb;
845: } else {
846: $dcmd = $cmda;
847: }
848: if (($serva =~ /^LondTransaction/) || ($serva eq '')) {
849: unless (($servb eq '') || ($servb =~ m{^/})) {
850: $dserv = $servb;
851: }
852: } else {
853: $dserv = $serva;
854: }
855: } else {
856: ($dserv,$dcmd) = split(/:/,$rest);
857: }
858: if ($sdf eq 'F') {
859: my $local=localtime($time);
860: &log($fh,"<b>Failed: $time, $dserv, $dcmd</b><br />");
861: $warnings++;
862: }
863: next if ((($dserv eq '') || ($dcmd eq '')) && ($sdf ne 'F'));
864: if ($sdf eq 'S') {
865: if ($dcmd eq 'update') {
866: if ($hostname{$dserv}) {
867: if ($exclusions{$serverhomes{$hostname{$dserv}}}) {
868: $ignored --;
869: } else {
870: $unsend --;
871: }
872: }
873: if (exists($bymachine{$dserv})) {
874: $bymachine{$dserv} --;
875: } else {
876: $bymachine{$dserv} = -1;
877: }
878: } else {
879: if ($hostname{$dserv}) {
880: $unsend --;
881: }
882: }
883: } elsif ($sdf eq 'D') {
884: if ($dcmd eq 'update') {
885: if ($hostname{$dserv}) {
886: if ($exclusions{$serverhomes{$hostname{$dserv}}}) {
887: $ignored ++;
888: } else {
889: $unsend ++;
890: }
891: }
892: if (exists($bymachine{$dserv})) {
893: $bymachine{$dserv} ++;
894: } else {
895: $bymachine{$dserv} = 1;
896: }
897: } else {
898: if ($hostname{$dserv}) {
899: $unsend ++;
900: }
901: }
902: }
903: }
904: undef $dfh;
905: my $nodest = 0;
906: my $retired = 0;
907: my %active;
908: if (keys(%bymachine)) {
909: unless ($checkexcluded) {
910: %serverhomes = &read_serverhomeIDs();
911: }
912: foreach my $key (keys(%bymachine)) {
913: if ($bymachine{$key} > 0) {
914: if ($hostname{$key}) {
915: $active{$serverhomes{$hostname{$key}}} += $bymachine{$key};
916: } else {
917: $retired ++;
918: $nodest += $bymachine{$key};
919: }
920: }
921: }
922: }
923: if (keys(%active)) {
924: &log($fh,"<p>Unsend messages by node, active (undegraded) nodes in cluster</p>\n");
925: foreach my $key (sort(keys(%active))) {
926: &log($fh,&encode_entities("$key => $active{$key}",'<>&"')."\n");
927: }
928: }
929: &log($fh,"<p>Total unsend messages: <b>$unsend</b> for ".scalar(keys(%active))." active (undegraded) nodes in cluster.</p>\n");
930: if (keys(%exclusions) > 0) {
931: &log($fh,"<p>Total incomplete updates <b>$ignored</b> for ".scalar(keys(%exclusions))." degraded nodes in cluster.</p>\n");
932: }
933: if ($retired) {
934: &log($fh,"<p>Total unsent <b>$nodest</b> for $retired nodes no longer in cluster.</p>\n");
935: }
936: if ($unsend > 0) {
937: $warnings=$warnings+$weights{'U'}*$unsend;
938: }
1.95 raeburn 939: }
1.1 albertel 940:
1.43 albertel 941: if ($unsend) { $simplestatus{'unsend'}=$unsend; }
1.48 albertel 942: &log($fh,"<h3>Outgoing Buffer</h3>\n<pre>");
1.68 www 943: # list directory with delayed messages and remember offline servers
944: my %servers=();
1.43 albertel 945: open (DFH,"ls -lF $perlvar{'lonSockDir'}/delayed|");
1.68 www 946: while (my $line=<DFH>) {
947: my ($server)=($line=~/\.(\w+)$/);
948: if ($server) { $servers{$server}=1; }
1.48 albertel 949: &log($fh,&encode_entities($line,'<>&"'));
1.46 albertel 950: }
1.48 albertel 951: &log($fh,"</pre>\n");
1.43 albertel 952: close (DFH);
1.68 www 953: # pong to all servers that have delayed messages
954: # this will trigger a reverse connection, which should flush the buffers
1.95 raeburn 955: foreach my $tryserver (sort(keys(%servers))) {
956: if ($hostname{$tryserver} || !$numhosts) {
957: my $answer;
958: eval {
959: local $SIG{ ALRM } = sub { die "TIMEOUT" };
960: alarm(20);
961: $answer = &Apache::lonnet::reply("pong",$tryserver);
962: alarm(0);
963: };
964: if ($@ && $@ =~ m/TIMEOUT/) {
965: &log($fh,"Attempted pong to $tryserver timed out<br />");
1.100 bisitz 966: print "Time out while contacting: $tryserver for pong.\n";
1.95 raeburn 967: } else {
968: &log($fh,"Pong to $tryserver: $answer<br />");
969: }
1.91 raeburn 970: } else {
1.95 raeburn 971: &log($fh,"$tryserver has delayed messages, but is not part of the cluster -- skipping 'Pong'.<br />");
1.91 raeburn 972: }
1.68 www 973: }
1.46 albertel 974: }
1.1 albertel 975:
1.46 albertel 976: sub finish_logging {
1.114 raeburn 977: my ($fh,$weightsref)=@_;
978: my %weights;
979: if (ref($weightsref) eq 'HASH') {
980: %weights = %{$weightsref};
981: }
1.48 albertel 982: &log($fh,"<a name='errcount' />\n");
1.113 raeburn 983: $totalcount=($weights{'N'}*$notices)+($weights{'W'}*$warnings)+($weights{'E'}*$errors);
1.43 albertel 984: &errout($fh);
1.46 albertel 985: &log($fh,"<h1>Total Error Count: $totalcount</h1>");
986: my $now=time;
987: my $date=localtime($now);
1.48 albertel 988: &log($fh,"<hr />$date ($now)</body></html>\n");
1.100 bisitz 989: print "lon-status webpage updated.\n";
1.43 albertel 990: $fh->close();
1.46 albertel 991:
992: if ($errors) { $simplestatus{'errors'}=$errors; }
993: if ($warnings) { $simplestatus{'warnings'}=$warnings; }
994: if ($notices) { $simplestatus{'notices'}=$notices; }
995: $simplestatus{'time'}=time;
1.1 albertel 996: }
997:
1.46 albertel 998: sub log_simplestatus {
1.73 albertel 999: rename("$statusdir/newstatus.html","$statusdir/index.html");
1.46 albertel 1000:
1.43 albertel 1001: my $sfh=IO::File->new(">$statusdir/loncron_simple.txt");
1002: foreach (keys %simplestatus) {
1003: print $sfh $_.'='.$simplestatus{$_}.'&';
1004: }
1005: print $sfh "\n";
1006: $sfh->close();
1.41 www 1007: }
1.46 albertel 1008:
1.84 raeburn 1009: sub write_loncaparevs {
1.100 bisitz 1010: print "Retrieving LON-CAPA version information.\n";
1.99 raeburn 1011: my %hostname = &Apache::lonnet::all_hostnames();
1012: my $output;
1013: foreach my $id (sort(keys(%hostname))) {
1014: if ($id ne '') {
1015: my $loncaparev;
1016: eval {
1017: local $SIG{ ALRM } = sub { die "TIMEOUT" };
1018: alarm(10);
1019: $loncaparev =
1020: &Apache::lonnet::get_server_loncaparev('',$id,1,'loncron');
1021: alarm(0);
1022: };
1023: if ($@ && $@ =~ m/TIMEOUT/) {
1.100 bisitz 1024: print "Time out while contacting lonHost: $id for version.\n";
1.99 raeburn 1025: }
1026: if ($loncaparev =~ /^[\w.\-]+$/) {
1027: $output .= $id.':'.$loncaparev."\n";
1028: }
1029: }
1030: }
1031: if ($output) {
1032: if (open(my $fh,">$perlvar{'lonTabDir'}/loncaparevs.tab")) {
1033: print $fh $output;
1034: close($fh);
1035: &Apache::lonnet::load_loncaparevs();
1036: }
1037: }
1038: return;
1039: }
1040:
1041: sub write_serverhomeIDs {
1.100 bisitz 1042: print "Retrieving LON-CAPA lonHostID information.\n";
1.99 raeburn 1043: my %name_to_host = &Apache::lonnet::all_names();
1044: my $output;
1045: foreach my $name (sort(keys(%name_to_host))) {
1046: if ($name ne '') {
1047: if (ref($name_to_host{$name}) eq 'ARRAY') {
1048: my $serverhomeID;
1.90 raeburn 1049: eval {
1050: local $SIG{ ALRM } = sub { die "TIMEOUT" };
1051: alarm(10);
1.125 raeburn 1052: $serverhomeID =
1.99 raeburn 1053: &Apache::lonnet::get_server_homeID($name,1,'loncron');
1.90 raeburn 1054: alarm(0);
1055: };
1056: if ($@ && $@ =~ m/TIMEOUT/) {
1.99 raeburn 1057: print "Time out while contacting server: $name\n";
1.90 raeburn 1058: }
1.99 raeburn 1059: if ($serverhomeID ne '') {
1060: $output .= $name.':'.$serverhomeID."\n";
1061: } else {
1062: $output .= $name.':'.$name_to_host{$name}->[0]."\n";
1.84 raeburn 1063: }
1064: }
1065: }
1066: }
1.99 raeburn 1067: if ($output) {
1068: if (open(my $fh,">$perlvar{'lonTabDir'}/serverhomeIDs.tab")) {
1069: print $fh $output;
1070: close($fh);
1071: &Apache::lonnet::load_serverhomeIDs();
1.85 raeburn 1072: }
1073: }
1074: return;
1075: }
1076:
1.96 raeburn 1077: sub write_checksums {
1.98 raeburn 1078: my $distro = &LONCAPA::distro();
1.96 raeburn 1079: if ($distro) {
1080: print "Retrieving file version and checksumming.\n";
1.97 raeburn 1081: my $numchksums = 0;
1.96 raeburn 1082: my ($chksumsref,$versionsref) =
1.97 raeburn 1083: &LONCAPA::Checksumming::get_checksums($distro,$perlvar{'lonDaemons'},
1084: $perlvar{'lonLib'},
1085: $perlvar{'lonIncludes'},
1086: $perlvar{'lonTabDir'});
1.96 raeburn 1087: if (ref($chksumsref) eq 'HASH') {
1088: $numchksums = scalar(keys(%{$chksumsref}));
1089: }
1090: print "File version retrieved and checksumming completed for $numchksums files.\n";
1091: } else {
1092: print "File version retrieval and checksumming skipped - could not determine Linux distro.\n";
1093: }
1.97 raeburn 1094: return;
1.96 raeburn 1095: }
1096:
1.117 raeburn 1097: sub write_hostips {
1098: my $lontabdir = $perlvar{'lonTabDir'};
1099: my $defdom = $perlvar{'lonDefDomain'};
1100: my $lonhost = $perlvar{'lonHostID'};
1101: my $newfile = "$lontabdir/currhostips.tab";
1102: my $oldfile = "$lontabdir/prevhostips.tab";
1103: my (%prevhosts,%currhosts,%ipchange);
1104: if ((-e $newfile) && (-s $newfile)) {
1105: move($newfile,$oldfile);
1106: chmod(0644,$oldfile);
1107: if (open(my $fh,'<',$oldfile)) {
1108: while (my $line=<$fh>) {
1109: chomp($line);
1110: if ($line =~ /^([^:]+):([\d.]+)$/) {
1111: $prevhosts{$1} = $2;
1112: }
1113: }
1114: close($fh);
1115: }
1116: }
1117: my ($ip_info,$cached) =
1118: &Apache::lonnet::is_cached_new('iphost','iphost');
1119: if (!$cached) {
1120: &Apache::lonnet::get_iphost();
1121: ($ip_info,$cached) =
1122: &Apache::lonnet::is_cached_new('iphost','iphost');
1123: }
1124: if (ref($ip_info) eq 'ARRAY') {
1125: %currhosts = %{$ip_info->[1]};
1126: if (open(my $fh,'>',$newfile)) {
1127: foreach my $key (keys(%currhosts)) {
1128: print $fh "$key:$currhosts{$key}\n";
1129: }
1130: close($fh);
1131: chmod(0644,$newfile);
1132: }
1133: }
1134: if (keys(%prevhosts) && keys(%currhosts)) {
1135: foreach my $key (keys(%prevhosts)) {
1136: unless ($currhosts{$key} eq $prevhosts{$key}) {
1.121 raeburn 1137: $ipchange{$key} = $prevhosts{$key}.' | '.$currhosts{$key};
1.117 raeburn 1138: }
1139: }
1140: foreach my $key (keys(%currhosts)) {
1141: unless ($currhosts{$key} eq $prevhosts{$key}) {
1.121 raeburn 1142: $ipchange{$key} = $prevhosts{$key}.' | '.$currhosts{$key};
1.117 raeburn 1143: }
1144: }
1145: }
1146: if (&Apache::lonnet::domain($defdom,'primary') eq $lonhost) {
1147: if (keys(%ipchange)) {
1148: if (open(my $fh,'>>',$perlvar{'lonDaemons'}.'/logs/hostip.log')) {
1149: print $fh "********************\n".localtime(time).' Changes --'."\n".
1.121 raeburn 1150: "| Hostname | Previous IP | New IP |\n".
1151: " --------------------------------- \n";
1.117 raeburn 1152: foreach my $hostname (sort(keys(%ipchange))) {
1.121 raeburn 1153: print $fh "| $hostname | $ipchange{$hostname} |\n";
1.117 raeburn 1154: }
1155: print $fh "\n*******************\n\n";
1156: close($fh);
1157: }
1158: my $emailto = &Apache::loncommon::build_recipient_list(undef,
1159: 'hostipmail',$defdom);
1160: if ($emailto) {
1161: my $subject = "LON-CAPA Hostname to IP change ($perlvar{'lonHostID'})";
1162: my $chgmail = "To: $emailto\n".
1163: "Subject: $subject\n".
1164: "Content-type: text/plain\; charset=UTF-8\n".
1165: "MIME-Version: 1.0\n\n".
1166: "Host/IP changes\n".
1167: " \n".
1.121 raeburn 1168: "| Hostname | Previous IP | New IP |\n".
1169: " --------------------------------- \n";
1.117 raeburn 1170: foreach my $hostname (sort(keys(%ipchange))) {
1.121 raeburn 1171: $chgmail .= "| $hostname | $ipchange{$hostname} |\n";
1.117 raeburn 1172: }
1173: $chgmail .= "\n\n";
1174: if (open(my $mailh, "|/usr/lib/sendmail -oi -t -odb")) {
1175: print $mailh $chgmail;
1176: close($mailh);
1177: print "Sending mail notification of hostname/IP changes.\n";
1178: }
1179: }
1180: }
1181: }
1182: return;
1183: }
1184:
1.107 raeburn 1185: sub clean_nosslverify {
1186: my ($fh) = @_;
1.125 raeburn 1187: my %unlinked;
1.107 raeburn 1188: if (-d "$perlvar{'lonSockDir'}/nosslverify") {
1189: if (opendir(my $dh,"$perlvar{'lonSockDir'}/nosslverify")) {
1190: while (my $fname=readdir($dh)) {
1191: next if ($fname =~ /^\.+$/);
1192: if (unlink("/home/httpd/sockets/nosslverify/$fname")) {
1193: &log($fh,"Unlinking $fname<br />");
1194: $unlinked{$fname} = 1;
1195: }
1196: }
1197: closedir($dh);
1198: }
1199: }
1200: &log($fh,"<p>Removed ".scalar(keys(%unlinked))." nosslverify clients</p>");
1201: return %unlinked;
1202: }
1203: sub clean_lonc_childpids {
1204: my $childpiddir = "$perlvar{'lonDocRoot'}/lon-status/loncchld";
1205: if (-d $childpiddir) {
1206: if (opendir(my $dh,$childpiddir)) {
1207: while (my $fname=readdir($dh)) {
1208: next if ($fname =~ /^\.+$/);
1209: unlink("$childpiddir/$fname");
1210: }
1211: closedir($dh);
1212: }
1213: }
1214: }
1215:
1.104 raeburn 1216: sub write_connection_config {
1.113 raeburn 1217: my ($domconf,%connectssl,%changes);
1218: $domconf = &get_domain_config();
1.104 raeburn 1219: if (ref($domconf) eq 'HASH') {
1220: if (ref($domconf->{'ssl'}) eq 'HASH') {
1221: foreach my $connect ('connto','connfrom') {
1222: if (ref($domconf->{'ssl'}->{$connect}) eq 'HASH') {
1223: my ($sslreq,$sslnoreq,$currsetting);
1224: my %contypes;
1225: foreach my $type ('dom','intdom','other') {
1226: $connectssl{$connect.'_'.$type} = $domconf->{'ssl'}->{$connect}->{$type};
1227: }
1228: }
1229: }
1230: }
1231: if (keys(%connectssl)) {
1.107 raeburn 1232: my %currconf;
1233: if (open(my $fh,'<',"$perlvar{'lonTabDir'}/connectionrules.tab")) {
1234: while (my $line = <$fh>) {
1235: chomp($line);
1236: my ($name,$value) = split(/=/,$line);
1237: if ($value =~ /^(?:no|yes|req)$/) {
1238: if ($name =~ /^conn(to|from)_(dom|intdom|other)$/) {
1239: $currconf{$name} = $value;
1240: }
1241: }
1242: }
1243: close($fh);
1244: }
1245: if (open(my $fh,'>',"$perlvar{'lonTabDir'}/connectionrules.tab")) {
1.104 raeburn 1246: my $count = 0;
1247: foreach my $key (sort(keys(%connectssl))) {
1248: print $fh "$key=$connectssl{$key}\n";
1.107 raeburn 1249: if (exists($currconf{$key})) {
1250: unless ($currconf{$key} eq $connectssl{$key}) {
1251: $changes{$key} = 1;
1252: }
1253: } else {
1254: $changes{$key} = 1;
1255: }
1.104 raeburn 1256: $count ++;
1257: }
1258: close($fh);
1259: print "Completed writing SSL options for lonc/lond for $count items.\n";
1260: }
1261: } else {
1262: print "Writing of SSL options skipped - no connection rules in domain configuration.\n";
1263: }
1264: } else {
1265: print "Retrieval of SSL options for lonc/lond skipped - no configuration data available for domain.\n";
1266: }
1.107 raeburn 1267: return %changes;
1.104 raeburn 1268: }
1269:
1270: sub get_domain_config {
1.113 raeburn 1271: my ($dom,$primlibserv,$isprimary,$url,%confhash);
1272: $dom = $perlvar{'lonDefDomain'};
1273: $primlibserv = &Apache::lonnet::domain($dom,'primary');
1274: if ($primlibserv eq $perlvar{'lonHostID'}) {
1275: $isprimary = 1;
1276: } elsif ($primlibserv ne '') {
1277: my $protocol = $Apache::lonnet::protocol{$primlibserv};
1278: my $hostname = &Apache::lonnet::hostname($primlibserv);
1279: unless ($protocol eq 'https') {
1280: $protocol = 'http';
1281: }
1.116 raeburn 1282: $url = $protocol.'://'.$hostname.'/cgi-bin/listdomconfig.pl?primary='.$primlibserv.'&format=raw';
1.113 raeburn 1283: }
1.104 raeburn 1284: if ($isprimary) {
1285: my $lonusersdir = $perlvar{'lonUsersDir'};
1286: my $fname = $lonusersdir.'/'.$dom.'/configuration.db';
1287: if (-e $fname) {
1288: my $dbref=&LONCAPA::locking_hash_tie($fname,&GDBM_READER());
1289: if (ref($dbref) eq 'HASH') {
1290: foreach my $key (sort(keys(%{$dbref}))) {
1291: my $value = $dbref->{$key};
1292: if ($value =~ s/^__FROZEN__//) {
1293: $value = thaw(&LONCAPA::unescape($value));
1294: } else {
1295: $value = &LONCAPA::unescape($value);
1296: }
1297: $confhash{$key} = $value;
1298: }
1299: &LONCAPA::locking_hash_untie($dbref);
1300: }
1301: }
1302: } else {
1.116 raeburn 1303: my $request=new HTTP::Request('GET',$url);
1304: my $response=&LONCAPA::LWPReq::makerequest($primlibserv,$request,'',\%perlvar,5);
1305: unless ($response->is_error()) {
1306: my $content = $response->content;
1307: if ($content) {
1308: my @pairs=split(/\&/,$content);
1.104 raeburn 1309: foreach my $item (@pairs) {
1310: my ($key,$value)=split(/=/,$item,2);
1311: my $what = &LONCAPA::unescape($key);
1312: if ($value =~ s/^__FROZEN__//) {
1313: $value = thaw(&LONCAPA::unescape($value));
1314: } else {
1315: $value = &LONCAPA::unescape($value);
1316: }
1317: $confhash{$what}=$value;
1318: }
1319: }
1320: }
1321: }
1322: return \%confhash;
1323: }
1324:
1325: sub write_hosttypes {
1326: my %intdom = &Apache::lonnet::all_host_intdom();
1327: my %hostdom = &Apache::lonnet::all_host_domain();
1328: my $dom = $hostdom{$perlvar{'lonHostID'}};
1329: my $internetdom = $intdom{$perlvar{'lonHostID'}};
1.107 raeburn 1330: my %changes;
1.104 raeburn 1331: if (($dom ne '') && ($internetdom ne '')) {
1332: if (keys(%hostdom)) {
1.107 raeburn 1333: my %currhosttypes;
1334: if (open(my $fh,'<',"$perlvar{'lonTabDir'}/hosttypes.tab")) {
1335: while (my $line = <$fh>) {
1336: chomp($line);
1337: my ($name,$value) = split(/:/,$line);
1338: if (($name ne '') && ($value =~ /^(dom|intdom|other)$/)) {
1339: $currhosttypes{$name} = $value;
1340: }
1341: }
1342: close($fh);
1343: }
1344: if (open(my $fh,'>',"$perlvar{'lonTabDir'}/hosttypes.tab")) {
1.104 raeburn 1345: my $count = 0;
1346: foreach my $lonid (sort(keys(%hostdom))) {
1347: my $type = 'other';
1348: if ($hostdom{$lonid} eq $dom) {
1.125 raeburn 1349: $type = 'dom';
1.104 raeburn 1350: } elsif ($intdom{$lonid} eq $internetdom) {
1351: $type = 'intdom';
1352: }
1353: print $fh "$lonid:$type\n";
1.107 raeburn 1354: if (exists($currhosttypes{$lonid})) {
1355: if ($type ne $currhosttypes{$lonid}) {
1356: $changes{$lonid} = 1;
1357: }
1358: } else {
1359: $changes{$lonid} = 1;
1360: }
1.104 raeburn 1361: $count ++;
1362: }
1363: close($fh);
1364: print "Completed writing host type data for $count hosts.\n";
1365: }
1366: } else {
1367: print "Writing of host types skipped - no hosts found.\n";
1368: }
1369: } else {
1370: print "Writing of host types skipped - could not determine this host's LON-CAPA domain or 'internet' domain.\n";
1371: }
1.107 raeburn 1372: return %changes;
1.104 raeburn 1373: }
1374:
1.106 raeburn 1375: sub update_revocation_list {
1.107 raeburn 1376: my ($result,$changed) = &Apache::lonnet::fetch_crl_pemfile();
1377: if ($result eq 'ok') {
1.106 raeburn 1378: print "Certificate Revocation List (from CA) updated.\n";
1379: } else {
1380: print "Certificate Revocation List from (CA) not updated.\n";
1381: }
1.107 raeburn 1382: return $changed;
1383: }
1384:
1385: sub reset_nosslverify_pids {
1.108 raeburn 1386: my ($fh,%sslrem) = @_;
1.107 raeburn 1387: &checkon_daemon($fh,'lond',40000,'USR2');
1388: my $loncpidfile="$perlvar{'lonDaemons'}/logs/lonc.pid";
1389: my $loncppid;
1390: if ((-e $loncpidfile) && (open(my $pfh,'<',$loncpidfile))) {
1391: $loncppid=<$pfh>;
1392: chomp($loncppid);
1393: close($pfh);
1394: if ($loncppid =~ /^\d+$/) {
1395: my %pids_by_host;
1396: my $docdir = $perlvar{'lonDocRoot'};
1397: if (-d "$docdir/lon-status/loncchld") {
1398: if (opendir(my $dh,"$docdir/lon-status/loncchld")) {
1399: while (my $file = readdir($dh)) {
1400: next if ($file =~ /^\./);
1401: if (open(my $fh,'<',"$docdir/lon-status/loncchld/$file")) {
1402: my $record = <$fh>;
1403: chomp($record);
1404: close($fh);
1405: my ($remotehost,$authmode) = split(/:/,$record);
1406: $pids_by_host{$remotehost}{$authmode}{$file} = 1;
1407: }
1408: }
1409: closedir($dh);
1410: if (keys(%pids_by_host)) {
1411: foreach my $host (keys(%pids_by_host)) {
1412: if ($sslrem{$host}) {
1413: if (ref($pids_by_host{$host}) eq 'HASH') {
1414: if (ref($pids_by_host{$host}{'insecure'}) eq 'HASH') {
1.109 raeburn 1415: if (keys(%{$pids_by_host{$host}{'insecure'}})) {
1416: foreach my $pid (keys(%{$pids_by_host{$host}{'insecure'}})) {
1.107 raeburn 1417: if (open(PIPE,"ps -o ppid= -p $pid |")) {
1418: my $ppid = <PIPE>;
1419: chomp($ppid);
1420: close(PIPE);
1421: $ppid =~ s/(^\s+|\s+$)//g;
1422: if (($ppid == $loncppid) && (kill 0 => $pid)) {
1423: kill QUIT => $pid;
1424: }
1425: }
1426: }
1427: }
1428: }
1429: }
1430: }
1431: }
1432: }
1433: }
1434: }
1435: }
1436: }
1437: return;
1.106 raeburn 1438: }
1439:
1.114 raeburn 1440: sub get_permcount_settings {
1441: my ($domconf) = @_;
1442: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
1443: my (%weights,$threshold,$sysmail,$reportstatus,%exclusions);
1444: foreach my $type ('E','W','N','U') {
1445: $weights{$type} = $defaults->{$type};
1446: }
1447: $threshold = $defaults->{'threshold'};
1448: $sysmail = $defaults->{'sysmail'};
1449: $reportstatus = 1;
1450: if (ref($domconf) eq 'HASH') {
1451: if (ref($domconf->{'contacts'}) eq 'HASH') {
1452: if ($domconf->{'contacts'}{'reportstatus'} == 0) {
1453: $reportstatus = 0;
1454: }
1455: if (ref($domconf->{'contacts'}{'lonstatus'}) eq 'HASH') {
1456: if (ref($domconf->{'contacts'}{'lonstatus'}{weights}) eq 'HASH') {
1457: foreach my $type ('E','W','N','U') {
1458: if (exists($domconf->{'contacts'}{'lonstatus'}{weights}{$type})) {
1459: $weights{$type} = $domconf->{'contacts'}{'lonstatus'}{weights}{$type};
1460: }
1461: }
1462: }
1463: if (ref($domconf->{'contacts'}{'lonstatus'}{'excluded'}) eq 'ARRAY') {
1464: my @excluded = @{$domconf->{'contacts'}{'lonstatus'}{'excluded'}};
1465: if (@excluded) {
1466: map { $exclusions{$_} = 1; } @excluded;
1467: }
1468: }
1469: if (exists($domconf->{'contacts'}{'lonstatus'}{'threshold'})) {
1470: $threshold = $domconf->{'contacts'}{'lonstatus'}{'threshold'};
1471: }
1472: if (exists($domconf->{'contacts'}{'lonstatus'}{'sysmail'})) {
1473: $sysmail = $domconf->{'contacts'}{'lonstatus'}{'sysmail'};
1474: }
1475: }
1476: }
1477: }
1478: return ($threshold,$sysmail,$reportstatus,\%weights,\%exclusions);
1479: }
1480:
1481: sub read_serverhomeIDs {
1482: my %server;
1483: if (-e "$perlvar{'lonTabDir'}/serverhomeIDs.tab") {
1484: if (open(my $fh,'<',"$perlvar{'lonTabDir'}/serverhomeIDs.tab")) {
1485: while (<$fh>) {
1486: my($host,$id) = split(/:/);
1487: chomp($id);
1488: $server{$host} = $id;
1489: }
1490: close($fh);
1491: }
1492: }
1493: return %server;
1494: }
1495:
1.46 albertel 1496: sub send_mail {
1.113 raeburn 1497: my ($sysmail,$reportstatus) = @_;
1.79 raeburn 1498: my $defdom = $perlvar{'lonDefDomain'};
1499: my $origmail = $perlvar{'lonAdmEMail'};
1.78 raeburn 1500: my $emailto = &Apache::loncommon::build_recipient_list(undef,
1501: 'lonstatusmail',$defdom,$origmail);
1.113 raeburn 1502: if (($totalcount>$sysmail) && ($reportstatus)) {
1.43 albertel 1503: $emailto.=",$perlvar{'lonSysEMail'}";
1504: }
1.101 raeburn 1505: my $from;
1506: my $hostname=`/bin/hostname`;
1507: chop($hostname);
1508: $hostname=~s/[^\w\.]//g;
1509: if ($hostname) {
1510: $from = 'www@'.$hostname;
1511: }
1512: my $subj="LON: $perlvar{'lonHostID'} E:$errors W:$warnings N:$notices";
1513: my $loncronmail = "To: $emailto\n".
1514: "From: $from\n".
1515: "Subject: ".$subj."\n".
1516: "Content-type: text/html\; charset=UTF-8\n".
1517: "MIME-Version: 1.0\n\n";
1518: if (open(my $fh,"<$statusdir/index.html")) {
1519: while (<$fh>) {
1520: $loncronmail .= $_;
1521: }
1522: close($fh);
1523: } else {
1524: $loncronmail .= "Failed to read from http://$hostname/lon-status/index.html\n";
1525: }
1526: $loncronmail .= "\n\n";
1527: if (open(my $mailh, "|/usr/lib/sendmail -oi -t -odb")) {
1528: print $mailh $loncronmail;
1529: close($mailh);
1530: print "Sending mail.\n";
1531: } else {
1532: print "Sending mail failed.\n";
1.52 albertel 1533: }
1.1 albertel 1534: }
1.46 albertel 1535:
1.49 albertel 1536: sub usage {
1537: print(<<USAGE);
1.100 bisitz 1538: loncron - housekeeping program that checks up on various parts of LON-CAPA
1.49 albertel 1539:
1540: Options:
1.71 albertel 1541: --help Display
1.49 albertel 1542: --noemail Do not send the status email
1543: --justcheckconnections Only check the current status of the lonc/d
1544: connections, do not send emails do not
1545: check if the daemons are running, do not
1546: generate lon-status
1547: --justcheckdaemons Only check that all of the Lon-CAPA daemons are
1548: running, do not send emails do not
1549: check the lonc/d connections, do not
1550: generate lon-status
1.59 albertel 1551: --justreload Only tell the daemons to reload the config files,
1552: do not send emails do not
1553: check if the daemons are running, do not
1554: generate lon-status
1.118 raeburn 1555: --justiptables Only update the dynamic iptables rules for the
1556: lond port; do not send emails, do not
1557: check if the daemons are running, do not
1558: generate lon-status
1.49 albertel 1559: USAGE
1560: }
1561:
1.46 albertel 1562: # ================================================================ Main Program
1563: sub main () {
1.71 albertel 1564: my ($help,$justcheckdaemons,$noemail,$justcheckconnections,
1.118 raeburn 1565: $justreload,$justiptables);
1.49 albertel 1566: &GetOptions("help" => \$help,
1567: "justcheckdaemons" => \$justcheckdaemons,
1568: "noemail" => \$noemail,
1.59 albertel 1569: "justcheckconnections" => \$justcheckconnections,
1.118 raeburn 1570: "justreload" => \$justreload,
1571: "justiptables" => \$justiptables
1.49 albertel 1572: );
1573: if ($help) { &usage(); return; }
1.46 albertel 1574: # --------------------------------- Read loncapa_apache.conf and loncapa.conf
1575: my $perlvarref=LONCAPA::Configuration::read_conf('loncapa.conf');
1576: %perlvar=%{$perlvarref};
1577: undef $perlvarref;
1578: delete $perlvar{'lonReceipt'}; # remove since sensitive and not needed
1579: delete $perlvar{'lonSqlAccess'}; # remove since sensitive and not needed
1.75 albertel 1580: chdir($perlvar{'lonDaemons'});
1.46 albertel 1581: # --------------------------------------- Make sure that LON-CAPA is configured
1582: # I only test for one thing here (lonHostID). This is just a safeguard.
1583: if ('{[[[[lonHostID]]]]}' eq $perlvar{'lonHostID'}) {
1584: print("Unconfigured machine.\n");
1585: my $emailto=$perlvar{'lonSysEMail'};
1.123 raeburn 1586: my $hostname = Sys::Hostname::FQDN::fqdn();
1587: $hostname=~s/\.+/./g;
1588: $hostname=~s/\-+/-/g;
1589: $hostname=~s/[^\w\.-]//g; # make sure is safe to pass through shell
1.46 albertel 1590: my $subj="LON: Unconfigured machine $hostname";
1.112 raeburn 1591: system("echo 'Unconfigured machine $hostname.' |".
1592: " mail -s '$subj' $emailto > /dev/null");
1.46 albertel 1593: exit 1;
1594: }
1595:
1596: # ----------------------------- Make sure this process is running from user=www
1597: my $wwwid=getpwnam('www');
1598: if ($wwwid!=$<) {
1.100 bisitz 1599: print("User ID mismatch. This program must be run as user 'www'.\n");
1.46 albertel 1600: my $emailto="$perlvar{'lonAdmEMail'},$perlvar{'lonSysEMail'}";
1601: my $subj="LON: $perlvar{'lonHostID'} User ID mismatch";
1.112 raeburn 1602: system("echo 'User ID mismatch. loncron must be run as user www.' |".
1603: " mail -s '$subj' $emailto > /dev/null");
1.46 albertel 1604: exit 1;
1605: }
1606:
1.72 albertel 1607: # -------------------------------------------- Force reload of host information
1.103 raeburn 1608: my $nomemcache;
1609: if ($justcheckdaemons) {
1610: $nomemcache=1;
1611: my $memcachepidfile="$perlvar{'lonDaemons'}/logs/memcached.pid";
1612: my $memcachepid;
1613: if (-e $memcachepidfile) {
1614: my $memfh=IO::File->new($memcachepidfile);
1615: $memcachepid=<$memfh>;
1616: chomp($memcachepid);
1617: if ($memcachepid =~ /^\d+$/ && kill 0 => $memcachepid) {
1618: undef($nomemcache);
1619: }
1620: }
1621: }
1.118 raeburn 1622: if (!$justiptables) {
1623: &Apache::lonnet::load_hosts_tab(1,$nomemcache);
1624: &Apache::lonnet::load_domain_tab(1,$nomemcache);
1625: &Apache::lonnet::get_iphost(1,$nomemcache);
1626: }
1.46 albertel 1627:
1.125 raeburn 1628: # ----------------------------------------- Force firewall update for lond port
1.81 raeburn 1629:
1630: if ((!$justcheckdaemons) && (!$justreload)) {
1631: my $now = time;
1632: my $tmpfile = $perlvar{'lonDaemons'}.'/tmp/lciptables_iphost_'.
1633: $now.$$.int(rand(10000));
1634: if (open(my $fh,">$tmpfile")) {
1635: my %iphosts = &Apache::lonnet::get_iphost();
1636: foreach my $key (keys(%iphosts)) {
1637: print $fh "$key\n";
1638: }
1639: close($fh);
1.89 raeburn 1640: if (&LONCAPA::try_to_lock('/tmp/lock_lciptables')) {
1641: my $execpath = $perlvar{'lonDaemons'}.'/lciptables';
1642: system("$execpath $tmpfile");
1.125 raeburn 1643: unlink('/tmp/lock_lciptables'); # Remove the lock file.
1.89 raeburn 1644: }
1.88 raeburn 1645: unlink($tmpfile);
1.81 raeburn 1646: }
1647: }
1648:
1.46 albertel 1649: # ---------------------------------------------------------------- Start report
1650:
1651: $errors=0;
1652: $warnings=0;
1653: $notices=0;
1654:
1.125 raeburn 1655:
1.49 albertel 1656: my $fh;
1.118 raeburn 1657: if (!$justcheckdaemons && !$justcheckconnections && !$justreload && !$justiptables) {
1.72 albertel 1658: $fh=&start_logging();
1.49 albertel 1659:
1660: &log_machine_info($fh);
1661: &clean_tmp($fh);
1662: &clean_lonIDs($fh);
1.115 raeburn 1663: &clean_balanceIDs($fh);
1.102 raeburn 1664: &clean_webDAV_sessionIDs($fh);
1.119 raeburn 1665: &clean_ltiIDs($fh);
1.49 albertel 1666: &check_httpd_logs($fh);
1667: &rotate_lonnet_logs($fh);
1.73 albertel 1668: &rotate_other_logs($fh);
1.49 albertel 1669: }
1.118 raeburn 1670: if (!$justcheckconnections && !$justreload && !$justiptables) {
1.76 albertel 1671: &checkon_daemon($fh,'lonmemcached',40000);
1.49 albertel 1672: &checkon_daemon($fh,'lonsql',200000);
1.63 albertel 1673: if ( &checkon_daemon($fh,'lond',40000,'USR1') eq 'running') {
1674: &checkon_daemon($fh,'lond',40000,'USR2');
1675: }
1.71 albertel 1676: &checkon_daemon($fh,'lonc',40000,'USR1');
1.70 raeburn 1677: &checkon_daemon($fh,'lonmaxima',40000);
1.80 www 1678: &checkon_daemon($fh,'lonr',40000);
1.49 albertel 1679: }
1.59 albertel 1680: if ($justreload) {
1.107 raeburn 1681: &clean_nosslverify($fh);
1.104 raeburn 1682: &write_connection_config();
1683: &write_hosttypes();
1.107 raeburn 1684: &update_revocation_list();
1.59 albertel 1685: &checkon_daemon($fh,'lond',40000,'USR2');
1.71 albertel 1686: &checkon_daemon($fh,'lonc',40000,'USR2');
1.59 albertel 1687: }
1.63 albertel 1688: if ($justcheckconnections) {
1.72 albertel 1689: &test_connections($fh);
1.49 albertel 1690: }
1.118 raeburn 1691: if (!$justcheckdaemons && !$justcheckconnections && !$justreload && !$justiptables) {
1.114 raeburn 1692: my $domconf = &get_domain_config();
1693: my ($threshold,$sysmail,$reportstatus,$weightsref,$exclusionsref) =
1694: &get_permcount_settings($domconf);
1695: &check_delayed_msg($fh,$weightsref,$exclusionsref);
1.87 raeburn 1696: &write_loncaparevs();
1697: &write_serverhomeIDs();
1.97 raeburn 1698: &write_checksums();
1.117 raeburn 1699: &write_hostips();
1.107 raeburn 1700: my %sslrem = &clean_nosslverify($fh);
1701: my %conchgs = &write_connection_config();
1702: my %hosttypechgs = &write_hosttypes();
1703: my $hadcrlchg = &update_revocation_list();
1.108 raeburn 1704: if ((keys(%conchgs) > 0) || (keys(%hosttypechgs) > 0) ||
1.107 raeburn 1705: $hadcrlchg || (keys(%sslrem) > 0)) {
1706: &checkon_daemon($fh,'lond',40000,'USR2');
1.108 raeburn 1707: &reset_nosslverify_pids($fh,%sslrem);
1.107 raeburn 1708: }
1.114 raeburn 1709: &finish_logging($fh,$weightsref);
1710: &log_simplestatus();
1711: if ($totalcount>$threshold && !$noemail) { &send_mail($sysmail,$reportstatus); }
1.49 albertel 1712: }
1.46 albertel 1713: }
1714:
1715: &main();
1.1 albertel 1716: 1;
1717:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>