Change Run Level Service CentOS

Posted on

Operating System : CentOS 6.3

If we want to change the run level of a service which means the service can automatically be started within several run level in an operating system. The idea of run level came up to specifically reconditioning operating system based on needs, for an example an administrator will need to run the operating system in run level 1 since he or she need to analyze and correct a corrupted disk, etc.

The command executed in this context for configuring run level of a service is based on CentOS 6.3 and every version of CentOS below 7. The main purpose is to activate a service automatically if the operating system start and run in certain run level.

Based on the CentOS documentation which is exist in the following URL: https://www.centos.org/docs/5/html/5.2/Installation_Guide/s2-init-boot-shutdown-rl.html, explained the run level, it can be summarized as follows :

The following runlevels are defined by default under Red Hat Enterprise Linux and also CentOS as one of its known variant :

0 — Halt
1 — Single-user text mode
2 — Not used (user-definable)
3 — Full multi-user text mode
4 — Not used (user-definable)
5 — Full multi-user graphical mode (with an X-based login screen)
6 — Reboot

According to the runlevel information given, it is very important to decide in what runlevel the service will be automatically started. Normally, it will be set in runlevel 3 and 5 which is only Graphical Display as the different condition of both runlevel. So, in order to enable the specific service to be automatically started in runlevel 3 and 5, below is the command which is needed to be executed in the bash prompt :

Based on the , this is the steps which is needed to be done :

-bash-4.1# chkconfig --list | grep httpd
httpd 0:off 1:off 2:off 3:off 4:off 5:on 6:off
-bash-4.1# chkconfig httpd on --level 35
-bash-4.1# chkconfig --list | grep httpd
httpd 0:off 1:off 2:off 3:on 4:off 5:on 6:off
-bash-4.1#

In this article, the example of the service which is going to be configured is Apache Webserver. The service normally named as httpd, http, apache2 or else depends on your operating system condition. In term of the operating system used for an example in this article, the Apache Webserver service name is httpd.

First of all, check whether the service exists with the runlevel information to be displayed. Run the following command in the bash prompt :

chkconfig service_name condition --level runlevel

service_name : name of the service which is going to be configured so that it can be automatically started within certain runlevel
condition : whether it will be between two of the following condition: on (start) or off (stop)
--level : additional parameter used together with the command to define the runlevel
runlevel : the number of the runlevel which is chosen

For an example :

chkconfig httpd on --level 35

The above command if it is executed in the bash prompt will order the operating system to remind itself to automatically run or start service httpd whenever the operating system start or up in runlevel 3 or 5, either in full multi-user mode text mode or graphical one.

One thought on “Change Run Level Service CentOS

Leave a Reply