I would like to configure a service to be started automatically while system startups up. How Do I enable a service under CentOS 7 or RHEL operating systme? How can I disable a service unit at boot time in centos 7?
In CentOS 7 or RHEL 7 system, you need to use “systemctl” command with “enable” or “disable” options to enable or disable service at boot time instead of “chkconfig” command.
CentOS 7 /RHEL7 Enable/Disable A Service
CentOS 7 Enabling A Service
To enable a service unit to be automatically started while system startups up, issue the following command:
systemctl enable <service_name>.service
OR
systemctl enable <service_name>
Example: To enable httpd service via running the following command:
#systemctl enable httpd.service
Outputs:
[root@devops /]# systemctl enable httpd.service ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service' [root@devops /]# ls -l /etc/systemd/system/multi-user.target.wants/httpd.service lrwxrwxrwx. 1 root root 37 Dec 12 07:36 /etc/systemd/system/multi-user.target.wants/httpd.service -> /usr/lib/systemd/system/httpd.service
From the above output, you can see that this command will create approriate symbolic links to the “/usr/lib/systemd/system/httpd.service“.
Note: if the symbolic link exists already, this command won’t rewrite this soft link. so if you want to recreate symbolic link for enabling service, issue the following “reenable” option, type:
systemctl reenable <service_name>.service
To reenable httpd service, type:
#systemctl reenable httpd.service
Outputs:
[root@devops /]# systemctl reenable httpd.service rm '/etc/systemd/system/multi-user.target.wants/httpd.service' ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service'
CentOS 7 Disabling A Service
To disable a service to be not started automatically at boot time by running the systemctl command with “disable” option, type:
systemctl disable <service_name>.service
OR
systemctl disable <service_name>
For example: disabling apache web service, enter:
#systemctl disable httpd.service
Outputs:
[root@devops /]# systemctl disable httpd.service rm '/etc/systemd/system/multi-user.target.wants/httpd.service'
This command will remove appropriate symbolic links to “/usr/lib/systemd/system/httpd.service”.
[root@devops /]# ls -l /etc/systemd/system/multi-user.target.wants/httpd.service
ls: cannot access /etc/systemd/system/multi-user.target.wants/httpd.service: No such file or directory
done….