Remove "disabled" services; Migrate from "old" launchd
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? 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”.
Jerry, Apple is clearly trying to transition to a different architecture/philosophy for agents and daemons. But while they're getting their ducks lined up, the legacy launchctl commands still work (more or less) as advertised. Have you tried 'launchctl remove <orphaned-service-identifier>' to make launchd forget? James
Jerry Krinock <mailto:jerry@ieee.org> August 23, 2015 at 6:15 AM 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?
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”.
_______________________________________________ launchd-dev mailing list launchd-dev@lists.macosforge.org https://lists.macosforge.org/mailman/listinfo/launchd-dev
Thank you, James.
On 2015 Aug 23, at 11:16, James Bucanek <subscriber@gloaming.com> wrote:
Apple is clearly trying to transition to a different architecture/philosophy for agents and daemons.
Indeed. That’s why I hope there is some kind of “transition guide”. Maybe it has all to do with XPC? (XPC is a topic which I’ve managed to avoid thus far.)
Have you tried 'launchctl remove <orphaned-service-identifier>' to make launchd forget?
Yes, I forgot say I tried that too. It has no effect. Jerry
On 23 Aug, 2015, at 06:15, Jerry Krinock <jerry@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
On 2015 Aug 24, at 09:12, Damien Sorresso <dsorresso@apple.com> wrote:
Disabling [removing] prevents the job from being loaded at all. So if the job exists in that disabled list, launchd will refuse to load it …
That’s good, Damien, but is it OK to have 3000 “disabled” jobs? Given the size of today’s hard drives, it could be argued that this is merely a cosmetic issue, but since there is apparently no limit or frequency with which agents can be created, one could easily have 10,000, 100,000 or 1,000,000. Is there no way to “empty the trash”?
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.
That is very good, thank you.
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.
OK, I just spent a half hour reading the documentation and shall file something.
On 2015 Aug 23, at 18:43, Thomas <tclementdev@free.fr> wrote:
I don't think you can remove them. You should use the same job label to avoid having these many job entries or posix_spawn from your main agent instead or use an xpc service instead.
I think you are correct, Thomas. But I’m still looking to confirm that in the documentation!
I’ve had a number of outstanding documentation bugs which are a couple of years old now related to this with no responses to any of them: https://openradar.appspot.com/radar?id=6115837404512256 https://openradar.appspot.com/radar?id=5064754754224128 https://openradar.appspot.com/radar?id=6184356729061376 Kevin
On 25 Aug 2015, at 05:52, Jerry Krinock <jerry@ieee.org> wrote:
On 2015 Aug 24, at 09:12, Damien Sorresso <dsorresso@apple.com> wrote:
Disabling [removing] prevents the job from being loaded at all. So if the job exists in that disabled list, launchd will refuse to load it …
That’s good, Damien, but is it OK to have 3000 “disabled” jobs? Given the size of today’s hard drives, it could be argued that this is merely a cosmetic issue, but since there is apparently no limit or frequency with which agents can be created, one could easily have 10,000, 100,000 or 1,000,000. Is there no way to “empty the trash”?
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.
That is very good, thank you.
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.
OK, I just spent a half hour reading the documentation and shall file something.
On 2015 Aug 23, at 18:43, Thomas <tclementdev@free.fr> wrote:
I don't think you can remove them. You should use the same job label to avoid having these many job entries or posix_spawn from your main agent instead or use an xpc service instead.
I think you are correct, Thomas. But I’m still looking to confirm that in the documentation! _______________________________________________ launchd-dev mailing list launchd-dev@lists.macosforge.org https://lists.macosforge.org/mailman/listinfo/launchd-dev
On 2015 Aug 25, at 02:02, Kevin Meaney <ktam@yvs.eu.com> wrote:
I’ve had a number of outstanding documentation bugs …
Indeed, after reading the documentation I find no indication of anything wrong with my app’s frequent creation and attempted destruction of launchd agents. After testing my app some more this week, I found that the number of “disabled” services which are reported by launchctl print-disabled gui/`id -u` | grep -c mycompany has now increased from 3160 to 3168. Do readers agree with me that it is a bug that disabled services remain in the system, apparently, *forever*, and there is no way to ever delete them, except, I suppose, re—installing OS X? Jerry
On 24 Aug, 2015, at 21:52, Jerry Krinock <jerry@ieee.org> wrote:
On 2015 Aug 24, at 09:12, Damien Sorresso <dsorresso@apple.com> wrote:
Disabling [removing] prevents the job from being loaded at all. So if the job exists in that disabled list, launchd will refuse to load it …
That’s good, Damien, but is it OK to have 3000 “disabled” jobs? Given the size of today’s hard drives, it could be argued that this is merely a cosmetic issue, but since there is apparently no limit or frequency with which agents can be created, one could easily have 10,000, 100,000 or 1,000,000. Is there no way to “empty the trash”?
Disabled job entries are stored in a dictionary, so the fact that you have thousands of unique entries makes me think you've hit a pathological condition. In this case, launchd is honoring its contract. Someone previously disabled a job of a certain name, and the expectation is that future attempts to load a job of that name should fail. There's no garbage collection policy. If there was, someone other than you would very likely complain that the system is not behaving as advertised. -damien
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.
That is very good, thank you.
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.
OK, I just spent a half hour reading the documentation and shall file something.
On 2015 Aug 23, at 18:43, Thomas <tclementdev@free.fr> wrote:
I don't think you can remove them. You should use the same job label to avoid having these many job entries or posix_spawn from your main agent instead or use an xpc service instead.
I think you are correct, Thomas. But I’m still looking to confirm that in the documentation! _______________________________________________ launchd-dev mailing list launchd-dev@lists.macosforge.org https://lists.macosforge.org/mailman/listinfo/launchd-dev
participants (4)
-
Damien Sorresso
-
James Bucanek
-
Jerry Krinock
-
Kevin Meaney