• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to enable or disable service on boot with chkconfig

by admin

CentOS/RHEL provides us with a simple command-line tool (chkconfig) for managing services that are started during the various runlevels of your system. chkconfig requires some additional comment lines in the actual init script to tell it in which run levels the service should be started, and when, relatively, the service should be started during the initialization of the run level. (init scripts are processed in a specific order to ensure that services dependent on others are started after the services they depend on.) These lines, taken from the httpd init script, are as follows:

# chkconfig: 345 85 15
# description: Apache is a World Wide Web server.  It is used to serve
# HTML files and CGI.

Here,
345 – runlevels that the service will be enabled for by default.
85 – start priority. The lower the number the higher the priority and the sooner a service will be started within a given runlevel.
15 – stop priority. The lower the number the higher the priority and the sooner a service will be stopped within a given runlevel.

Listing Services by Using chkconfig

To get a list of which services are started at which run level, use the command “chkconfig –list“.

# chkconfig --list
acpid          	0:off	1:off	2:on	3:on	4:on	5:on	6:off
auditd         	0:off	1:off	2:on	3:on	4:on	5:on	6:off
blk-availability	0:off	1:on	2:on	3:on	4:on	5:on	6:off
cgconfig       	0:off	1:off	2:off	3:off	4:off	5:off	6:off
...

Optionally, you can add a name as an additional argument, and chkconfig will list only the information for that service. Following is the output of chkconfig –list iptables on my system:

# chkconfig --list iptables
iptables       	0:off	1:off	2:off	3:on	4:on	5:on	6:off

In this case, chkconfig reports that the iptables service is to be started for run levels 3, 4, and 5.

Enabling or Disabling a Service at boot

In this example, we will use iptables service. If you want, list the currents rulevels where the services will be starting:

# chkconfig --list iptables
httpd           0:off   1:off   2:off    3:off    4:off    5:off    6:off

“chkconfig on” without specifying any runlevel will enable the service on runlevel 2,3,4 and 5. For example:

# chkconfig iptables on
# chkconfig --list iptables
iptables       	0:off	1:off	2:on	3:on	4:on	5:on	6:off

Similarly, to disable the service at all run levels, use the “chkconfig off” command. For example:

# chkconfig iptables off
# chkconfig --list iptables
iptables       	0:off	1:off	2:off	3:off	4:off	5:off	6:off

chkconfig Fine Control

The –level option can be given to chkconfig to specify which runlevels to make the change (either on or off). Other runlevels will not be altered. This would configure the system to start iptables in runlevels 3 and 5:

# chkconfig --level 35 iptables on
# chkconfig --list iptables
iptables       	0:off	1:off	2:off	3:on	4:off	5:on	6:off

Adding a Service by Using chkconfig

To add a new service to all run levels according to the recommendations given to chkconfig, use the following command:

# chkconfig --add [servicename]

chkconfig sets all the links for the service in the correct directories in one swoop.

Note: When an application or service is installed an initialization script is generated and automatically added to the /etc/init.d. So if you have difficulty in identifying the name of your service, visit /etc/init.d, locate the appropriate script and obtain the service name from its contents.

Resetting Service Information

Playing with services is educational, as long as you have a backup of your /etc/rc.d directory tree and a way to get back into the system to restore it. However, this type of drastic action is usually not necessary. Instead, you can restore the service’s startup priority and other information to the recommended settings by issuing the following command.

# chkconfig [servicename] reset

This command returns everything to a (hopefully) sane default.

Removing a service using chkconfig

If you no longer require the use of a service, you can disable it at boot by using the “chkconfig off” switch:

# chkconfig [servicename] off

You should then proceed to stop the service from running with the following command:

# service [servicename] stop

The preceding command will take immediate effect. However, in order to finalize this procedure you may want to remove it from the chkconfig management tool by typing:

# chkconfig --del [servicename]

Filed Under: CentOS/RHEL 6, Linux, OEL 6

Some more articles you might also be interested in …

  1. pw-cat Command Examples in Linux
  2. mumble: command not found
  3. CentOS / RHEL 6,7 : How to recover an interrupted yum package installation
  4. How to use fdisk to partition a disk in Linux
  5. How to Remove virbr0 and lxcbr0 Interfaces on CentOS/RHEL 6,7
  6. How to determine file and free space fragmentation of OCFS2
  7. partx: command not found
  8. autoreconf: command not found
  9. Xine Multimedia Software – Play audio and video files in Ubuntu Linux
  10. pw-play Command Examples in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • qm Command Examples in Linux
  • qm wait Command Examples in Linux
  • qm start Command Examples in Linux
  • qm snapshot Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright