Re: Restarting Apache via a script
Hi !
From my experience, I can say there are many reasons why apache can't
start when you ask it. One of them is some directory being not present.
I've used graceful restart and other options, but every time I tried it,
it was having problems. That's why I ended using "apachectl stop" then
wait a bit, then "apachectl start". Then you get in trouble because
sometimes, it takes quite a while to kill all apache process (depending
on your configuration). This is why I always check for "apachectl start"
to return "httpd started". If it don't, then I try again until it works.
Here is the script sample (from Domain Technologie Control):
<?php
[...]
exec ("$APACHECTL configtest", $plop, $return_var);
if($return_var == false){
echo "Config is OK : restarting Apache\n";
system("$APACHECTL stop");
$ctl_retry = 0; // We have to continue going on,
even if apache don't restart...
$ctl_return = system("$APACHECTL start");
// Check that apache is really started, because
experience showed sometimes it's not !!!
while( strstr($ctl_return,"started") == false &&
$ctl_retry++ < 15){
echo "Warning: apache not started, will retry in
3 seconds...\n";
sleep(3);
$ctl_return = system("$APACHECTL start",
$return_var);
}
}else{
echo "Config not OK : I can't reload apache !!!\n";
}
[...]
?>
Then the only big problem I encounter, is that it doesn't work with
RedHat systems because apachectl don't print anything under Fedora, and
then in that case, maybe I'll have to check the return value of the
apachectl script. But that's another story.
Regards,
Thomas Goirand, GPLHost LLC Manager
--
http://www.gplhost.com
GPLHost:>_ Opensource hosting worldwide
Webspaces featuring GPL control panel
Locations in Florida and Singapore
Simon wrote:
Hi There,
We have a custom apache configuration front-end that we have built, it
allows our wholesale customers to add/edit/delete hosts etc... The
standard thing. We then have a cron task that looks for any
additions/updates etc and executes some scripts like building dir
structures, writing apache conf filese etc...
How do you get around the fact that *sometimes* if there are any
errors within the conf files, a "apache2ctl -t" outputs "Syntax OK",
but if you do a real restart, apache fails to start for xx reason...
Is there a way to TRULY check if there is any issues with the
configuration?
Simon
Reply to: