docs:mac:launchd

This is an old revision of the document!


launchd

Mac OS X provides two methods for launching daemons: 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.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.
  1. review the External Links below to get a better understanding of how launchd and launchctl work
  2. open Property List Editor (included in Developer Tools) or use a text editor to create files like the examples below
  3. save the file with a namespaced filename, such as com.example.MyApp.plist
    • if you edit the file in a text editor and launchctl complains later, you can check the file for errors with
      plutil -lint <path to your plist file>
  4. if you want the job to run for all users, place it in /Library/LaunchAgents/, with permissions as 644, root:wheel
  5. if you want the job to run only for you, place it in ~/Library/LaunchAgents/
  6. the job will start when your computer is restarted; to start the job now, run this:
    launchctl load <path to your plist file>
  7. to stop the job, run this:
    launchctl unload <path to your plist file>
  8. you can start an interactive session by running launchctl. If you do this with sudo, it will be the root launchd session; otherwise it will only be for your user

local.Apache2.plist

  • Root dictionary
    • Label (string): Apache2
    • UserName (string): _www
    • Program (string): /usr/local/apache2/bin/apachectl
    • ProgramArguments (array):
      • (string): start
    • OnDemand (boolean): false
  • docs/mac/launchd.1302978469.txt.gz
  • Last modified: 2011/04/16 12:27
  • by billh