Launchctl difference between load and start, unload and stop

Solution 1:

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.

Solution 2:

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.