Forked from drmalex07/README-create-debian-startup-script.md
Last active
February 28, 2020 15:28
-
-
Save mwiemarc/0a5d2846bc8d67844134d742e2dfe69f to your computer and use it in GitHub Desktop.
An example of how to create a init.d script in Debian, using dependency booting. #debian #init.d #lsb-script #startup-script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
### BEGIN INIT INFO | |
# Provides: foo | |
# Required-Start: $local_fs $network | |
# Required-Stop: $local_fs | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: foo service | |
# Description: Run Foo service | |
### END INIT INFO | |
# Carry out specific functions when asked to by the system | |
case "$1" in | |
start) | |
echo "Starting Foo..." | |
sudo -u foo-user bash -c 'cd /path/to/scripts/ && ./start-foo.sh' | |
;; | |
stop) | |
echo "Stopping Foo..." | |
sudo -u foo-user bash -c 'cd /path/to/scripts/ && ./stop-foo.sh' | |
sleep 2 | |
;; | |
*) | |
echo "Usage: /etc/init.d/foo {start|stop}" | |
exit 1 | |
;; | |
esac | |
exit 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The following is mostly taken from the example published at https://mkaz.com/2013/07/03/run-script-at-start-on-debian/ | |
Write an init.d script according to the the dependency-booting specification (see at https://wiki.debian.org/LSBInitScripts). | |
, say it `foo.sh`. Place the script under `/etc/init.d`. | |
ln -s /root/scripts/foo.sh /etc/init.d/foo | |
Update the runlevel directories under `/etc/rc*`: | |
update-rc.d foo defaults | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment