This post is a follow-up on the setup of your own Apache web server (although the technique can be used to start about anything of course).
Unlike classical Linuces that stock programs to launch at boot in a /etc/init.d folder for example; OS X uses a mechanism called Startup Items. These items can be found in /Library/StartupItems/, ~/Library/StartupItems and /System/Library/StartupItems.
One particular strength of the Startup Items is that you can specify in which order to launch them.
Let’s say I’ll make a startup item called MyApache. I’ll start by create the folder:
mbp:~ florent$ sudo mkdir /Library/StartupItems/MyApache
This folder will contain at least two files: an executable script called MyApache, and a file called StartupParameters.plist.
The script will be called at startup and shutdown, and will look like this:
## Apache Web Server ; custom install ##
ConsoleMessage "Starting Apache"
ConsoleMessage "Stopping Apache"
ConsoleMessage "Restarting Apache"
The StartupParameters.plist file will contain data about the information to launch. It’s an XML file that will look like:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<string>My own Apache webserver</string>
<string>Starting my Apache</string>
<string>Stopping my Apache</string>
We can see that Apache Requires the networks to be up, and will use Disks.
Let’s imagine I want to launch my Apache after my Jabber server for some reason. I’ll just create a StartupItem called “Jabber”, the same way as we just did, then add the following line to MyApache’s StartupParameters.plist “Requires” section:
Now at startup, OS X will launch Jabber and wait until it’s up and running before launching Apache.