Configure the OS X Server from .pkg postinstall script I make a .pkg-installer for a product that extends the Apache server in OS X.

From the postinstall script in the .pkg I'm currently able to configure the default setup of Yosemite and El Capitan, by adding a product.conf file in the /etc/apache2/other folder.

To load the new configuration I simply do the following from the postinstall script:

launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist #if not loaded
apachectl stop #if already started
apachectl start


Installing the OS X Server changes the way Apache is configured, so the above approach fails.
So, how can I configure the OS X Server from my postinstall script to do the same?
The automating of server.app components is quite trivial since you can use serveradmin to do the heavy lifting.

  sudo serveradmin start web;


Asking a service to start if it's already running is harmless/idempotent.

To fork between the Apache configured by the Server.app and the "normal state" do the following:

if serverinfo -q --software; then
   cp product.conf /Library/Server/Web/Config/apache2/other
   serveradmin stop web
   serveradmin start web
else
   cp product.conf /etc/apache2/other
   launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist
   apachectl stop #if already started
   apachectl start
fi