Published by expire0
Posted on April 12, 2008
Linux has 7 different run levels (or operating modes):
* rc0.d – System Halted
* rc1.d – Single User Mode
* rc2.d – Single User Mode with Networking
* rc3.d – Multi-User Mode – boot up in text mode
* rc4.d – Not yet Defined
* rc5.d – Multi-User Mode – boot up in X Windows
* rc6.d – Shutdown & Reboot
Please research this as some of the information may not work for your environment
Here I will explain different ways of enabling and disabling the system services.
1) Red Hat Method
Red Hat and Red Hat based Linux distributions make use of the script called chkconfig to enable and disable the system services running in Linux.
For example, to enable the apache webserver to start in certain run levels, you use the chkconfig script to enable it in the desired run levels as follows:
# chkconfig httpd –add
# chkconfig httpd on –level 2,3,5
This will enable the apache webserver to automatically start in the run levels 2, 3 and 5. You can check this by running the command:
# chkconfig –list httpd
One can also disable the service by using the off flag as shown below:
# chkconfig httpd off
# chkconfig httpd –del
Red Hat also has a useful script called service which can be used to start or stop any service. Taking the previous example, to start apache webserver, you execute the command:
# service httpd start
and to stop the service…
# service httpd stop
The options being start, stop and restart which are self explanatory.
2) Debian Method
Debian Linux has its own script to enable and disable services across runlevels. It is called update-rc.d. Going by the above example, you can enable apache webserver as follows:
# update-rc.d apache2 defaults
… this will enable the apache webserver to start in the default run levels of 2,3,4 and 5. Of course, you can do it explicitly by giving the run levels instead of the “defaults” keyword as follows:
# update-rc.d apache2 start 20 2 3 4 5 . stop 80 0 1 6 .
The above command modifies the sym-links in the respective /etc/rcX.d directories to start or stop the service in the destined runlevels. Here X stands for a value of 0 to 6 depending on the runlevel. One thing to note here is the dot (.) which is used to terminate the set which is important. Also 20 and 80 are the sequence codes which decides in what order of precedence the scripts in the /etc/init.d/ directory should be started or stopped.
And to disable the service in all the run levels, you execute the command:
# update-rc.d -f apache2 remove
Here -f option which stands for force is mandatory.
But if you want to enable the service only in runlevel 5, you do this instead:
# update-rc.d apache2 start 20 5 . stop 80 0 1 2 3 4 6 .
3) Gentoo Method
Gentoo also uses a script to enable or disable services during boot-up. The name of the script is rc-update . Gentoo has three default runlevels. Them being: boot, default and nonetwork. Suppose I want to add the apache webserver to start in the default runlevel, then I run the command:
# rc-update add apache2 default
… and to remove the webserver, it is as simple as :
# rc-update del apache2
To see all the running applications at your runlevel and their status, similar to what is achieved by chkconfig –list, you use the rc-status command.
# rc-status –all
—————————– update 2/19/13 ———
check current runlevel
set the level