version 1.2, 2006/03/03 22:35:09
|
version 1.3, 2006/03/03 23:25:47
|
Line 30
|
Line 30
|
# http://www.lon-capa.org/ |
# http://www.lon-capa.org/ |
# |
# |
|
|
# global variables |
|
$PREFORK = 5; # number of children to maintain |
|
$MAX_CLIENTS_PER_CHILD = 5; # number of clients each child should process |
|
%children = (); # keys are current child process IDs |
|
$children = 0; # current number of children |
|
|
|
use IPC::Open3; |
use IPC::Open3; |
use IO::Select; |
use IO::Select; |
Line 45 use POSIX;
|
Line 40 use POSIX;
|
use lib '/home/httpd/lib/perl/'; |
use lib '/home/httpd/lib/perl/'; |
use LONCAPA::Configuration; |
use LONCAPA::Configuration; |
|
|
# Scary: cannot use strict!!! |
use strict; |
##### use strict; |
|
|
# global variables |
|
my $PREFORK = 5; # number of children to maintain |
|
my $MAX_CLIENTS_PER_CHILD = 5; # number of clients each child should process |
|
my %children = (); # keys are current child process IDs |
|
my $children = 0; # current number of children |
|
my $status; # string for current status |
|
|
|
use vars qw($PREFORK $MAX_CLIENTS_PER_CHILD %children $children $status |
|
$cmd_in $cmd_out $cmd_err $pidfile $port %perlvar $lastlog |
|
$currenthostid $client $server $cmd |
|
); |
|
|
sub maximareply { |
sub maximareply { |
my $cmd=shift; |
my $cmd=shift; |
Line 167 $SIG{__DIE__}=\&catchexception;
|
Line 173 $SIG{__DIE__}=\&catchexception;
|
|
|
# ---------------------------------- Read loncapa_apache.conf and loncapa.conf |
# ---------------------------------- Read loncapa_apache.conf and loncapa.conf |
&status("Read loncapa.conf and loncapa_apache.conf"); |
&status("Read loncapa.conf and loncapa_apache.conf"); |
my $perlvarref=LONCAPA::Configuration::read_conf('loncapa.conf'); |
%perlvar=%{&LONCAPA::Configuration::read_conf('loncapa.conf')}; |
%perlvar=%{$perlvarref}; |
|
undef $perlvarref; |
|
|
|
# ----------------------------- Make sure this process is running from user=www |
# ----------------------------- Make sure this process is running from user=www |
my $wwwid=getpwnam('www'); |
my $wwwid=getpwnam('www'); |
Line 247 $SIG{INT} = $SIG{TERM} = \&HUNTSMAN;
|
Line 251 $SIG{INT} = $SIG{TERM} = \&HUNTSMAN;
|
while (1) { |
while (1) { |
&status('Parent process, sleeping'); |
&status('Parent process, sleeping'); |
sleep; # wait for a signal (i.e., child's death) |
sleep; # wait for a signal (i.e., child's death) |
for ($i = $children; $i < $PREFORK; $i++) { |
for (my $i = $children; $i < $PREFORK; $i++) { |
&status('Parent process, starting child'); |
&status('Parent process, starting child'); |
make_new_child( ); # top up the child pool |
make_new_child( ); # top up the child pool |
} |
} |
Line 280 sub make_new_child {
|
Line 284 sub make_new_child {
|
or die "Can't unblock SIGINT for fork: $!\n"; |
or die "Can't unblock SIGINT for fork: $!\n"; |
|
|
# handle connections until we've reached $MAX_CLIENTS_PER_CHILD |
# handle connections until we've reached $MAX_CLIENTS_PER_CHILD |
for ($i=0; $i < $MAX_CLIENTS_PER_CHILD; $i++) { |
for (my $i=0; $i < $MAX_CLIENTS_PER_CHILD; $i++) { |
&status('Accepting connections'); |
&status('Accepting connections'); |
$client = $server->accept( ) or last; |
$client = $server->accept( ) or last; |
while ($cmd=<$client>) { |
while ($cmd=<$client>) { |