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