Re: END block aborted during httpd shutdown

2000-12-21 Thread Doug MacEachern

On Wed, 18 Oct 2000, Ernest Lergon wrote:

> Dear list members, dear Doug,
> 
> it seems to me, that my initial mail of this thread was to long to read
> and to be answered  - especially because the questions are in the last
> paragraph far down below and need scrolling of the message text ;-))
> 
> Ok, I'll try to split it up in bite-sized pieces:
> 
> 1) Our apache is running 20 childs. A perl module is loaded via
> startup.pl. On shutdown of apache the END block of this module is called
> 20 times and not only 1 time as I expected. Why?

because perl_destruct() runs the END blocks, and each child calls
perl_destruct() at exit.

if you only want something to run once in the parent on shutdown or
restart, use a registered cleanup:

#PerlRequire startup.pl
warn "parent pid is $$\n";
Apache->server->register_cleanup(sub { warn "server cleanup in $$\n"});




Re: END block aborted during httpd shutdown

2000-10-18 Thread Ernest Lergon

META
Hi Ged,
why are you answering me directly and not through the list?
/META

G.W. Haywood wrote:
> 
> On Wed, 18 Oct 2000, Ernest Lergon wrote:
> 
> > but how does it fit in the idea of shared modules in mod_perl?
> 
> Shared memory, not shared events.
>
I have to think about this.

> 
> > So I have to go more in detail: It's not just closing files...
> 
> Write your own Aapche module, and use that to tidy up before Apache
> shuts down?  It's always a little bit uncertain to rely on Perl END
> blocks if you want to be sure that stuff gets written to the disc.
> 
Hmmm - so all that POD is only funny stuff? The Perl-authors are just
kidding about END blocks?

Ernest


-- 
Yours sincerely
Mit freundlichen Grüßen

Ernest Lergon

VIRTUALITAS
Artists online, Fine Arts online, Poets online
http://www.virtualitas.com/




Re: END block aborted during httpd shutdown

2000-10-18 Thread Ernest Lergon

G.W. Haywood wrote:
> 
> On Wed, 18 Oct 2000, Ernest Lergon wrote:
> 
> > 1) Our apache is running 20 childs. A perl module is loaded via
> > startup.pl. On shutdown of apache the END block of this module is called
> > 20 times and not only 1 time as I expected. Why?
> 
> Because each child is its own program and each executes the block.
> You could put a global flag in there if you're adamant that it mustn't
> do things more than once.
> 
This workaround came to my mind too, but how does it fit in the idea of
shared modules in mod_perl?

>
> > 2) I want to use the END block of this preloaded module to execute some
> > cleanup - checking and writing back to disk data possibly changed during
> > module livetime: a lengthy operation.
> 
> You shouldn't need to do tha, the OS should take care of it if you
> just close the files.  Use Symbol;
> 
So I have to go more in detail: It's not just closing files. On startup
of apache (and loading of the module) the files will be read in and the
module creates an internal net of objects (sort of cache). The files
will be locked on disk so that a call to the module via unwanted mod_cgi
will fail. Those objects might be changed by several requests to this
module. On shutdown (NOT after each request!) all objects are checked
and changed objects are written back to the files on disk.

I expected, that this will be done once in the END block and that apache
will wait.

The root of the net of objects is a Class::Singleton object.

Ernest




Re: END block aborted during httpd shutdown

2000-10-18 Thread Ernest Lergon

Dear list members, dear Doug,

it seems to me, that my initial mail of this thread was to long to read
and to be answered  - especially because the questions are in the last
paragraph far down below and need scrolling of the message text ;-))

Ok, I'll try to split it up in bite-sized pieces:

1) Our apache is running 20 childs. A perl module is loaded via
startup.pl. On shutdown of apache the END block of this module is called
20 times and not only 1 time as I expected. Why?

2) I want to use the END block of this preloaded module to execute some
cleanup - checking and writing back to disk data possibly changed during
module livetime: a lengthy operation. But this is aborted on apache
shutdown after 5 seconds with SIGKILL. Do I need special configuration
for compiling apache/perl/mod_perl, in httd.conf or startup.pl to tell
apache to wait for the completion of the END block(s)?

Extended information can be found in my message at the beginning of this
thread.

Thank you in advance for your help.

Ernest




-- 
Yours sincerely
Mit freundlichen Grüßen

Ernest Lergon

VIRTUALITAS
Artists online, Fine Arts online, Poets online
http://www.virtualitas.com/




END block aborted during httpd shutdown

2000-10-16 Thread Ernest Lergon

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