Difference between revisions of "Launchd"
From Wasya Wiki
(Created page with " == Startup Scripts == From: https://medium.com/@fahimhossain_16989/adding-startup-scripts-to-launch-daemon-on-mac-os-x-sierra-10-12-6-7e0318c74de1 Agent is run on behalf of...") |
|||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
+ | mac os x services | ||
+ | |||
+ | == nginx == | ||
+ | edit file /Library/LaunchDaemons/ata.nginx.plist : | ||
+ | <pre> | ||
+ | <?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> | ||
+ | </pre> | ||
+ | sudo vim /Library/LaunchDaemons/ata.nginx.plist | ||
+ | sudo launchctl load -w /Library/LaunchDaemons/ata.nginx.plist | ||
== Startup Scripts == | == Startup Scripts == | ||
Line 25: | Line 45: | ||
<string>/usr/local/lib/mongodb/bin</string> | <string>/usr/local/lib/mongodb/bin</string> | ||
</array> | </array> | ||
+ | </dict> | ||
+ | </plist> | ||
+ | </pre> | ||
+ | |||
+ | Another example: | ||
+ | <pre> | ||
+ | <?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> | </dict> | ||
</plist> | </plist> | ||
Line 33: | Line 73: | ||
sudo launchctl unload -w /Library/LaunchAgents/com.mongodb.mongodb.plist | sudo launchctl unload -w /Library/LaunchAgents/com.mongodb.mongodb.plist | ||
sudo launchctl load -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 |
Latest revision as of 05:33, 10 May 2023
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