MacOS X 10.5 has autofs, but 10.4 doesn’t. Alternative solution is am-utils, available in MacPorts. However, MacPorts doesn’t provide any way to launch amd at startup.
In MacOS X, there’s no scripts like /etc/rc, but there’s launchd. I spent about a half day to launch amd by launchd and learned:
- Write the policy to launch in /System/Library/LaunchDaemons/foobar.plist
- The process spawned by foobar.plist must NOT go background, but must stay in foreground (see launchd.plist(5)!).
However, my sweet amd goes background… So, launchd misunderstands: “Oh, amd is dead. I must start a new one!” and there will be so many amd processes.
As the solution, I wrote a simple wrapper script (amd_start) like:
#!/bin/sh /opt/local/sbin/amd -F /opt/local/etc/amd.conf while [ true ]; do sleep 360000 done
And my amd.plist is this:
<?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>amd</string> <key>OnDemand</key> <false/> <key>ProgramArguments</key> <array> <string>/System/Library/amd_start</string> </array> <key>ServiceIPC</key> <false/> </dict> </plist>
Put this in /System/Library/LaunchDaemons/amd.plist, then:
% sudo launchctl load /System/Library/LaunchDaemons/amd.plist
This will launch amd.
launchd is fun… It works as /etc/rc, crond and inetd. Wow.