Where is service-target documented for launchctl?

I'm struggling to understand how to use launchctl enable/disable instead of launchctl load/unload on 10.11 15A279b


The specific issue is I want to disable mongodb so it no longer starts at boot:


manoa:~ mike$ ps -ef|grep [m]ongo
manoa:~ mike$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
manoa:~ mike$ ps -ef|grep [m]ongo
  501  1722     1   0  9:12AM ??         0:00.09 /usr/local/opt/mongodb/bin/mongod --config /usr/local/etc/mongod.conf
manoa:~ mike$ launchctl disable ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
Usage: launchctl disable <service-target>


The man page for launchctl states:


launchctl allows for detailed examination of launchd endpoints. A domain

manages the execution policy for a collection of services. A service may

be thought of as a virtual process that is always available to be spawned

in response to demand. Each service has a collection of endpoints, and

sending a message to one of those endpoints will cause the service to

launch on demand. Domains advertise these endpoints in a shared namespace

and may be thought of as synonymous with Mach bootstrap subsets.

Many subcommands in launchctl take a specifier which indicates the target

domain or service for the subcommand. This specifier may take one of the

following forms:


I'm lost without some concrete example/tutorial at this point. Which domain is my plist a part of (or can it sit across several?)


Is there a WWDC session that covers how to understand what the difference is between:


  • system/[service-name]
  • user/<uid>/[service-name]
  • login/<asid>/[service-name]
  • gui/<uid>/[service-name]
  • session/<asid>/[service-name]
  • pid/<pid>/[service-name]

Is <service-target> from the Usage: help one of the above choices or something else?


manoa:~ mike$ launchctl list|grep mongo
1722 0 homebrew.mxcl.mongodb


What is service-name specifically in this case?

manoa:~ mike$ launchctl disable pid/1722/homebrew.mxcl.mongodb
Could not disable service: 1: Operation not permitted

Replies

Probably too late, but my understanding is:


service-path = ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist

domain-target = gui/$UID

(when you did "launchctl load", it loaded the service into the current domain, which was probably "gui/$UID" (where $UID is replaced by your current User ID. Try "echo $UID") )

service-name = homebrew.mxcl.mongodb (from the "label" field of the plist, which should be identical to the plist filename, as recommended in the launchd.plist(5) manpage)


and finally service-target = domain-target/service-name


See also the answer to this StackExchange question:

http://apple.stackexchange.com/questions/166397/what-is-the-difference-between-a-service-name-and-a-service-target


The different domains are indeed confusing if you're coming from a traditional unix background. The system/ domain is the normal root/system one where system daemons run. Services from /System/Library/LaunchDaemons and /Library/LaunchDaemons are loaded into this domain. The user/ domain is the Background one for users, which exists independantly of graphically logged-in users, and is also the one that exists when you ssh into your box. You can load services into it by having LimitLoadToSessionType=Background key in a service's plist. Note that you can't store Background/user services in ~/Library/LaunchAgents, they have to be stored in /Library/LaunchAgents, see this [1] thread in the launchd mailing-list. Finally, the login/<asid> and gui/<uid> domains are aliases, the first indexed on the Audit Session ID (dunno how to find that), the latter indexed on the $UID. Both exist when the user is logged in graphically. You can find what the domain is for a given shell session by doing "launchctl managername". By default any service manually loaded with "launchctl load path/to/plist" will land in the gui/$UID domain.


You can find which services exist in which domain with "launchctl print domain-target" and looking at the service {} array.


[1] https://lists.macosforge.org/pipermail/launchd-dev/2015-November/001165.html

Sorry for the necromancy but I think this might help future folks googling this issue... You can just run launchctl blame <pid> and it will give you the domain and label.

e.g.

% launchctl blame 8094 
Unrecognized target specifier, did you mean
gui/<uid>/homebrew.mxcl.skhd

Usage: launchctl blame <service-target>
<service-target> takes a form of <domain-target>/<service-id>.
Please refer to `man launchctl` for explanation of the <domain-target> specifiers.

This works for system domain things also:

% launchctl blame 619
Unrecognized target specifier, did you mean
system/com.canonical.multipassd

Usage: launchctl blame <service-target>
<service-target> takes a form of <domain-target>/<service-id>.
Please refer to `man launchctl` for explanation of the <domain-target> specifiers.