[launchd-dev] Remove "disabled" services; Migrate from "old" launchd

Damien Sorresso dsorresso at apple.com
Mon Aug 24 09:12:06 PDT 2015


On 23 Aug, 2015, at 06:15, Jerry Krinock <jerry at ieee.org> wrote:
> Ever since 10.5, my apps have used long-running launchd agents to detect filesystem changes, and these in turn schedule one-shot agents to perform tasks.  They do this by writing and removing plist files in ~/Library/LaunchAgents, and by running launchctl with subcommands ‘load’ and ‘unload’.
> 
> I just discovered that running this command:
> 
>   launchctl print-disabled gui/`id -u`
> 
> shows hundreds of such services, probably every one which my app has created for the past year or more.  Apparently, my agents are not being completely removed, only “disabled”.  How do I remove them?

The "remove" subcommand unloads the job from launchd. It is like the "unload" subcommand, except instead of working with a path to the plist, it works with the label. Disabling prevents the job from being loaded at all. So if the job exists in that disabled list, launchd will refuse to load it unless you give the "-f" flag to the "load" subcommand.

> I tried ‘unbootstrap’, but got:
> 
>   Command is not yet implemented.
> 
> * * *
> 
> More broadly, is there an article which explains the recent changes in launchd, so that I can properly update my apps?  The current launchctl man page is incomprehensible to me until I get to the LEGACY SUBCOMMANDS section.  No more “agents", it seems; everything is a “service”.

It's a switch in terminology, but not as radical a change as you might fear. A "service" in launchd refers to anything that is a daemon, agent, or XPC service, that is, anything launchd can load and manage. Daemons and agents are still things, as are XPC services. But in the new implementation (introduced in Yosemite), they are all represented by the same data structure and go through the same basic bootstrapping path. In prior implementations, they were treated substantially differently.

If any of this was unclear in the documentation or can be made more clear, I encourage you to file bugs. These kinds of concepts are critical to developing a good mental model of how launchd operates, so good documentation is key.
-damien

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 3327 bytes
Desc: not available
URL: <https://lists.macosforge.org/pipermail/launchd-dev/attachments/20150824/e3613126/attachment.p7s>


More information about the launchd-dev mailing list