[launchd-dev] Install and load a launch daemon without a reboot
Iceberg-Dev
dev.iceberg at gmail.com
Tue Jan 25 15:10:49 PST 2011
On Jan 25, 2011, at 7:33 PM, Jeremy Reichman wrote:
> What is considered the current best practice for installing and then
> running a launch daemon, while avoiding a reboot? I didn't see exactly
> what I was looking for in my list archive or found it in any
> documentation
> on installation packages.
>
> I have reviewed TN2083, specifically the "Starting a Daemon"
> section. That
> answers most of my question but it would be helpful to have
> confirmation.
> Besides the conditions listed in TN2083, I'd like my installer to
> behave
> well when installed to a disk other than the current startup volume. I
> need to target Mac OS X 10.5 and 10.6.
>
> It looks as if I'd need to test for the right conditions and then run
> launchctl to load the property list. Roughly -- not production code
> -- it
> looks like I'd need a postinstall and postupgrade script to do the
> following:
>
> # Test if the destination volume for the payload and the root
> volume path
> are the same
> if [ "$3" = "$4" ] ; then
> # Quick test to see if the script is run by root
> if [ `/usr/bin/whoami` = "root" ] ; then
> /bin/launchctl load
> "$3/Library/LaunchDaemons/com.vendor.launchdaemon.plist"
> fi
> fi
> exit 0
>
> Is that the right approach? Thanks!
By payload, do you mean an installation package payload?
If so, then you need to require root/admin authentication in the
installation package (to be able to install stuff in /Library/
LaunchDaemons/.
And you don't need both a postinstall and postupgrade scripts. A
postflight script is enough if you're using a bundle package. A
postinstall script is OK if you are using a flat package.
You don't need to use whoami. Just use sudo before /bin/launchctl.
More information about the launchd-dev
mailing list