Domanda

I recently upgraded my Mac's OS from Lion to Lion Server, which changes how the httpd.conf settings are read when Apache is started. In particular, environment variables like WEBSHARING_ON and MACOSXSERVER are set by the Server.app process, so that extra modules and files are read in when Apache is started.

So now, to restart the Apache server with all the proper settings and modules loaded, I have to use the command:-

sudo serveradmin stop web && sudo serveradmin start web

Previously, I would run:-

sudo apachectl -S
sudo apachectl graceful

I prefer the latter method by far. For one thing, the command returns much quicker, and I also imagine that the apache / httpd server process doesn't completely terminate, just the settings are reloaded.

So, is there a way to gracefully restart Apache in Lion Server?

È stato utile?

Soluzione

The quick answer is no.
The 'apachectl' program is actually just a shell script, so (after realising this) it's easy to see what it's doing, and why it's not doing what I expected.

When restarting Apache (gracefully or otherwise) on a Mac, the relevant launchctl job is just unloaded and reloaded, which I imagine is not as per the official Apache description of a graceful restart:

The USR1 or graceful signal causes the parent process to advise the children to exit after their current request (or to exit immediately if they're not serving anything)

The reason apachectl -S doesn't show the configured virtual servers is because this command is not run by launchctl, and so the environment variables set in /System/Library/LaunchDaemons/org.apache.httpd.plist are not loaded.

So, apachectl graceful, apachectl restart and others do load the proper variables, and therefore read the config files properly, but not all commands do by default.

To overcome this, I've manually edited /usr/sbin/apachectl, as below. All I did was add "-D MACOSXSERVER -D WEBSERVICE_ON" where appropriate.

case $ARGV in
start)
    run_launchctl load -w $LAUNCHD_JOB
    ERROR=$?
    ;;
stop|graceful-stop)
    run_launchctl unload -w $LAUNCHD_JOB
    ERROR=$?
    ;;
restart|graceful)
    run_launchctl unload -w $LAUNCHD_JOB 2> /dev/null
    run_launchctl load -w $LAUNCHD_JOB
    ERROR=$?
    ;;
startssl|sslstart|start-SSL)
    echo The startssl option is no longer supported.
    echo Please edit httpd.conf to include the SSL configuration settings
    echo and then use "apachectl start".
    ERROR=2
    ;;
configtest)
    $HTTPD -t -D MACOSXSERVER -D WEBSERVICE_ON
    ERROR=$?
    ;;
status|fullstatus)
    echo Go to $STATUSURL in the web browser of your choice.
    echo Note that mod_status must be enabled for this to work.
    ;;
*)
    $HTTPD $ARGV -D MACOSXSERVER -D WEBSERVICE_ON
    ERROR=$?
esac
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top