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
chmod +x /etc/init.d/program
Edit it, and create something like this
case $1 in
sudo -u irc /home/ircd/unreal start
sudo -u irc /home/ircd/unreal stop
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 thoughts on “Startup Scripts in Debian”
Thanks to Kurt for this; couldn’t remember the program for the life of me that does the linking for you.
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
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
very nice explain