Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
docs:mac:launchd [2011/04/16 15:19] – billh | docs:mac:launchd [2012/07/01 15:28] (current) – billh | ||
---|---|---|---|
Line 4: | Line 4: | ||
Mac OS X provides two methods for launching daemons: [[creating startup items|startup items]] and launchd(8) daemons. Which one you use depends largely on the versions of Mac OS X that the daemon must support. | Mac OS X provides two methods for launching daemons: [[creating startup items|startup items]] and launchd(8) daemons. Which one you use depends largely on the versions of Mac OS X that the daemon must support. | ||
* Mac OS X v10.3 and earlier: You must use startup items. The launchd service is not supported prior to v10.4. | * Mac OS X v10.3 and earlier: You must use startup items. The launchd service is not supported prior to v10.4. | ||
- | * Mac OS X v10.4 and earlier: You can either use startup items or launchd daemons. Using launchd daemons is preferred unless you also require backwards compatibility with versions of Mac OS X prior to v10.4. | + | * Mac OS X v10.4 and later: You can either use startup items or launchd daemons. Using launchd daemons is preferred unless you also require backwards compatibility with versions of Mac OS X prior to v10.4. |
- | ===== Basic Instructions | + | ===== Creating a launchd job ===== |
- review the [[#External Links]] below to get a better understanding of how launchd and launchctl work | - review the [[#External Links]] below to get a better understanding of how launchd and launchctl work | ||
- open Property List Editor (included in Developer Tools) or use a text editor to create files like the examples below | - open Property List Editor (included in Developer Tools) or use a text editor to create files like the examples below | ||
Line 19: | Line 19: | ||
- the job will start when your computer is restarted or if you log out and back in, depending on where you placed the file. To start the job now, run this:< | - the job will start when your computer is restarted or if you log out and back in, depending on where you placed the file. To start the job now, run this:< | ||
launchctl load <path to your plist file> | launchctl load <path to your plist file> | ||
+ | </ | ||
+ | * if you get a " | ||
+ | launchctl load -w <path to your plist file> | ||
</ | </ | ||
- to stop the job, run this:< | - to stop the job, run this:< | ||
Line 27: | Line 30: | ||
===== Example: Apache2 ===== | ===== Example: Apache2 ===== | ||
- | FIXME | + | Since the apachectl program spawns a daemon and doesn' |
+ | |||
+ | **/ | ||
+ | <code sh> | ||
+ | #!/bin/sh | ||
+ | / | ||
+ | |||
+ | sleeptime=40 | ||
+ | |||
+ | httpdArray=(`ps -U www | grep httpd | awk ' | ||
+ | let httpdCount=${# | ||
+ | |||
+ | while (($httpdCount > 0)) | ||
+ | do | ||
+ | sleep $sleeptime; | ||
+ | hpptdArray=(`ps -U www | grep httpd | awk ' | ||
+ | let httpdCount=${# | ||
+ | done | ||
+ | |||
+ | echo " | ||
+ | </ | ||
+ | |||
+ | **/ | ||
+ | <code xml> | ||
+ | <?xml version=" | ||
+ | < | ||
+ | " | ||
+ | <plist version=" | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
===== Example: MySQL ===== | ===== Example: MySQL ===== | ||
Line 48: | Line 96: | ||
< | < | ||
< | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ===== Example: Postgres ===== | ||
+ | **/ | ||
+ | |||
+ | * note - the below script causes console to log this:< | ||
+ | * 7/1/12 2:24:05.272 PM com.apple.launchd: | ||
+ | </ | ||
+ | * however, if you try changing the users to _postgres, the launch fails (doesn' | ||
+ | |||
+ | <code xml> | ||
+ | < | ||
+ | " | ||
+ | <plist version=" | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
< | < | ||
< | < | ||
Line 65: | Line 151: | ||
* [[http:// | * [[http:// | ||
* [[http:// | * [[http:// | ||
- | |||