2 Replies Latest reply: Jun 25, 2012 1:44 PM by spleach
spleach Level 1 Level 1 (0 points)

Hi,

 

With any Unix machine, one can run at the command line:-

 

 apachectl -S

 

This will show all virtual servers configured in Apache, and will break if there are any obvious problems in the httpd .conf files. It's very handy for testing a new configuration before restarting the server.

 

With Mac OS X Server though, this doesn't work properly. Sure, I can run that command and see a virtual server or two, but with the introduction of the server Apache wrappers, the command line tools read a very different configuration than the `serveradmin` tool does.

e.g. Wrappers like:-

<IfDefine MACOSXSERVER>
    ....
</IfDefine>

or

<IfDefine WEBSERVICE_ON>
    Include /etc/apache2/sites/*.conf
</IfDefine>

 

There's loads of these, and they mean that I can't use any of my favourite apache command line tools.

A really critical command that I'm pretty sure doesn't work with these wrappers is:-

 

sudo apachectl graceful

 

 

So, how can I use apachectl under Mac OS X server? There's a couple of quite large plist files in the /etc/apache2 directory, but I don't know how to read plist settings into the environment before executing a program. The Developer documentation seems directed towards ObjC developers, which I am not.

Any help much appreciated.

Cheers,

Alex

 

ps. Running `sudo serveradmin stop web && sudo serveradmin start web` really ***** compared to `apachectl graceful`; it's painfully slow and doesn't provide a way to test a custom configuration before attempting to restart.


Mac Pro mid-2010, Mac OS X (10.6.4)
  • Strontium90 Level 4 Level 4 (3,615 points)

    Try:

     

    apachectl configtest

  • spleach Level 1 Level 1 (0 points)

    Thanks for the suggestion. It doesn't make a difference though, because `configtest` still doesn't load the environment variables stored in the relevant plist file.

    I since noticed, soon after initially posting this question, that apachectl is just a shell  script, so it's quite easy to see what it's doing, and also, to edit...

    For instance, the restart / graceful command is defined in the script as:-

    restart|graceful)

        run_launchctl unload -w $LAUNCHD_JOB 2> /dev/null

        run_launchctl load -w $LAUNCHD_JOB

        ERROR=$?

     

    As these use launchctl, the environment variables in the plist file are used, so that's all good. However, with configtest and other commands, the httpd executable is called directly, without first loading the plist variables. i.e.

    configtest)

        $HTTPD -t

        ERROR=$?

     

    Manually setting the environment variables doesn't help, but looking at `apachectl -h`, one can see that variables can be passed by adding `-D ...` command line arguments.

     

    So, my solution is to manually add the necessary keyword arguments to each ${HTTPD} call in apachectl.

     

    The bottom of my /usr/sbin/apachectl is now as follows:-

     

    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

     

    Hope this might come in handy for anyone else in the same predicament...