Restart Apache gracefully on Lion Server

I recently upgraded my Mac OS from Lion to Lion Server, which changes my httpd.conf options settings when Apache starts up. In particular, environment variables such as WEBSHARING_ON and MACOSXSERVER are set by the Server.app process so that additional modules and files are read when Apache starts up.

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

sudo serveradmin stop web && sudo serveradmin start web

      

I used to run: -

sudo apachectl -S
sudo apachectl graceful

      

I prefer the latter method. On the one hand, the command returns much faster, and I am also guessing that the apache / httpd server process is not completely shutting down, just the settings are being reloaded.

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

+3


source to share


1 answer


The quick answer is no.
The "apachectl" program is really just a shell script, so (once implemented) it's easy to see what it does and why it doesn't do what I expected.

When restarting Apache (gracefully or otherwise) on a Mac, the corresponding job starts only unloads and reloads, which I think does not match the official Apache description of graceful restart:

USR1 or graceful signal causes the parent process to tell children to exit after their current request (or exit immediately if they are not serving anything)

The reason apachectl -S

does not show configured virtual servers is because this command is not launched by launchctll, so environment variables set in /System/Library/LaunchDaemons/org.apache.httpd.plist are not loaded.



So apachectl graceful

, apachectl restart

while others are charged the correct variables and is therefore correctly read configuration files, but not all of the default command.

To overcome this, I manually edited / usr / sbin / apachectl as shown 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

      

+2


source







All Articles