What can a child_init do?
am 19.02.2009 03:56:46 von Craig MacKenna
Is there anything a mod_perl2 child_init phase can do to call attention
to a problem?
I moved a block of code from a post_config handler to a new child_init
handler, without thinking much about the niceties of the move. The
code contained a couple of 'die' statements, which I trust would
prevent an Apache startup if executed in a post config handler.
Q1: WOULD 'DIE' IN A POST_CONFIG HANDLER ABORT AN
APACHE2 STARTUP?
In the child_init handler, an executed 'die' did nothing noticeable.
Specifically the message did not end up in the error_log. In the
mod_perl2 doc pages, child_init is described as being 'of type void',
which another page says means that the return value doesn't matter.
I will change the 'die' to a '$s->log_error', and return the nastiest-
sounding Apache return code I can find, in hopes that some future
Apache might notice it.
Q2: IS THERE ANYTHING A CHILD_INIT PHASE CAN DO TO
ABORT ITS CHILD PROCESS, AND THUS CALL ATTENTION
TO A SERIOUS PROBLEM?
It's amusing that the 'child_init' process seems to be an orphan
in the Apache2 world...
Thanks in advance,
cmac
www.animalhead.com
Re: What can a child_init do?
am 19.02.2009 09:22:56 von torsten.foertsch
On Thu 19 Feb 2009, craig@animalhead.com wrote:
> Is there anything a mod_perl2 child_init phase can do to call
> attention to a problem?
>
> I moved a block of code from a post_config handler to a new
> child_init handler, without thinking much about the niceties of the
> move. =A0The code contained a couple of 'die' statements, which I trust
> would prevent an Apache startup if executed in a post config handler.
>
> Q1: WOULD 'DIE' IN A POST_CONFIG HANDLER ABORT AN
> APACHE2 STARTUP?
yes. Place the following line in your httpd.conf:
PerlPostConfigHandler "sub {die q{huhu>>>>>>>>>>>>>>>>>>>>>>>>}}"
and you'll see something like this in your error log:
[Thu Feb 19 08:51:21 2009] [error] huhu>>>>>>>>>>>>>>>>>>>>>>>> at (eval=20
50) line 1.\n
Configuration Failed
and of course no running httpd.
> In the child_init handler, an executed 'die' did nothing noticeable.
> Specifically the message did not end up in the error_log. =A0In the
> mod_perl2 doc pages, child_init is described as being 'of type void',
> which another page says means that the return value doesn't matter.
>
> I will change the 'die' to a '$s->log_error', and return the
> nastiest- sounding Apache return code I can find, in hopes that some
> future Apache might notice it.
>
> Q2: =A0IS THERE ANYTHING A CHILD_INIT PHASE CAN DO TO
> ABORT ITS CHILD PROCESS, AND THUS CALL ATTENTION
> TO A SERIOUS PROBLEM?
PerlChildInitHandler "sub {warn q{about to commit suicide}; kill 9, $$}"
or
PerlChildInitHandler "sub {warn q{exiting now}; CORE::exit -1}"
But you should not need that. Because when apache needs another worker=20
it will start one (or more). If they exit immediately apache will keep=20
starting new ones.
Also, such things are bad for your users experience. The server accepts=20
the connection but doesn't respond. The request times out without=20
receiving a single byte. I think it's better to serve at least one=20
request and inform the user about temporary problems. You can ask the=20
current worker to die when the current request is done by=20
$r->child_terminate (or was it terminate_child?).
Torsten
=2D-=20
Need professional mod_perl support?
Just hire me: torsten.foertsch@gmx.net