Search code examples
macosservicelaunchd

launchd: Confusion on the sematics of bootstrap/bootout for controlling services on macOS


I've read the following manual pages on launchd: launchctl, launchd, and launchd.plist.

However, nothing is really said in these manual pages regarding what the launchctl boostrap and launchctl bootout (sub)commands actually do (see below). Is it to be inferred from their names?

Futhermore, I cannot find information in the man pages, regarding what user/group the service (agent/daemon) runs as. However, launchd.plist mentions UserName/GroupName for controlling the user/group for the system domain. So, what user are per-user services in /Library/LaunchAgents or ~/Library/LaunchAgents run as?

Finally, I would expect I need to bootstrap/load my daemon's .plist, but after putting the .plist in /Library/LaunchAgents or /Library/LaunchDaemons, it was automatically loaded (run) at system boot. Indeed, RunAtLoad=true, but what's the purpose of bootstrap, if services run anyway?

man launchctl:

 bootstrap | bootout domain-target [service-path service-path2 ...] | service-target
          Bootstraps or removes domains and services. When service arguments are present, bootstraps and correspondingly removes their definitions into the domain.  Services may be specified as a series of
          paths or a service identifier.  Paths may point to XPC service bundles, launchd.plist(5) s, or a directories containing a collection of either. If there were one or more errors while bootstrapping or
          removing a collection of services, the problematic paths will be printed with the errors that occurred.

          If no paths or service target are specified, these commands can either bootstrap or remove a domain specified as a domain target. Some domains will implicitly bootstrap pre-defined paths as part of
          their creation.

Solution

  • bootstrap and bootout can be used to load and unload services without rebooting or logging in and out. They can be useful if you need to temporarily stop a service to do some task and then start it up again without requiring a reboot of the system.

    /Library/LaunchDaemons run as root by default. You can use the UserName and GroupName keys to control the configuration of daemons.

    /Library/LaunchAgents run as the currently logged in user (these run for every user).

    ~/Library/LaunchAgents run as that specific user.

    For further reading: