[launchd-dev] run once and then vaporize

James Bucanek subscriber at gloaming.com
Thu Jul 24 07:49:06 PDT 2008


Blake Garner <mailto:trodemaster at gmail.com> wrote (Wednesday, 
July 23, 2008 7:15 PM -0700):

>I'm hoping that an elegant solution exists for launchd to kick off a
>script on boot as root and then unload and remove itself. I understand
>that login hooks and startup items may be simpler but I would prefer
>to use a launchd plist as it fits better with our automation system.
>
>This is what I have right now..
>
><?xml version="1.0" encoding="UTF-8"?>
><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
>"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
><plist version="1.0">
><dict>
><key>Label</key>
><string>runonce</string>
><key>ProgramArguments</key>
><array>
><string>/Library/Scripts/runonce.sh</string>
><string>;</string>
><string>/bin/launchctl</string>
><string>unload</string>
><string>-w</string>
><string>/Library/LaunchDaemons/runonce.plist</string>
><string>;</string>
><string>/usr/bin/rm</string>
><string>/Library/LaunchDaemons/runonce.plist</string>
></array>
><key>RunAtLoad</key>
><true/>
></dict>
></plist>
>
>My test script currently just echo's some text into system.log and
>exits. The script runs but the launchd item fails to unload or remove
>itself. Ideally I would like to keep the removal function in the
>launchd item.

The elements of the ProgramArguments key are the arguments 
passed to your script. There is no shell or scripting language 
involved. Your script was simply passed the literal arguments

     runonce.sh ';' '/bin/launchctl' unload -w 
'/Library/LaunchDaemons/runonce.plist' ';' ...

As the documentation for ProgramArguments says: Please read 
execvp(3) very carefully!

Unless runonce.sh takes the remainder of its command line 
arguments and passes them to a shell for execution, nothing else 
will happen.

If you want your daemon to uninstall itself after running, it 
will need to do that itself.

-- 
James Bucanek



More information about the launchd-dev mailing list