Cyberithub

8 Popular chkconfig command examples on RedHat/CentOS 7

In this article, I will take you through 8 Popular chkconfig command examples on RedHat/CentOS 7. chkconfig command is used to enable system services in different run level. Run Level is defined as the state of Init Process under which a group of processes and services start with the booting of the Linux OS. There are 7 run level defined in Linux.

0 – Shut down the System.
1 – Single user mode.
2 – Multiple user mode with no NFS.
3 – Multiple user mode with NFS
4 – User-definable.
5 – Graphical User Interface Mode or X11 Mode.
6 – Restart the System

Syntax

chkconfig [–list] [–type type] [name]
chkconfig –add name
chkconfig –del name
chkconfig –override name
chkconfig [–level levels] [–type type] [–no-redirect] name <on|off|reset|resetpriorities>
chkconfig [–level levels] [–type type] [–no-redirect] name

8 Popular chkconfig command examples on RedHat/CentOS 7 1

Chkconfig Command Examples

10 Best lastcomm command to monitor user activity in RedHat/CentOS 7

1. Check chkconfig command version

You can use -v option to check the chkconfig command version as shown below. As you can see from below output, current chkconfig command version is 1.7.4.

[root@localhost ~]# chkconfig -v
chkconfig version 1.7.4

-v : to check the version of chkconfig command

2. List All the Services

You can list all the services and their current run level status using --list option with chkconfig command as shown below. Here you can see only 2 services currently managed under chkconfig. Rest of the services are getting managed under Systemd. You can run systemctl list-unit-files command to list all systemd managed services. You can check 30 Useful Commands to Manage systemd services through systemctl to know more about Systemd Services.

[root@localhost ~]# chkconfig --list

Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.

If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.

netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off

–list : to list all the services managed under chkconfig

3. Enable httpd Service on Run Level 1 and 3

If you want to enable httpd service on run level 1 and 3, then you need to use chkconfig --level 13 httpd on command as shown below. It means whenever you try to start your system in run level 1 or 3 using init 1 or init 3 command, it will automatically enable httpd services with the Kernel boot up. You don’t have to manually start the httpd service.

[root@localhost ~]# chkconfig --level 13 httpd on

–level : Specify init run level from 0 to 6

4. Disable httpd Service on Run Level 1 and 3

If you want to disable httpd service on run level 1 and 3 then you need to use chkconfig --level 13 httpd off command as shown below.

[root@localhost ~]# chkconfig --level 13 httpd off

5. List a Service using chkconfig command

If you to check the run level information of a service for example network service in this example you need to use chkconfig --list network command to check that.

[root@localhost ~]# chkconfig --list network

Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.

If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.

network 0:off 1:off 2:on 3:on 4:on 5:on 6:off

6. Add httpd Service

If you want to add httpd system service under chkconfig management then you need to use chkconfig --add httpd command as shown below.

[root@localhost ~]# chkconfig --add httpd

–add : this option will add the service under chkconfig management.

After adding the service, you can verify the service list using chkconfig --list httpd command .

[root@localhost ~]# chkconfig --list httpd

Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.

If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.

httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off

7. Delete httpd Service

If you want to remove httpd service from chkconfig management then you need to use chkconfig --del httpd command as shown below.

[root@localhost ~]# chkconfig --del httpd

–del : this option will remove the service from chkconfig command management.

After removing the service you can check if httpd service deleted from the chkconfig management or not. As you can see from below output, httpd service is now removed from the list.

[root@localhost ~]# chkconfig --list httpd

Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.

If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.

service httpd supports chkconfig command, but is not referenced in any runlevel (run 'chkconfig --add httpd')

8. Do not redirect requests to Systemd

By default enabling run level for any service will redirect the request to systemd as shown below.

[root@localhost ~]# chkconfig --level 123 httpd on

So if you want to stop the redirection under Systemd managed services then you need to use --no-redirect option as shown below. This option will allow the service to be managed under chkconfig services only.

[root@localhost ~]# chkconfig --level 123 --no-redirect httpd on

–no-redirect :  this option will switch off the redirection to Systemd.

After enabling httpd service in run level 1, 2 and 3 you can check the status by running chkconfig --list httpd command as shown below.

[root@localhost ~]# chkconfig --list httpd

Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.

If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.

httpd 0:off 1:on 2:on 3:on 4:off 5:off 6:off

 

 

10 Easy Steps to Set Up high availability Cluster in CentOS 8

7 Steps to Change SSH Port Number in Linux(RedHat/CentOS 7)

3 Best Linux Copy File Command Examples

Best Way to disable SELinux on RedHat/CentOS 7

12 Best Example of SCP Command in Linux

8 Popular Linux cp command examples for Professionals

Leave a Comment