20

I was reading through the launchctl man page and have a few questions about its functioning:

  • What is the difference between load and start, unload and stop?
  • Where do I find the job label for a daemon, is it in the plist file?
10

TL;DR

  • You typically want to use launchctl load -w and launchctl unload -w.
  • start and stop are usually reserved for testing or debugging a job.

Details

  • launchctl start <label>: Starts the job. This is usually reserved just for testing or debugging a particular job.
  • launchctl stop <label>: Stops the job. Opposite of start, and it's possible that the job will immediately restart if the job is configured to stay running.

  • launchctl remove <label>: Removes the job from launchd, but asynchronously. It will not wait for the job to actually stop before returning, so no error handling on this one.

  • launchctl load <path>: Loads and starts the job as long as the job is not "disabled."
  • launchctl unload <path>: Stops and unloads the job. The job will still restart on the next login/reboot.

  • launchctl load -w <path>: Loads and starts the job while also marking the job as "not disabled." The job will restart on the next login/reboot.
  • launchctl unload -w <path>: Stops and unloads and disables the job. The job will NOT restart on the next login/restart.

Where do I find the job label for a daemon, is it in the plist file?

Yes, it's in the plist file and it typically matches the filename of the plist file.

7

Loading and unloading tells launchd to load the configuration file. Whether it runs the program and under what conditions is determined by the plist file. A job that isn't currently running can be started with launchctl start ... and stopped with launchctl stop ....

The label for the job is defined by the label key, and the name of the plist should also be the job label followed by the plist extension.

  • 6
    How does remove factor into this? Specifically how is it different from unload? – chrisortman Apr 18 '15 at 3:25
  • @chrisortman remove is like unload except that it does not wait for the job to stop first. It just returns immediately without checking if any errors occurred. – Ryan McGeary Dec 8 '17 at 22:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .