Startup Items
If you compile and install a daemon, you’ll probably want it to start at boot time. For example, MySQL will build out of the box on Mac OS X (you can download it from http://www.mysql.com).
A startup item is controlled by three things: a folder (such as /Library/StartupItems/MyItem), a shell script with the same name as the directory (such as MyItem), and a property list named StartupParameters.plist. The shell script and the property list must appear at the top level of the startup item’s folder. You can also create a Resources directory to hold localized resources, but this is not mandatory.
To set up the MySQL startup item, create the directory /Library/StartupItems/MySQL. Then, create two files in that directory, the startup script MySQL and the property list StartupParameters.plist. The MySQL file should be an executable since it is a shell script. After you set up these two files as directed in the following sections, MySQL will be launched at each boot.
The startup script
The startup script should be a shell
script with StartService( )
, StopService( )
, and RestartService( )
functions. The
contents of /Library/StartupItems/MySQL/MySQL
are shown in Example 2-3. The function call at the
bottom of the script invokes the RunService( )
function from rc.common, which in turn invokes
StartService( )
, StopService( )
, or RestartService( )
, depending on
whether the script was invoked with an argument of
start, stop, or
restart.
#!/bin/sh ...
Get Mac OS X for Unix Geeks now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.