httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Trawick <>
Subject Re: Forcing Apache to exit on startup
Date Mon, 22 Oct 2012 20:26:30 GMT
On Mon, Oct 22, 2012 at 4:05 PM, Sorin Manolache <> wrote:
> On 2012-10-22 21:29, Joshua Marantz wrote:
>> Hi,
>> Our module has multiple confirmation parameters.  There is a case where if
>> you have option A and option B, then you must also specify option C,
>> otherwise Bad things can happen that are a lot easier to debug on startup
>> than they are after the server is running.
>> I know how to force 'apachectl' to exit with a nice error message if I
>> don't like the value of option A or option B.  I can do that in the
>> function-pointer I provide in my option-table by returning a non-null
>> char*
>> message.
>> But in this case I want to exit nicely from the function I have registered
>> with ap_hook_child_init, having noticed that option A and B are set but
>> not
>> C.  Is that possible?
>> By "nicely", I mean that the user types:
>> % sudo /etc/init.d/apachectl restart
>> Error in pagespeed.conf: if you have option A and B specified, you must
>> specify a value for option C.
>> At that point either the server would not be running, or it would still be
>> in whatever state it was previously in.
>> Is this possible?
>> Currently our solution is to log an error and call abort(), and it's not
>> very nice!

exit(APEXIT_CHILDFATAL) is better than abort(), but if at all possible
you should handle this in the parent

> Don't do it in child_init. I don't think the child can stop the server.
> I think apachectl spawns apache with an appropriate -k argument (e.g.
> "apache2 -k stop") to start/stop/reload apache. However, I don't think that
> the child has sufficient privileges to stop the parent by exec'ing "apache2
> -k stop". Nor can it send the apropriate signal to the parent.
> But you can exit nicely in post_config, which is run (as root) after the
> conf is read but before the children are spawned. It suffices to return a
> non-ok code for apache to exit. I _think_, I'm not sure, that what you log
> in post_config does not go on the console but goes to the server log. But
> maybe there's a way to put the error message on the console too.

where the output goes depends on the phase of initialization

1st time post-config is called: ap_log_error goes nowhere
subsequent times post-config is called: ap_log_error goes to the error log

Some other modules handle this issue with an open_logs hook that runs
before core's open_logs hook.  The module can then log an error that
goes to the console and return an error so that startup is aborted.

Example from server/mpm/prefork/prefork.c:

static void prefork_hooks(apr_pool_t *p)
    /* The prefork open_logs phase must run before the core's, or stderr
     * will be redirected to a file, and the messages won't print to the
     * console.
    static const char *const aszSucc[] = {"core.c", NULL};
    ap_hook_open_logs(prefork_open_logs, NULL, aszSucc, APR_HOOK_MIDDLE);

> Sorin

Born in Roswell... married an alien...

View raw message