[LON-CAPA-cvs] cvs: loncom / lonsql
matthew
lon-capa-cvs@mail.lon-capa.org
Tue, 13 Aug 2002 19:40:57 -0000
matthew Tue Aug 13 15:40:57 2002 EDT
Modified files:
/loncom lonsql
Log:
This appears to work, but frankly I wouldn't trust it. Fixed enough of the
errors that it runs, forks, and returns search results. Theoretically, it
should also do the logfile searches, too.
Index: loncom/lonsql
diff -u loncom/lonsql:1.51 loncom/lonsql:1.52
--- loncom/lonsql:1.51 Tue Aug 6 09:48:47 2002
+++ loncom/lonsql Tue Aug 13 15:40:57 2002
@@ -3,7 +3,7 @@
# The LearningOnline Network
# lonsql - LON TCP-MySQL-Server Daemon for handling database requests.
#
-# $Id: lonsql,v 1.51 2002/08/06 13:48:47 matthew Exp $
+# $Id: lonsql,v 1.52 2002/08/13 19:40:57 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -116,76 +116,6 @@
my %children = (); # keys are current child process IDs
my $children = 0; # current number of children
-########################################################
-########################################################
-
-=pod
-
-=item Functions required for forking
-
-=over 4
-
-=item REAPER
-
-REAPER takes care of dead children.
-
-=item HUNTSMAN
-
-Signal handler for SIGINT.
-
-=item HUPSMAN
-
-Signal handler for SIGHUP
-
-=item DISCONNECT
-
-Disconnects from database.
-
-=back
-
-=cut
-
-########################################################
-########################################################
-sub REAPER { # takes care of dead children
- $SIG{CHLD} = \&REAPER;
- my $pid = wait;
- $children --;
- &logthis("Child $pid died");
- delete $children{$pid};
-}
-
-sub HUNTSMAN { # signal handler for SIGINT
- local($SIG{CHLD}) = 'IGNORE'; # we're going to kill our children
- kill 'INT' => keys %children;
- my $execdir=$perlvar{'lonDaemons'};
- unlink("$execdir/logs/lonsql.pid");
- &logthis("<font color=red>CRITICAL: Shutting down</font>");
- $unixsock = "mysqlsock";
- my $port="$perlvar{'lonSockDir'}/$unixsock";
- unlink($port);
- exit; # clean up with dignity
-}
-
-sub HUPSMAN { # signal handler for SIGHUP
- local($SIG{CHLD}) = 'IGNORE'; # we're going to kill our children
- kill 'INT' => keys %children;
- close($server); # free up socket
- &logthis("<font color=red>CRITICAL: Restarting</font>");
- my $execdir=$perlvar{'lonDaemons'};
- $unixsock = "mysqlsock";
- my $port="$perlvar{'lonSockDir'}/$unixsock";
- unlink($port);
- exec("$execdir/lonsql"); # here we go again
-}
-
-sub DISCONNECT {
- $dbh->disconnect or
- &logthis("<font color=blue>WARNING: Couldn't disconnect from database ".
- " $DBI::errstr : $@</font>");
- exit;
-}
-
###################################################################
###################################################################
@@ -241,6 +171,7 @@
} else {
$dbh->disconnect;
}
+
#
# Check if other instance running
#
@@ -251,6 +182,7 @@
chomp($pide);
if (kill 0 => $pide) { die "already running"; }
}
+
#
# Read hosts file
#
@@ -268,6 +200,7 @@
close(CONFIG);
#
$PREFORK=int($PREFORK/4);
+
#
# Create a socket to talk to lond
#
@@ -280,14 +213,15 @@
Listen => 10)) {
print "in socket error:$@\n";
}
-########################################################
-########################################################
+
#
# Fork once and dissociate
+#
my $fpid=fork;
exit if $fpid;
die "Couldn't fork: $!" unless defined ($fpid);
POSIX::setsid() or die "Can't start new session: $!";
+
#
# Write our PID on disk
my $execdir=$perlvar{'lonDaemons'};
@@ -295,6 +229,7 @@
print PIDSAVE "$$\n";
close(PIDSAVE);
&logthis("<font color=red>CRITICAL: ---------- Starting ----------</font>");
+
#
# Ignore signals generated during initial startup
$SIG{HUP}=$SIG{USR1}='IGNORE';
@@ -303,11 +238,13 @@
for (1 .. $PREFORK) {
make_new_child();
}
+
#
# Install signal handlers.
$SIG{CHLD} = \&REAPER;
$SIG{INT} = $SIG{TERM} = \&HUNTSMAN;
$SIG{HUP} = \&HUPSMAN;
+
#
# And maintain the population.
while (1) {
@@ -586,7 +523,7 @@
sub logthis {
my $message=shift;
my $execdir=$perlvar{'lonDaemons'};
- my $fh=IO::File->new(">>$execdir/logs/lonsqlfinal.log");
+ my $fh=IO::File->new(">>$execdir/logs/lonsql.log");
my $now=time;
my $local=localtime($now);
print $fh "$local ($$): $message\n";
@@ -872,6 +809,76 @@
}
close IN;
return join('&',sort(@results));
+}
+
+########################################################
+########################################################
+
+=pod
+
+=item Functions required for forking
+
+=over 4
+
+=item REAPER
+
+REAPER takes care of dead children.
+
+=item HUNTSMAN
+
+Signal handler for SIGINT.
+
+=item HUPSMAN
+
+Signal handler for SIGHUP
+
+=item DISCONNECT
+
+Disconnects from database.
+
+=back
+
+=cut
+
+########################################################
+########################################################
+sub REAPER { # takes care of dead children
+ $SIG{CHLD} = \&REAPER;
+ my $pid = wait;
+ $children --;
+ &logthis("Child $pid died");
+ delete $children{$pid};
+}
+
+sub HUNTSMAN { # signal handler for SIGINT
+ local($SIG{CHLD}) = 'IGNORE'; # we're going to kill our children
+ kill 'INT' => keys %children;
+ my $execdir=$perlvar{'lonDaemons'};
+ unlink("$execdir/logs/lonsql.pid");
+ &logthis("<font color=red>CRITICAL: Shutting down</font>");
+ $unixsock = "mysqlsock";
+ my $port="$perlvar{'lonSockDir'}/$unixsock";
+ unlink($port);
+ exit; # clean up with dignity
+}
+
+sub HUPSMAN { # signal handler for SIGHUP
+ local($SIG{CHLD}) = 'IGNORE'; # we're going to kill our children
+ kill 'INT' => keys %children;
+ close($server); # free up socket
+ &logthis("<font color=red>CRITICAL: Restarting</font>");
+ my $execdir=$perlvar{'lonDaemons'};
+ $unixsock = "mysqlsock";
+ my $port="$perlvar{'lonSockDir'}/$unixsock";
+ unlink($port);
+ exec("$execdir/lonsql"); # here we go again
+}
+
+sub DISCONNECT {
+ $dbh->disconnect or
+ &logthis("<font color=blue>WARNING: Couldn't disconnect from database ".
+ " $DBI::errstr : $@</font>");
+ exit;
}