Creating Startup Items (Mac OS X)
Mac Startup Items are deprecated in favor of launchd
Mac OS X startup is nothing like other Unix systems. Most significantly, Mac OS X has nothing like the /etc/init.d directory. Instead, it finds its startup items in either /System/Library/StartupItems (for system startup items) or /Library/StartupItems (for locally-installed startup items).
To get compilers and many other development tools, you'll need the Mac OS X Developer tools. If you bought the boxed version of Mac OS X 10.2 (Jaguar), the Developer Tools should be included on a separate CD-ROM. If you bought a new Macintosh that came with Mac OS X preinstalled, the Developer Tools installer will probably be in /Applications/Installers. Failing either of those, or if you'd like to get the latest version of the tools, they are available to Apple Developer Connection (ADC) members.
You can use existing startup items as a template, or check out Mac OS X for Unix Geeks for detailed instructions. At a minimum, you need to:
- Create a subdirectory under /Library/StartupItems. For example, if you are setting up a startup item for MySQL, you might create the directory /Library/StartupItems/MySQL.
- Put a startup file in that subdirectory. It should have the same name as its parent folder, as in /Library/StartupItems/MySQL/MySQL. For an example, you can look at Mac OS X's startup item for Apache, /System/Library/StartupItems/Apache/Apache.
- At a minimum, add a StartupParameters.plist file to that subdirectory. Again, see an existing startup item for a template.
- If you used a control variable to determine whether your daemon starts at boot (Apache uses WEBSERVER), set that variable to -YES- or -NO- in /etc/hostconfig.
After you've done these steps, you can start the service with SystemStarter, as in sudo SystemStarter start MySQL.
Example: MySQL
Directory Structure:
- /Library/StartupItems/MySQL
- /Resources
- /English.lproj
- Localizable.strings
- MySQL
- StartupParameters.plist
Localizable.strings
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd"> <plist version="0.9"> <dict> <key>MySQL</key> <string>MySQL</string> </dict> </plist>
MySQL
#!/bin/sh ## # Configure MySQL Server ## . /etc/rc.common StartService () { ConsoleMessage "Starting MySQL Database" /sw/bin/mysqld_safe --user=mysql & } StopService () { ConsoleMessage "Stopping MySQL Database" /sw/share/mysql/mysql.server stop } RestartService () { ConsoleMessage "Restarting MySQL Database" /sw/share/mysql/mysql.server restart } StatusService () { ps auxww | grep mysqld | grep -v grep > /dev/null 2>&1 if [ $? -eq 0 ]; then ConsoleMessage "MySQL is running." else ConsoleMessage "MySQL is not running." fi } RunService "$1"
StartupParameters.plist
{ Description = "MySQL Database Server"; Provides = ("MySQL"); Requires = ("Resolver"); Uses = ("Network Time", "NFS"); OrderPreference = "None"; Messages = { start = "Starting MySQL"; stop = "Stopping MySQL"; }; }
/etc/hostconfig (excerpt)
... MYSQL=-YES- ...