launchd
OSX 10.4より、デーモンやクーロンジョブの起動はlaunchdというのを通して行うことになった。
cron, xinetd, init の処理をまとめて行えるらしい。デーモンが落ちたりしたら、自動で再起動してくれる機能もある。サーバに使うには便利そうだ。
- http://developer.apple.com/macosx/launchd.html
- http://developer.apple.com/documentation/Darwin/Reference/ManPages/man8/launchd.8.html
- http://developer.apple.com/documentation/Darwin/Reference/ManPages/man1/launchctl.1.html#//apple_ref/doc/man/1/launchctl
- http://developer.apple.com/documentation/Darwin/Reference/ManPages/man5/launchd.plist.5.html#//apple_ref/doc/man/5/launchd.plist
例として macportで入れたlighttpdの起動スクリプト。/opt/local/etc/LaunchDaemons/org.macports.lighttpd.plist
<?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>org.macports.lighttpd</string> <key>OnDemand</key> <false/> <key>ProgramArguments</key> <array> <string>/opt/local/sbin/lighttpd</string> <string>-D</string> <string>-f</string> <string>/opt/local/etc/lighttpd/lighttpd.conf</string> </array> </dict> </plist>
/Library/LaunchDaemons/org.macports.lighttpd.plist へソフトリンク。
デーモンの起動
sudo launchctl load -w /Library/LaunchDaemons/org.macports.lighttpd.plist
停止
sudo launchctl unload -w /Library/LaunchDaemons/org.macports.lighttpd.plist
sudo launchctl stop org.macports.lighttpd
としても、launchdにより再起動されてしまうので注意。(この再起動をさせない設定は在る)