--- loncom/lond 2001/12/22 21:46:02 1.62 +++ loncom/lond 2002/02/05 18:05:47 1.66 @@ -2,7 +2,7 @@ # The LearningOnline Network # lond "LON Daemon" Server (port "LOND" 5663) # -# $Id: lond,v 1.62 2001/12/22 21:46:02 www Exp $ +# $Id: lond,v 1.66 2002/02/05 18:05:47 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -46,7 +46,8 @@ # 11/26,11/27 Gerd Kortemeyer # 12/20 Scott Harrison # 12/22 Gerd Kortemeyer -# +# YEAR=2002 +# 01/20/02,02/05 Gerd Kortemeyer ### # based on "Perl Cookbook" ISBN 1-56592-243-3 @@ -84,6 +85,10 @@ sub catchexception { die($error); } +sub timeout { + &logthis("CRITICAL: TIME OUT ".$$.""); + &catchexception('Timeout'); +} # -------------------------------- Set signal handlers to record abnormal exits $SIG{'QUIT'}=\&catchexception; @@ -187,6 +192,7 @@ sub checkchildren { &initnewstatus(); &logstatus(); &logthis('Going to check on the children'); + $docdir=$perlvar{'lonDocRoot'}; foreach (sort keys %children) { sleep 1; unless (kill 'USR1' => $_) { @@ -194,6 +200,19 @@ sub checkchildren { &logstatus($$.' is dead'); } } + sleep 5; + foreach (sort keys %children) { + unless (-e "$docdir/lon-status/londchld/$_.txt") { + &logthis('Child '.$_.' did not respond'); + kill 9 => $_; + $emailto="$perlvar{'lonAdmEMail'},$perlvar{'lonSysEMail'}"; + $subj="LON: $perlvar{'lonHostID'} killed lond process $_"; + system("echo 'Killed lond process $_.' |\ + mailto $emailto -s '$subj' > /dev/null"); + $execdir=$perlvar{'lonDaemons'}; + system("cp $execdir/logs/lond.log $execdir/logs/lond.log.".$_); + } + } } # --------------------------------------------------------------------- Logging @@ -212,8 +231,16 @@ sub logthis { sub logstatus { my $docdir=$perlvar{'lonDocRoot'}; + { my $fh=IO::File->new(">>$docdir/lon-status/londstatus.txt"); print $fh $$."\t".$status."\t".$lastlog."\n"; + $fh->close(); + } + { + my $fh=IO::File->new(">$docdir/lon-status/londchld/$$.txt"); + print $fh $status."\n".$lastlog."\n".time; + $fh->close(); + } } sub initnewstatus { @@ -222,6 +249,11 @@ sub initnewstatus { my $now=time; my $local=localtime($now); print $fh "LOND status $local - parent $$\n\n"; + opendir(DIR,"$docdir/lon-status/londchld"); + while ($filename=readdir(DIR)) { + unlink("$docdir/lon-status/londchld/$filename"); + } + closedir(DIR); } # -------------------------------------------------------------- Status setting @@ -431,6 +463,7 @@ sub make_new_child { # Child can *not* return from this subroutine. $SIG{INT} = 'DEFAULT'; # make SIGINT kill us as it did before $SIG{USR1}= \&logstatus; + $SIG{ALRM}= \&timeout; $lastlog='Forked '; $status='Forked'; @@ -499,6 +532,7 @@ sub make_new_child { chomp($userinput); &status('Processing '.$hostid{$clientip}.': '.$userinput); my $wasenc=0; + alarm(120); # ------------------------------------------------------------ See if encrypted if ($userinput =~ /^enc/) { if ($cipher) { @@ -677,7 +711,7 @@ sub make_new_child { $fpnow.='/'.$fpparts[$i]; unless (-e $fpnow) { unless (mkdir($fpnow,0777)) { - $fperror="error:$!\n"; + $fperror="error:$!"; } } } @@ -1335,6 +1369,7 @@ sub make_new_child { print $client "unknown_cmd\n"; } # -------------------------------------------------------------------- complete + alarm(0); &status('Listening to '.$hostid{$clientip}); } # --------------------------------------------- client unknown or fishy, refuse