--- loncom/loncron 2006/10/25 21:33:54 1.68 +++ loncom/loncron 2014/03/17 14:47:38 1.100 @@ -2,7 +2,7 @@ # Housekeeping program, started by cron, loncontrol and loncron.pl # -# $Id: loncron,v 1.68 2006/10/25 21:33:54 www Exp $ +# $Id: loncron,v 1.100 2014/03/17 14:47:38 bisitz Exp $ # # Copyright Michigan State University Board of Trustees # @@ -32,6 +32,10 @@ use strict; use lib '/home/httpd/lib/perl/'; use LONCAPA::Configuration; +use LONCAPA::Checksumming; +use LONCAPA; +use Apache::lonnet; +use Apache::loncommon; use IO::File; use IO::Socket; @@ -43,21 +47,6 @@ use vars qw (%perlvar %simplestatus $err my $statusdir="/home/httpd/html/lon-status"; -# -------------------------------------------------- Non-critical communication -sub reply { - my ($cmd,$server,$hostname)=@_; - my $peerfile="$perlvar{'lonSockDir'}/".$hostname->{$server}; - my $client=IO::Socket::UNIX->new(Peer =>"$peerfile", - Type => SOCK_STREAM, - Timeout => 10) - or return "con_lost"; - print $client "sethost:$server:$cmd\n"; - my $answer=<$client>; - chomp($answer); - if (!$answer) { $answer="con_lost"; } - return $answer; -} - # --------------------------------------------------------- Output error status sub log { @@ -76,20 +65,27 @@ sub errout { ENDERROUT } +sub rotate_logfile { + my ($file,$fh,$description) = @_; + my $size=(stat($file))[7]; + if ($size>40000) { + &log($fh,"
Rotating $description ...
"); + rename("$file.2","$file.3"); + rename("$file.1","$file.2"); + rename("$file","$file.1"); + } +} + sub start_daemon { my ($fh,$daemon,$pidfile,$args) = @_; my $progname=$daemon; - if ($daemon eq 'lonc' && $args eq 'new') { + if ($daemon eq 'lonc') { $progname='loncnew'; - print "new "; } my $error_fname="$perlvar{'lonDaemons'}/logs/${daemon}_errors"; - my $size=(stat($error_fname))[7]; - if ($size>40000) { - &log($fh,"Rotating error logs ...
"); - rename("$error_fname.2","$error_fname.3"); - rename("$error_fname.1","$error_fname.2"); - rename("$error_fname","$error_fname.1"); + &rotate_logfile($error_fname,$fh,'error logs'); + if ($daemon eq 'lonc') { + &clean_sockets($fh); } system("$perlvar{'lonDaemons'}/$progname 2>$perlvar{'lonDaemons'}/logs/${daemon}_errors"); sleep 1; @@ -208,18 +204,7 @@ sub checkon_daemon { } my $fname="$perlvar{'lonDaemons'}/logs/$daemon.log"; - - my ($dev,$ino,$mode,$nlink, - $uid,$gid,$rdev,$size, - $atime,$mtime,$ctime, - $blksize,$blocks)=stat($fname); - - if ($size>$maxsize) { - &log($fh,"Rotating logs ...
"); - rename("$fname.2","$fname.3"); - rename("$fname.1","$fname.2"); - rename("$fname","$fname.1"); - } + &rotate_logfile($fname,$fh,'logs'); &errout($fh); return $result; @@ -286,19 +271,13 @@ sub log_machine_info { &log($fh,""); - open(DSH,"$perlvar{'lonDaemons'}/distprobe |"); - while (my $line="); &errout($fh); } sub start_logging { - my ($hostdom,$hostrole,$hostname,$spareid)=@_; my $fh=IO::File->new(">$statusdir/newstatus.html"); my %simplestatus=(); my $now=time; @@ -323,7 +302,6 @@ sub start_logging {) { - &log($fh,&encode_entities($line,'<>&"')); - $psproc++; - } - close(DSH); + &log($fh,&encode_entities(&LONCAPA::distro(),'<>&"')); &log($fh,"
$id | ".$hostdom->{$id}. - " | ".$hostrole->{$id}. - " | ".$hostname->{$id}." |
Cleaned up ".$cleaned." stale sockets.
"); +} + # ----------------------------------------------------------------------- httpd sub check_httpd_logs { my ($fh)=@_; - &log($fh,''); - - open (DFH,"tail -n25 /etc/httpd/logs/access_log|"); - while (my $line=) { &log($fh,&encode_entities($line,'<>&"')) }; - close (DFH); - - &log($fh,"
"); - - open (DFH,"tail -n25 /etc/httpd/logs/error_log|"); - while (my $line="); &errout($fh); } @@ -440,7 +526,7 @@ sub check_httpd_logs { sub rotate_lonnet_logs { my ($fh)=@_; &log($fh,') { - &log($fh,"$line"); - if ($line=~/\[error\]/) { $notices++; } + if (open(PIPE,"./lchttpdlogs|")) { + while (my $line= ) { + &log($fh,$line); + if ($line=~/\[error\]/) { $notices++; } + } + close(PIPE); } - close (DFH); - &log($fh,"
'); - print "checking logs\n"; + print "Checking logs.\n"; if (-e "$perlvar{'lonDaemons'}/logs/lonnet.log"){ open (DFH,"tail -n50 $perlvar{'lonDaemons'}/logs/lonnet.log|"); while (my $line="); &errout($fh); } +sub rotate_other_logs { + my ($fh) = @_; + my %logs = ( + autoenroll => 'Auto Enroll log', + autocreate => 'Create Course log', + searchcat => 'Search Cataloguing log', + autoupdate => 'Auto Update log', + refreshcourseids_db => 'Refresh CourseIDs db log', + ); + foreach my $item (keys(%logs)) { + my $fname=$perlvar{'lonDaemons'}.'/logs/'.$item.'.log'; + &rotate_logfile($fname,$fh,$logs{$item}); + } +} + # ----------------------------------------------------------------- Connections sub test_connections { - my ($fh,$hostname)=@_; + my ($fh)=@_; &log($fh,') { @@ -459,34 +545,39 @@ sub rotate_lonnet_logs { } else { &log($fh,"No perm log\n") } my $fname="$perlvar{'lonDaemons'}/logs/lonnet.log"; - - my ($dev,$ino,$mode,$nlink, - $uid,$gid,$rdev,$size, - $atime,$mtime,$ctime, - $blksize,$blocks)=stat($fname); - - if ($size>40000) { - &log($fh," Rotating logs ...
"); - rename("$fname.2","$fname.3"); - rename("$fname.1","$fname.2"); - rename("$fname","$fname.1"); - } + &rotate_logfile($fname,$fh,'lonnet log'); &log($fh,"