[launchd-dev] Install and load a launch daemon without a reboot

Jeremy Reichman jaharmi at jaharmi.com
Tue Jan 25 10:33:18 PST 2011


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!


-- 
Jeremy




More information about the launchd-dev mailing list