[launchd-dev] run once and then vaporize

Blake Garner trodemaster at gmail.com
Wed Jul 23 19:15:44 PDT 2008


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.

Suggestions and links to similar examples are welcome.

Thanks,
Blake


More information about the launchd-dev mailing list