CentOS – chkconfig

By | February 4, 2015

Preface

There are two things to take away from this article, first is a basic knowledge of runlevels, and how to just get a service to run at boot so you don’t have to worry about it if your server has to be rebooted.

Run Levels

Here is a little bit of information I’ve pulled together, I’m trying to stay very topical with this information, cause you can get really deep in system architecture with run levels:

 
Red Hat as well as most of its derivatives (such as CentOS) uses runlevels like this:
 
ID 	Description
0 	Halt
1 	Single user
2 	Full multi-user with no networking
3 	Full multi-user, console logins only
4 	Not used/User definable
5 	Full multi-user, with display manager as well as console logins
6 	Reboot

[1]

Using the diagram above you see in the .rpm architecture there are 7 basic run levels. Pretty easily defined, they all have their purpose but for our use in this article will be 3 and 5. These are your normal operating run levels, level 3 is command line only, level 5 is the same as 3 but will include the X-Window system.

Check the list

First thing we are going to want to do is check the list of available services already configured in chkconfig, you can run this with the following command:

 
# chkconfig --list

list.png

For as much information is spouted out by this command its fairly easy to read, you get a listed service and an “on” status label. Those that are on will start working if not already started when the system changes to the particular run level.

Make a service start for normal usage

This is easy, chkconfig lets you do custom configurations and will allow you to make certain services start only on certain runlevels. For this example we will make a service start on 3,4,and 5:

 
# chkconfig httpd on

Thats it, turn it on, now apache will start when ever the server is rebooted.

I’ve got an init script but its not listed in chkconfig

Ok, backing up a little bit chkconfig will only start if there is an available init script(automated service startup script) to start from. If you have this init file listed in /etc/init.d/ you only need to run two commands to get it running at boot:

 
# chkconfig --config example
# chkconfig example on

Keep in mind that “example” is also the name of the init script, they must match.

Сomments аrchive