2

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?

  • What version of Server.app and what version of OS X? Your script is likely going to fork based on SIP and also depend on what "extending" means in practice? – bmike Oct 6 '15 at 19:47
  • As I´m deploying for OS X in general I would like the script to work for all versions of the Server.app that is able to run on El Capitan and Yosemite. "Extending Apache" doesn't mean anything else than loading cgi, mime and alias apache modules and creating Aliases and Scriptaliases within a product.conf file. Could you explain what you mean by "fork based on SIP"? – Joachim Bratteli Oct 7 '15 at 7:16
  • @bmike SIP = System Integrity Protection? Fork = Fail? – Joachim Bratteli Oct 7 '15 at 10:50
  • SIP - is exactly what you guesses. No one likes to be "forked" - also the need to code an OS check to see which "fork" to take. If 10.10, do this and that, if 10.11, do something else - type of "fork". – bmike Oct 7 '15 at 15:19
  • Ah, in that case I hope that Apple gives some way of dealing with SIP in a user friendly way. My approach seems to work for plain El Capitan, as I was able to do a launchctl unload followed by launchctl load without issues. – Joachim Bratteli Oct 8 '15 at 7:36
1

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
  • Thanks. I guess I could expect that I do not need to load any service, as this is done within the start command? I will try the following within my script: serveradmin stop web then serveradmin start web – Joachim Bratteli Oct 7 '15 at 7:18
  • 1
    Yes - a stop would probably be best if you want to be sure it's restarted @JoachimBratteli – bmike Oct 7 '15 at 15:24
  • 1
    I copied my configuration file from /etc/apache2/other/ to /Library/Server/Web/Config/apache2/other/, did a serveradmin stop and start, and now It works! . Thanks @bmike – Joachim Bratteli Oct 8 '15 at 7:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .