Debian – How to start an application automatically on boot

debianlinuxstartup

I am new to Linux & looking forward to start application (which toggles a led every 10 sec).
I have written the application program & it is working fine but now I want to start it automatically on boot.

The documentation here says to copy the startup script to the /etc/init.d directory and make a symbolic link to the copied script in the rc.d directory.

What should be the extension and name of these script files?
Can we manually add the symbolic link in rc.d or is there some specific procedure for this?

Any suggestion how to achieve it?

Best Answer

Here's the excerpt from http://www.debian-administration.org/articles/28 which seems to answer your question.

Note: In the example script below just add a call to the "start)" section to actually launch your program. You can test the script's functionality without rebooting the system: call it with the full path and giving it a parameter of "start" or "stop"

Here goes:

Debian uses a Sys-V like init system for executing commands when the system runlevel changes - for example at bootup and shutdown time.

If you wish to add a new service to start when the machine boots you should add the necessary script to the directory /etc/init.d/. Many of the scripts already present in that directory will give you an example of the kind of things that you can do.

Here's a very simple script which is divided into two parts, code which always runs, and code which runs when called with "start" or "stop".

#! /bin/sh
# /etc/init.d/blah
#

# Some things that run always
touch /var/lock/blah

# Carry out specific functions when asked to by the system
case "$1" in
  start)
    echo "Starting script blah "
    echo "Could do more here"
    ;;
  stop)
    echo "Stopping script blah"
    echo "Could do more here"
    ;;
  *)
    echo "Usage: /etc/init.d/blah {start|stop}"
    exit 1
    ;;
esac

exit 0

Once you've saved your file into the correct location make sure that it's executable by running "chmod 755 /etc/init.d/blah".

Then you need to add the appropriate symbolic links to cause the script to be executed when the system goes down, or comes up.

The simplest way of doing this is to use the Debian-specific command update-rc.d:

root@skx:~# update-rc.d blah defaults
 Adding system startup for /etc/init.d/blah ...
   /etc/rc0.d/K20blah -> ../init.d/blah
   /etc/rc1.d/K20blah -> ../init.d/blah
   /etc/rc6.d/K20blah -> ../init.d/blah
   /etc/rc2.d/S20blah -> ../init.d/blah
   /etc/rc3.d/S20blah -> ../init.d/blah
   /etc/rc4.d/S20blah -> ../init.d/blah
   /etc/rc5.d/S20blah -> ../init.d/blah
Related Question