Re: Launchctl question
Re: Launchctl question
- Subject: Re: Launchctl question
- From: Damien Sorresso <email@hidden>
- Date: Mon, 30 Mar 2009 14:32:29 -0700
On Mar 30, 2009, at 1:32 PM, Tim Murison wrote:
Hi,
I'm trying to restart my launch agent running as a user from a script
running as root.
I tried the obvious:
sudo -u my_user launchctl load /Library/LaunchAgents/myproduct.plist
and I get "Socket is not connected."
I've googled around a bit and found many people with the same
problem, but
no solutions. Does anyone here know a way around this?
sudo changes credentials, not environment. You're changing to a user
who does not have privileges to write to the root user's launchd
socket, thus the connection fails, and this error message gets printed.
Please keep in mind that UID is not the sole arbiter of capabilities
on Mac OS X. The bootstrap your process resides in also determines its
capabilities (like joining the active WindowServer session, security
session, etc.).
Your agent should accept a message or signal that will cause it to
restart itself. Why do you believe unloading and loading the agent is
necessary? Are you running an installer or something?
What I'd recommend is writing a small script to unload and load the
job. It would consist of:
#!/bin/sh
launchctl unload /Library/LaunchAgents/myproduct.plist
launchctl load /Library/LaunchAgents/myproduct.plist
You would then do something like this from your script running as root.
launchctl bsexec <AgentPID> <PathToTheAboveScript>
This will spawn a new process for your script in the bootstrap context
that your agent is running in. The invocations of launchctl from that
script will inherit the correct environment and talk to the correct
launchd.
--
Damien Sorresso
BSD Engineering
Apple Inc.
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden