Linux: Enable and Disable services during Startup

Do you ever wonder that how to setup CentOS (RedHat) Linux server startup service and how the services running?

With CentOS, you may use the command named chkconfig to configure your startup services.

First of all, you need to understand what is Linux runlevels, for more information, you may refer to the URL below,
http://www.mickgenie.com/understand-linux-runlevels/

In this example, let say we could like to set the runlevel at 2, 3, and 5 with httpd (Apache).

To enable the services in startup,

# chkconfig httpd --add
# chkconfig httpd on --level 235

To check which runlevel you have set,

# chkconfig --list httpd

To disable the startup,

# chkconfig httpd off

Apache: service httpd does not support chkconfig

As you know, when you installed your Apache service to your Centos/Redhat server manually (make & make install but not yum) and could like to run the service automatically, you should copy the apachectl from the Apache bin folder to /etc/init.d/ folder as named httpd.

Then you might want to set the chkconfig and facing the error as below,

service httpd does not support chkconfig

To fix this issue, you may simply add the following line to your file at /etc/init.d/httpd.

#
# Startup script for the Apache Web Server
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server. It is used to serve
# HTML files and CGI.
# processname: httpd
# pidfile: /usr/local/apache/logs/httpd.pid
# config: /usr/local/apache/conf/httpd.conf

Then you may chkconfig again,

chkconfig --level 235 httpd on

And now restart your httpd service.