Starting Applications At Boot with Debian

January 12, 2010
By

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

Tags: , , , , ,

490 views

4 Responses to “ Starting Applications At Boot with Debian ”

  1. [...] View original post here: Starting Applications At Boot with Debian « Press [...]

  2. [...] is easy. For this example, we’re going to start on boot an application called ‘laser.’ More here There are two steps to get this to work. First create a start-up script called laser and put it in [...]

  3. Jean Christophe André on January 13, 2010 at 1:17 pm

    I would be worth telling that you can find documentation starting point in “/etc/init.d/README” and also an example script in “/etc/init.d/skeleton”. Cheers, J.C.

  4. [...] is easy. For this example, we’re going to start on boot an application called ‘laser.’ More here There are two steps to get this to work. First create a start-up script called laser and put it in [...]