[launchd-dev] [Un]loading user agents on [Un]install
Tim Schooley
tim at sbdev.net
Tue Sep 30 04:24:04 PDT 2008
Hi all,
Is nobody able to advise on this type of scenario?
Kind regards,
Tim
On Tue, 23 Sep 2008 12:13:37 +0100, Tim Schooley wrote:
> Hi all,
>
> So I think this is probably quite a "sane" task to have to perform:
>
> - Upon installing a product, detect which users are logged in, and load
> the installed LaunchAgent script for each user.
>
> - Upon uninstalling the product, detect which users are logged in, and
> unload the LaunchAgent script for each user.
>
> These tasks would be performed preupgrade, postinstall, etc...
>
> I wrote the following script to perform this task:
>
>
> ----
> for user in `/usr/bin/users`
> do
> echo "Loading agent for user $user..."
> /usr/bin/su -l $user -c "/bin/launchctl load
> -SAqua /Library/LaunchAgents/com.mycompany.myproduct.plist" EXIT_STATUS=$?
> if [ $EXIT_STATUS != 0 ]
> then
> echo "failed (non-fatal, status $EXIT_STATUS)."
> else
> echo "Done!"
> fi
> done
> ----
>
> And similarly for unloading.
>
> The script works for the user that launched the installer. But if for
> example another user is logged in using Fast-User Switching, the following
> error is printed in the installer log when preupgrade attempts to unload
> the script:
>
> preupgrade[pid]: launchctl: Error unloading: com.mycompany.myproduct.plist
>
> Also, on post[upgrade/install], the following error is printed when
> attempting to load the script for other users:
>
> postupgrade[pid]: launch_msg(): socket is not connected
>
> I've searched around for answers to these issues, but had no luck. I was
> hoping someone here might be able to point me in the right direction?
>
> Many thanks for any help!
>
> Kind regards,
>
> Tim
>
>
> _______________________________________________
> launchd-dev mailing list
> launchd-dev at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/launchd-dev
>
More information about the launchd-dev
mailing list