LaunchD |
Lingon is a graphical interface for creating launchd configuration files and controlling them through launchctl for Mac OS X Tiger... You get all your launchd configuration files listed in a table so you easily can see which are loaded and what they do, and you can also load and unload any easily. If you want to create or edit a launchd configuration file you can do that in Lingon through an assistant or in an easy graphical way (or through an built-in text editor, should you want to).
I generally prefer command line interface to gui, but lingon is an exception to the rule.
launchctl unload ~/Library/LaunchDaemons/filename launchctl load ~/Library/LaunchDaemons/filename launchctl list launchctl start launchctl stop
<?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"> <plist version="1.0"> <dict> <key>Label</key> <string>wu.nagios</string> <key>ProgramArguments</key> <array> <string>/usr/local/nagios/bin/nagios</string> <string>-d</string> <string>/usr/local/nagios/etc/nagios.cfg</string> </array> <key>OnDemand</key> <false/> </dict> </plist>
For processes that daemonize (e.g. apache), set the OnDemand key as illustrated above. You may need to manually start the service after booting, and the service will not automatically be restarted in the event that it dies.
To support launchd, you must obey the following guidelines when writing your daemon code:
Although they are normally part of the daemon creation process, it is worth emphasizing that forking and exiting the parent process and calling the daemon function must be avoided if you want to support launchd. The launchd program configures your daemon to run as a daemon before your code is ever called, so these steps are unnecessary. In addition, calling them interferes with the ability of launchd to launch your daemon on demand.