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