Tips Linux Explorers   All Things Linux Forum   Great Linux Links   Hometown    

INIT ( Startup Scripts )

The boot process of a Linux distro is a complex process, and today we will shed some light on a small part of it: The init-scripts.

Let's say you have a program you want to start at boot, depending on the runlevel ( See Runlevels ). Here are two ways to get the job done:

1). The first way is you add the command to start your program at the end of the "rc.local" file. Here is a list of the location of that file in the major distros:

Fedora: /etc/rc.local
Slackware: /etc/rc.d/rc.local
SUSE: /etc/init.d/boot.local
Mandriva: /etc/rc.local
PCLos: /etc/rc.local

2). Or, if starting the program takes more than one line, make a simple bash-script ( See Bash Script ), make it executable and place the script in the /etc/init.d directory.

The next step is to decide what Runlevel you want the script to be executed, the runlevels are represented by directories you will find in /etc/rc.d they are numbered rc1.d, to rc6.d ( in Debian and Ubuntu see the "README" in the /etc/rcS.d directory ) . . . . you might want to have a look in one of them:

# ls -al /etc/rc.d/rc5.d

And you will see that all the files in there are actually links and that they start with a code.

All these symlinks are starting either with an "S" or with a "K", the "S" is for start, the "K" stands for Kill. Just after the S there is a number, for example 04, this stands for the order in which those scripts are executed in that level.

So in a nutshell: if you have a script called "clocksync" place it in /etc/init.d and symlink it with:

# ln -s /etc/init.d/clocksync /etc/rc.d/rc5.d/S90clocksync

This way you are sure it will start at the end of the bootup in runlevel 5 . . . . . ( make sure the /etc/init.d/clocksync is executable or it will not work ! )
If you then discover the "clocksync" program starts too late, you simply remove the link and make a new one with a lower "S" number


PS: More about the Linux boot process:

-- Apr 24 2006 ( Revised Jul 22 2006 ) --

Tips Linux Explorers   All Things Linux Forum   Great Linux Links   Hometown