Skip to content

Instantly share code, notes, and snippets.

@toonetown
Created July 19, 2019 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toonetown/ffb277d23652f3d2e69ae88eb4ca4865 to your computer and use it in GitHub Desktop.
Save toonetown/ffb277d23652f3d2e69ae88eb4ca4865 to your computer and use it in GitHub Desktop.
Startup/Shutdown
#!/bin/bash
function shutdown()
{
# INSERT HERE THE COMMAND YOU WANT EXECUTE AT SHUTDOWN OR SERVICE UNLOAD
exit 0
}
function startup()
{
# INSERT HERE THE COMMAND YOU WANT EXECUTE AT STARTUP OR SERVICE LOAD
tail -f /dev/null &
wait $!
}
trap shutdown SIGTERM
trap shutdown SIGKILL
startup;
<?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>com.toonetown.shutdown</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/sbin/boot-shutdown.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
@toonetown
Copy link
Author

From https://stackoverflow.com/a/27102949

You can customize and place your boot-shutdown.sh script in /usr/local/sbin - make sure you set the permissions to 711 on the file.

Place com.toonetown.shutdown.plist into /Library/LaunchDaemons and run:

sudo launchctl load /Library/LaunchDaemons/com.toonetown.shutdown.plist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment