Tuesday, January 29, 2019

Start service on Operating system on boot time - chkconfig/systemctl command




These are Linux commands to deal with services running for different apps on operating system. By the use of systemctl and chkconfig command, we can start and stop the services as well as configure them for auto start/stop in unix.


Basically above commands or tools allows you to configure automatic service start stop in the /etc/init.d scripts available on operating systems. Until RHEL 6.x, "chkconfig " command was available and later RHEL 7, the command "systemctl" introduced for auto service start/stop. although all legacy commands may support in new versions of RHEL and CentOS.


List All Services

  By Chkconfig command, list all the services on
[root@aps ~]# chkconfig  --list
httpd           0:off   1:off   2:on    3:on    4:on    5:on    6:off
rhnsd           0:off   1:off   2:off   3:on    4:off   5:on    6:off
netconsole      0:off   1:off   2:off   3:on    4:off   5:on    6:off
...
Above snippet shows different run level by numbering and post fixes.

By Systemctl, all active services and all enabled/disabled services
[root@aps ~]# systemctl list-units --type service
[root@aps ~]# systemctl list-unit-files --type service
Check Specific Service Status
[root@aps ~]# chkconfig --list | grep httpd
httpd           0:off   1:off   2:off   3:on   4:on   5:on   6:off
[root@aps ~]# systemctl list-units --type service | grep httpd
Stop Specific Service on Run Levels

Below command will stop httpd service at run level 2,3,4,5.
[root@aps ~]# chkconfig --level 2345 httpd off
Start/Stop Specific Service by systemctl
[root@aps ~]# systemctl stop [service_name]
[root@aps ~]# systemctl start [service_name]
Check Status of a Service by systemctl
[root@aps ~]# systemctl status [service_name]

How to Auto Start a Service at Boot of Operating System



By chkconfig command, below will stop httpd service at run level 4,5.
[root@aps ~]# chkconfig --level 45 httpd off

By systemctl command, you can enable any of service to start on boot time as below
[root@aps ~]# systemctl enable [service_name]
[root@aps ~]# systemctl disable [service_name]


_________________________________________________________________________________



No comments:

Post a Comment