Maybe this is something elementary that I've just missed, but it seems
to me that when transitioning from mod_perl 1 to 2 there's no way to
get a non-zero exit code from Apache if your application has
compilation errors.
I have an application that I'm loading like this:
PerlPostConfigRequire /usr/local/myapp/startup.pm
And in that file I do:
use strict;
use warnings;
use Apache2::ServerUtil ();
BEGIN {
die "Only makes sense when running under mod_perl\n" if !$ENV{MOD_PERL};
# We don't want to run this in the first Apache startup phase or
# we'll start up a useless instance of our application that'll
# consume memory
unless (Apache2::ServerUtil::restart_count() > 1) {
print STDERR "Running in Apache initialization phase #1\n";
return;
}
require lib;
lib->import('/usr/local/myapp/lib');
# Preload everything
require MyApp::Preload;
require MyApp::Apache::Handler;
}
1;
And even though I've inserted a "die" at line two of Handler.pm when
starting I get:
$ date; time sudo /usr/sbin/httpd; echo $?
Sat Oct 15 17:50:24 CEST 2011
real 0m1.113s
user 0m0.045s
sys 0m0.035s
0
At which point httpd returns zero exit code, but then proceeds to
start up my application, only later will I get this in the error log:
[Sat Oct 15 17:50:31 2011] [error] Died at
/usr/local/myapp/lib/MyApp/Apache/Handler.pm line 2
Of course if I load the application both when restart_count() == 1 and
>1 I'll get an error, but I'll also waste a lot of memory since I'll
be keeping around a copy of the application.
The reason I want to have a non-zero exit code if the application has
an error when initializing is that I have some production systems that
indicate problems if the startup fails, and while we could start up,
wait a bit, and then try if a http requests succeeds I'd rather change
how Apache operates than changing those systems if possible.
As far as I can tell my only options are:
* To find some Apache config option to make the server wait until
it's successfully loaded mod_perl in restart_count() > 1. This
option has thus far evaded be and it might not exist at all.
* Wrap Apache in an init script that forks, and then either polls
http:// or does an strace() and waits for sign of successfully
forked children.
* Change the startup.pm to have something like:
unless (Apache2::ServerUtil::restart_count() > 1) {
print STDERR "Running in Apache initialization phase #1\n";
system $^X => qw(MyApp::Apache::Handler -e1) and die $!;
return;
}
Which would slow down our startup, but wouldn't take up a
unnecessary amount of memory by keeping a the restart_count() ==
1's processes require()'d modules around.