site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com 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." #!/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. _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... This email sent to site_archiver@lists.apple.com On Mar 30, 2009, at 1:32 PM, Tim Murison wrote: 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: 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. smime.p7s
participants (1)
-
Damien Sorresso