![]() |
News | Profile | Code | Photography | Looking Glass | Projects | System Statistics | Uncategorized |
Blog |
I was playing around with TemperatureMonitor on my parents' iMac, today, and decided to add support for it to mrtg-rmt. Adding support was easy (included in the 1.8.3 release), but I didn't know exactly how to get the daemon started at boot. Legacy support in OS X for the usual rc.local hacks probably exist, but I figured I would do it right. So, I stumbled upon launchd, which is a subsystem in OS X that provides granular control to the starting and stopping of daemons and optionally can act as a full-blown xinetd/inetd replacement.
I started out by reading parts of the launchd.plist(5) and launchctl(1) manpages, and threw together a simple XML propertly list file for mrtg-rmt:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>com.prolixium.mrtg-rmt</string> <key>ProgramArguments</key> <array> <string>/usr/local/sbin/mrtg-rmt</string> </array> <key>RunAtLoad</key> <true/> </dict> </plist>
Apparently there are a couple locations for the plist files. The system (ie, don't touch) ones are in /System/Library/LaunchDaemons, and the custom ones should go in /Library/LaunchDaemons. I placed com.prolixium.mrtg-rmt.plist in there, and ran the following:
% sudo launchctl load -w /Library/LaunchDaemons/com.prolixium.mrtg-rmt.plist
Neat, it started up all by itself:
% ps ax | grep mrtg-rmt 866 ?? Ss 0:00.04 /usr/bin/perl -w /usr/local/sbin/mrtg-rmt 870 s001 S+ 0:00.00 grep --color -i mrtg
The plist XML schema has several other nifty options, too, but I didn't really explore them. The whole thing sure beats putting scripts into /etc/init.d! launchd reminds me of Sun's SMF stuff, too - but somehow more elegant and easier to use…
Read more: Getting Started with launchd
New comments are currently disabled for this entry.
![]() ![]() ![]() ![]() ![]() |
This HTML for this page was generated in 0.000 seconds. |