17 juli 2015 kl. 17:12 skrev Per Olofsson <per.olofsson(a)gu.se>:
>
> When an installer package contains a LaunchAgent we typically try to load it into any current user sessions, to avoid requiring a logout or restart. Through trial and error we've arrived at using launchctl bsexec with chroot in a loop like this:
>
> if [[ "$3" == "/" ]]; then
> # Load agent for all logged in users.
> for pid_uid in $(ps -axo pid,uid,args | grep -i "[l]oginwindow.app" | awk '{print $1 "," $2}'); do
> pid=$(echo $pid_uid | cut -d, -f1)
> uid=$(echo $pid_uid | cut -d, -f2)
> if [[ "$uid" -ne 0 ]]; then
> launchctl bsexec "$pid" chroot -u "$uid" / launchctl unload "$AGENT"
> launchctl bsexec "$pid" chroot -u "$uid" / launchctl load "$AGENT"
> fi
> done
> fi
>
> It's not perfect but it got the job done. Unfortunately it looks like it breaks in the 10.11 betas if SIP is enabled (launchctl exits with code 5). Is there a better/proper/supported way of loading LaunchAgents for users in a background script running as root?
I cross-posted to launchd-dev and got a great reply there:
https://lists.macosforge.org/pipermail/launchd-dev/2015-July/001139.html
--
Per Olofsson, IT-service, University of Gothenburg
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Installer-dev mailing list (Installer-dev(a)lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/installer-dev/site_archiver%40lists…
This email sent to site_archiver(a)lists.apple.com
When an installer package contains a LaunchAgent we typically try to load it into any current user sessions, to avoid requiring a logout or restart. Through trial and error we've arrived at using launchctl bsexec with chroot in a loop like this:
if [[ "$3" == "/" ]]; then
# Load agent for all logged in users.
for pid_uid in $(ps -axo pid,uid,args | grep -i "[l]oginwindow.app" | awk '{print $1 "," $2}'); do
pid=$(echo $pid_uid | cut -d, -f1)
uid=$(echo $pid_uid | cut -d, -f2)
if [[ "$uid" -ne 0 ]]; then
launchctl bsexec "$pid" chroot -u "$uid" / launchctl unload "$AGENT"
launchctl bsexec "$pid" chroot -u "$uid" / launchctl load "$AGENT"
fi
done
fi
It's not perfect but it got the job done. Unfortunately it looks like it breaks in the 10.11 betas if SIP is enabled (launchctl exits with code 5). Is there a better/proper/supported way of loading LaunchAgents for users in a background script running as root?
--
Per Olofsson, IT-service, University of Gothenburg
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Installer-dev mailing list (Installer-dev(a)lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/installer-dev/site_archiver%40lists…
This email sent to site_archiver(a)lists.apple.com