Skip to content

Instantly share code, notes, and snippets.

@amonks
Created January 21, 2014 16:15
Show Gist options
  • Save amonks/8543044 to your computer and use it in GitHub Desktop.
Save amonks/8543044 to your computer and use it in GitHub Desktop.
Put this file in /etc/init.d/ and edit {THING-TO-LAUNCH} as appropriate. You can run `sudo update-rc.d {THIS-FILE'S-NAME} defaults` to `start` at boot and `stop` at shutdown.
#! /bin/sh
# /etc/init.d/{THING-TO-LAUNCH}
### BEGIN INIT INFO
# Provides: {THING-TO-LAUNCH}
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Simple script to start a program at boot
# Description: Simple, conventional, practical launch script. By Andrew Monks.
### END INIT INFO
# run `sudo update-rc.d {THIS-FILE'S-NAME} defaults` to `start` at boot and `stop` at shutdown.
# Carry out specific functions when asked to by the system
case "$1" in
start)
echo "Starting {THING-TO-LAUNCH}"
# run application you want to start
# runs as root by default, hence the `su`
# /usr/bin/{THING-TO-LAUNCH} # on its own works if you'd like to run as root.
su pi -c '/usr/bin/{THING-TO-LAUNCH}' # or whatever
;;
stop)
echo "Stopping {THING-TO-LAUNCH}"
# kill application you want to stop
su pi -c 'killall {THING-TO-LAUNCH}' # or whatever
;;
*)
echo "Usage: /etc/init.d/{THING-TO-LAUNCH} {start|stop}"
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment