Starting Applications At Boot with Debian

Starting applications when you’re Debian server reboots is easy.

For this example, we’re going to start on boot an application called ‘laser.’

There are two steps to get this to work. First create a start-up script called laser and put it in the directory /etc/init.d and then use Debian’s ‘update-rc.d’ tool to tell the server to fire up ‘laser’ at boot.

Here’s what the ‘laser’ start-up script looks like assuming there’s executable in /usr/local/bin called ‘laser’:

#!/bin/sh -e
### BEGIN INIT INFO
# Provides:          laser
# Required-Start:    $all
# Required-Stop:     $remote_fs $syslog
# Default-Start:     6
# Default-Stop:      0 1 2 3 4 5
# Short-Description: Start daemon at boot time
# Description:       This is laser.
### END INIT INFO

set -e
. /lib/lsb/init-functions
CMD="/usr/local/bin/laser"
USER=laser

case $1 in
     start)
     log_daemon_msg "Starting laser"
     start-stop-daemon --chuid $USER --start --exec $CMD start
     ;;
     restart)
     log_daemon_msg "Restart laser"
     $CMD stop
     start-stop-daemon --chuid $USER --start --exec $CMD start
     ;;
     stop)
     log_daemon_msg "Stopping laser"
     $CMD stop
     ;;
     status)
     log_daemon_msg "Check laser status"
     $CMD status
     ;;
     *)
     log_success_msg "Usage: /etc/init.d/laser {start|stop|status}"
     ;;
esac
exit 0;

Now use the Debian tool update-rc.d as root or with sudo and tell the server to start laser on boot.
update-rc.d laser defaults

You can test your init.d laser script by running as root or sudo this command:
/etc/init.d/laser start

To stop ‘laser’ from starting on boot, run this command as root or with sudo.
update-rc.d -f laser remove

4 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>