Startup Scripts in Debian

If you would like to add a custom startup script to your Linux machine (for running ircd or an iptables script for example) the process is simple.

Create a file in /etc/init.d

touch /etc/init.d/program

chmod +x /etc/init.d/program

Edit it, and create something like this

#!/bin/bash

case $1 in

start)

sudo -u irc /home/ircd/unreal start

;;

stop)

sudo -u irc /home/ircd/unreal stop

;;

esac

These scripts are run as root, so you should probably use sudo to run programs as unprivileged users.

Now we just have to add it to our default runlevel (runlevel can be found in /etc/inittab on Debian, in Ubuntu this file does not exist as far as I know). The runlevel should be the same across all Debian (including ubuntu) systems.

ln -s /etc/init.d/program /etc/rc2.d/S20program

The S20 requires a little bit of explanation. S means Start, and 20 means to run after the 19’s but before the 21+’s. It’s simply a priority system.  You can replace S with K to ‘stop’ instead of ‘start’ when the computer shuts down.

3 Responses to “Startup Scripts in Debian”

  1. termina says:

    Thanks to Kurt for this; couldn’t remember the program for the life of me that does the linking for you.

    man update-rc.d

  2. The neko says:

    Excuse me, i understand that your script example is for any program, but i got a question, i just want to create an environment variable, i mean, like this

    JAVA_HOME=/usr/java/jdk1.5.0_15

    my question is: where can i put my environment variable in your script, because i can not to use my commands allocated in that directory, or is a different script or what????
    I modified my /etc/configure but i would like to use my commands with any user, and if i make in this way, the commands just work with my user, no with root, and i modify the bash(any bash or bashrc) not works, that is the reason by i want to make a script that initializes at startup and works with any user… can you help me?????
    thanks a lot for your attention..
    atte: the neko

  3. lascost says:

    very nice explain

Leave a Reply to termina Cancel reply

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

Time limit is exhausted. Please reload CAPTCHA.