[launchd-dev] Yosemite not starting a system launch agent

James Bucanek subscriber at gloaming.com
Thu Jul 23 12:14:53 PDT 2015


Damian,

Thanks for sticking with me. OK, here's what I've tried:

> Damien Sorresso <mailto:dsorresso at apple.com>
> July 23, 2015 at 8:35 AM
> On 22 Jul, 2015, at 22:49, James Bucanek <subscriber at gloaming.com 
> <mailto:subscriber at gloaming.com>> wrote:
>>> Damien Sorresso <mailto:dsorresso at apple.com>
>>> July 22, 2015 at 6:19 PM
>
> That is your problem. In that context, `launchctl load` will attempt 
> to load your job as a daemon because it is running as root in the root 
> Mach bootstrap. One thing that's critical to understand is that 
> there's nothing about the contents of your plist which identifies it 
> as a daemon or agent; the same plist can be loaded into multiple 
> contexts. Each context can have sessions within it. As it turns out, 
> the only place this matters is the per-user context, which has 
> Background and Aqua. The intended effect of `launchctl load` and 
> friends is determined by your calling context.

I'm getting that.
>
> This is why the new bootstrap subcommand introduced in Yosemite takes 
> an explicit parameter identifying the context you want to bootstrap 
> the job into. Try changing your NSTask invocation in your helper tool 
> to this:
>
> launchctl bootstrap user/$UID /path/to/plist
Here's the experiment I performed. I uninstalled all of my software, 
created a test .plist file on my desktop that points to a working 
version of my user agent, and issued the following command

     sudo launchctl bootstrap user/501 
/Users/james/Desktop/com.qrecall.scheduler.plist

Here's what worked:

- The QRecallScheduler executable started up for user 501 (yea!).

- Using 'launchctrl print user/501' and 'launchctl print 
user/501/com.qrecall.scheduler' I can see that the agent was installed.

Where's what doesn't work:

The agent only runs for user 501. When I log in with another user, the 
agent doesn't start. Now this is consistent with my understanding of the 
"user/501" domain; this syntax refers to the session belonging to user 
501 and only user 501.

This is not what I'm trying to accomplish. (I have the per-user stuff 
working just fine). I'm trying, as an administrator (root), to install a 
user agent that will run FOR ALL USERS.

This is my frustration with the documentation for the new launchctl. I 
can see that "system/" applies to the root system (daemons). I 
understand that "user/PID" applies to the context of a single user, as 
does its various synonyms (login/ASID, gui/UID, session/ASID, ...). What 
I can't figure out is the syntax for addressing a user agent to be 
started for ALL users. Said another way, how do you say to launchctl "I, 
the administrator, have installed a user agent that needs to be 
installed and started for every logged in user, here's its .plist"? 
After that command, if there were three users logged in, I'd expect 
three instances of my agent to start.

I tried "user/*". It doesn't work. ;)

Finally, I notice that 'launchctl bootstrap ...' does not copy the 
.plist to the /Library/LaunchAgents or ~/Library/LaunchAgents folder, 
and after restarting the system my agent is no longer running and no 
longer appears in 'launchctl print user/501'. I infer from this that to 
permanently install a user agent, I'm still responsible for copying the 
.plist to the appropriate directory (/Library/LaunchAgents or 
~/Library/LaunchAgents).

Having now vented my angst over this whole mess, I'm considering a 
solution that bypasses the need to install an agent for all users.

You've helped me by clearly describing the difference between a 
"Background" session for a user and the "Aqua" session for a user. I'm 
thinking now that I don't need to install a user agent for all users. I 
just need to install a "Background" agent for each users that wants the 
scheduler to run when they are logged out, and I can do that without 
needing admin authorization. I still need the "kicker" system daemon to 
create the session for each user (with a scheduler installed) before 
they've logged in, but that should also start all of the per-user 
"Background" agents in ~/Library/LaunchAgents for that user, correct?

James

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/launchd-dev/attachments/20150723/e6041e4d/attachment.html>


More information about the launchd-dev mailing list