Launchd
From Wasya Wiki
mac os x services
Contents
nginx
edit file /Library/LaunchDaemons/ata.nginx.plist :
<?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>ata.nginx</string>
<key>Program</key>
<string>/usr/local/bin/nginx</string>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
sudo vim /Library/LaunchDaemons/ata.nginx.plist sudo launchctl load -w /Library/LaunchDaemons/ata.nginx.plist
Startup Scripts
Agent is run on behalf of the logged in user while a daemon runs on behalf of the root
/Library/LaunchAgents/com.mongodb.mongodb.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>com.mongodb.mongodb</string> <!-- org.mongodb.mongodb perhaps? -->
<key>OnDemand</key>
<false/>
<key>Disabled</key>
<false />
<key>UserName</key>
<string>piousbox</string>
<key>GroupName</key>
<string>wheel</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/lib/mongodb/bin</string>
</array>
</dict>
</plist>
Another example:
<?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>com.piousbox.mysql</string>
<key>ProcessType</key> <string>Interactive</string>
<key>Disabled</key> <false/>
<key>RunAtLoad</key> <true/>
<key>KeepAlive</key> <true/>
<key>SessionCreate</key> <true/>
<key>LaunchOnlyOnce</key> <false/>
<key>ExitTimeOut</key> <integer>600</integer>
<key>Program</key> <string>/usr/local/mysql/bin/mysqld</string>
<key>WorkingDirectory</key> <string>/usr/local/mysql</string>
</dict>
</plist>
The -w flag makes it load always on startup.
sudo launchctl unload -w /Library/LaunchAgents/com.mongodb.mongodb.plist sudo launchctl load -w /Library/LaunchAgents/com.mongodb.mongodb.plist
Troubleshooting
/Users/piousbox/Library/LaunchAgents/homebrew.mxcl.postgresql.plist: Path had bad ownership/permissions
sudo chown root:wheel homebrew.mxcl.postgresql.plist