12

I have some plist files in ~/Library/LaunchAgents.

I have been happily using launchctl load -w and launchctl unload -w to turn these on and off for years. However, I notice that now load and unload are relegated to the "legacy" section of the man page. Let's call one of them com.example.service.plist.

However, when I try to interact with these plists via launchctl enable "gui/$(id -u)/com.example.service" and launchctl disable "gui/$(id -u)/com.example.service", other launchd commands seem to report success - for example, launchctl print "gui/$(id -u)" totally shows me disabled flags that correspond to the state that I've set - the services don't actually start and stop or listen and unlisten on their ports.

Is there some step I'm missing? For the moment I am sticking with load and unload but I'd like to learn the non-deprecated way of interacting with this stuff before Apple eventually slams the door on the old/bad way...

  • The legacy means that a change is afoot - you can still use load and unload to your heart's content on 10.11 and lower. My presumption is Apple will have documentation at WWDC this year and a timeline for migration... – bmike Feb 4 '16 at 20:09
  • 1
    I guess there just might not be an answer for this yet, but it sure looks like enable and disable are intended to replace load and unload. I just can't get them to work as I expect. – Glyph Feb 5 '16 at 22:55
  • 1
    Have you tried following launchctl enable with launchctl kickstart? – user11633 Feb 10 '16 at 17:46
  • I have not, but isn't launchctl kickstart supposed to just issue an activation for the job in question? I am using launchd specifically because I want purely on-demand activation. – Glyph Feb 11 '16 at 20:47
  • 2
    This looks like it may help: babodee.wordpress.com/2016/04/09/launchctl-2-0-syntax – TJ Luoma Apr 20 '16 at 6:18
6

I asked the Twitter user @launchderp:

@launchderp Arelaunchctl load and unload still safe to use, at least until 10.12 or whatever comes next?

c.f How do I use non-"legacy" launchctl commands to load and unload plists?

And @launchderp replied

@tjluoma Yeah they're still safe. Too many years of dependencies to break them.

While this may not seem like an official Apple statement, I believe this person to be someone who is actively working on launchd for Apple, and trust what they say. YMMV.

Moral of the story: If load/unload is working for you, keep using them :-)

  • 2
    Not marking as "accepted" because it doesn't quite address the question about enable and disable but upvoted because I still appreciate the information :). – Glyph Apr 15 '16 at 22:03
1

The article referred by TJ Luoma is very helpful. Steps for Launch Daemon:

  1. Save your plist file in /Library/LaunchDaemons/ as usual. Let's say the file is com.example.mysrv.plist, and the Label in plist is com.example.mysrv.
  2. sudo launchctl bootstrap system /Library/LaunchDaemons/com.example.mysrv.plist. Note that the path can be relative (to $PWD) or absolute.
  3. Check the service with sudo launchctl print system/com.example.mysrv. It should say "running".

Launch Agents should be similar. Caveat: I have no idea how to stop a service without unloading it through bootout.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .