Hi!
Trying to use mod_perl for a perl module to load a bunch of data on
server startup and writing possible changes back to disk on server
shutdown leads me to strange behaviour in the END { } block: The END
block is aborted, before all checking and writing is done. Therefore
the files on disk are not consistent (partly written, not in sync
etc.).
Works fine under mod_cgi - but new reading and writing at every
request is of cause NOT, what we want.
I could isolate and reproduce it:
Nothing defined for mod_perl in httpd.conf except:
PerlRequire /home/ernest/lib/start-up.pl
The startup.pl:
---
>--snip--
#!/usr/bin/perl -w
use strict;
# extend @INC if needed
use lib qw ( /home/ernest/lib );
# make sure we are in a sane environment.
$ENV{GATEWAY_INTERFACE} =~ /^CGI-Perl/
or die "GATEWAY_INTERFACE not Perl!";
# for things in the "/perl" URL
use Apache::Registry;
#load perl modules of your choice here
#this code is interpreted *once* when the server starts
use Apache::Status;
# tell me more about warnings
use Carp ();
$SIG{__WARN__} = \&Carp::cluck;
use MYMOD ();
1;
>--snip--
Module MYMOD:
-
>--snip--
#
# This Module simulates a lengthy END block...
#
package MYMOD;
use strict;
use English;
# SUBS
sub debug_log {
print STDERR '[', scalar ( localtime ), '] [debug] child=', $PID, ' ',
__PACKAGE__, @_, "\n";
}
#
# time consuming cleanup...
#
END {
debug_log ( '::END start' );
my $m = 60; # sec
my $i = $m;
while ( $i > 0 ) {
debug_log ( '::END ', $m - $i, ' of ', $m, ' sec' );
sleep 1;
$i--;
}
debug_log ( '::END done' );
}
1;
__END__
>--snip--
Starting Apache with:
/usr/local/apache/bin/httpd -X -f /home/ernest/conf/httpd.conf
and killing with ^C gives the wanted result in the error.log:
[Mon Oct 16 19:36:08 2000] [info] created shared memory segment #12417
[Mon Oct 16 19:38:17 2000] [debug] child=1507 MYMOD::END start
[Mon Oct 16 19:38:17 2000] [debug] child=1507 MYMOD::END 0 of 60 sec
[Mon Oct 16 19:38:18 2000] [debug] child=1507 MYMOD::END 1 of 60 sec
[Mon Oct 16 19:38:19 2000] [debug] child=1507 MYMOD::END 2 of 60 sec
[Mon Oct 16 19:38:20 2000] [debug] child=1507 MYMOD::END 3 of 60 sec
...
[Mon Oct 16 19:39:15 2000] [debug] child=1507 MYMOD::END 58 of 60 sec
[Mon Oct 16 19:39:16 2000] [debug] child=1507 MYMOD::END 59 of 60 sec
[Mon Oct 16 19:39:17 2000] [debug] child=1507 MYMOD::END done
Same with mod_cgi using a little cgi-skript just to load the module.
Starting Apache with:
/usr/local/apache/bin/httpd -f /home/ernest/conf/httpd.conf
starts the wanted 20 Servers with the shared module.
Shutting down with a little shell script containing:
PID=`cat $PIDFILE`
kill -15 $PID
shows the abortion in the error.log:
[Mon Oct 16 18:10:40 2000] [info] created shared memory segment #12289
[Mon Oct 16 18:10:40 2000] [notice] Apache/1.3.12 (Unix) mod_perl/1.24 PHP/4.0.2
FrontPage/4.0.4.3 mod_ssl/2.6.5 OpenSSL/0.9.5a configured -- resuming normal operations
[Mon Oct 16 18:10:40 2000] [info] Server built: Sep 22 2000 19:19:57
[Mon Oct 16 18:11:30 2000] [debug] child=32700 MYMOD::END start
[Mon Oct 16 18:11:30 2000] [debug] child=32700 MYMOD::END 0 of 60 sec
[Mon Oct 16 18:11:30 2000] [debug] child=32699 MYMOD::END start
[Mon Oct 16 18:11:30 2000] [debug] child=32699 MYMOD::END 0 of 60 sec
... 40 lines ...
[Mon Oct 16 18:11:31 2000] [debug] child=32700 MYMOD::END 1 of 60 sec
[Mon Oct 16 18:11:31 2000] [debug] child=32698 MYMOD::END 1 of 60 sec
[Mon Oct 16 18:11:31 2000] [debug] child=32699 MYMOD::END 1 of 60 sec
... 20 lines ...
[Mon Oct 16 18:11:32 2000] [warn] child process 32681 still did not exit, sending a
SIGTERM
[Mon Oct 16 18:11:32 2000] [warn] child process 32682 still did not exit, sending a
SIGTERM
... 20 lines ...
[Mon Oct 16 18:11:32 2000] [debug] child=32700 MYMOD::END 2 of 60 sec
... 80 lines ...
[Mon Oct 16 18:11:35 2000] [debug] child=32682 MYMOD::END 5 of 60 sec
[Mon Oct 16 18:11:36 2000] [error] child process 32681 still did not exit, sending a
SIGKILL
[Mon Oct 16 18:11:36 2000] [error] child process 32682 still did not exit, sending a
SIGKILL
... 20 lines ...
[Mon Oct 16 18:11:36 2000] [info] removed PID file /home/ernest/logs/httpd.pid
(pid=32679)
[Mon Oct 16 18:11:36 2000] [notice] caught SIGTERM, shutting down
Additional info:
perl -V
---
Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration:
Platform:
osname=linux, osvers=2.2.5-22smp, archname=i386-linux
uname='linux porky.devel.redhat.com 2.2.5-22smp #1 smp wed jun 2 09:11:51 edt 1999
i686 unknown '
hint=recommended, useposix=true, d_sigaction=define
usethreads=undef useperlio=undef d_sfio=undef
Compiler:
cc='cc', optimize='-O2 -m486 -fno-strength-reduce', gccversion=egcs-2.91.66
19990314/Linux (egcs-1.1.2 release)
cppflags='-Dbool=char -DHAS_BOOL -I/usr/local/include'
c