Tuesday, June 16, 2009

How to configure services to run at different runlevels?

Once the kernel has been loaded and has started to run, it calls the /sbin/init program. This program runs as root and sets the "run level" to that requested at initial boot time.

Now what is run level?

A run level is simply a number that Linux uses to distinguish different types of high-level configurations that the machine should be booted into.

For Red Hat Linux system here are the different run levels described below.

Typical Linux run levels:
===========================================================================
ID Name Description

0 Halt the system

1 Single-User Mode Does not: configure network interfaces, start
daemons, or allow non-root logins.(generally
only used for administration purposes)

2 Multi-user mode with networking disabled Does not: configure network interfaces or start
daemons.

3 Multi-User Mode with Networking Starts the system normally.

4 Unused run level

5 Multi-user mode with networking Enabled Multi-User mode with network and
running the X Window System, and/or to start X

6 Reboot

===========================================================================

How init initializes the system?

INIT uses an ASCII configuration file (/etc/inittab) to tell it how to change the runlevel. Usually, this configuration file instructs init to run the script /etc/rc.d/rcRunLevelNumber.d, thus passing it to the runlevel number.


Suppose you have to configure your newly installed service to run it at RunLevel-5. Here is the procedure how to access it.


Primarily all your service starter demon resides into the following path.
----------------
/etc/rc.d/init.d/servicename
----------------

But when Linux startup on a specific run level suppose (n) it will find the find the service starter script at the following location.

------------
/etc/rc.d/rcRunLevelNumber/servicename
------------

So you have to create a soft link with /etc/rc.d/rcRunLevelNumber.d/servicename to /etc/rc.d/init.d/servicename



But how the system will know if the process will start or stop at the booting time. Also how to decide the sequence of starting the process.

Here is the description how it solves the problem.

The link described above is suffixed with the name of the service it is linked to.
The prefix is made up of two parts: a single uppercase character followed by a two-digit decimal number. The single uppercase character is either a "S" (meaning "start") or a "K" (meaning "kill," or stop). The two-digit number can range from 00 to 99. This number signifies the priority of process started in order. Lesser in value denotes higher priority.

Here is an example of the structure.

==========================
lrwxrwxrwx 1 root root 16 Jun 29 2008 K03smartd -> ../init.d/smartd
lrwxrwxrwx 1 root root 21 Jun 29 2008 S01tog-pegasus -> ../init.d/tog-pegasus
lrwxrwxrwx 1 root root 22 Jun 29 2008 K02avahi-daemon -> ../init.d/avahi-daemon
lrwxrwxrwx 1 root root 24 Jun 29 2008 K02avahi-dnsconfd -> ../init.d/avahi-dnsconfd
lrwxrwxrwx 1 root root 16 Jun 29 2008 K02dhcdbd -> ../init.d/dhcdbd
==========================

This command will help you a lot to solve this problem. Through the command you can add or delete any service from the startup links.
---------------------------
/sbin/chkconfig (For details man chkconfig)
---------------------------



After running the service if you want to check the service is running or not, this command below will help you a lot to understand.


================
/sbin/chkconfig --list

===============


For details please view the following links.

http://www.ibm.com/developerworks/linux/library/l-boot.html
http://en.wikipedia.org/wiki/Runlevel

That's all.

No comments:

Post a Comment

 Linux Interview  Linux booting process EXT4 XFS file system runlevel scan disk hba driver systool -c fc_host lspci -nn | grep -i hba single...