Skip to content

Instantly share code, notes, and snippets.

@drmalex07
Last active September 29, 2023 11:42
Show Gist options
  • Star 34 You must be signed in to star a gist
  • Fork 11 You must be signed in to fork a gist
  • Save drmalex07/298ab26c06ecf401f66c to your computer and use it in GitHub Desktop.
Save drmalex07/298ab26c06ecf401f66c 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
#! /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
@m6969p
Copy link

m6969p commented Sep 29, 2023

thanks pal,
I had forgotten how to add a service, not used for a very long time.
You have no idea how many search results there were for this: paywalls mostly, and idiots who answer 'why would you need that'....

Great contribution, you have no idea how valuable this small snippet has just been.
Just for that one line: update-rc.d .

Mike

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