Question sent in by Nathan from Quebec in reply to "Restarting Services in Red Hat 7".
Q: Thanks for you help with understanding how to start and stop services. Now how to I get services to start on boot in Red Hat 7 or CentOS 7?
A: Sorry Nathan, I should have touched on this when I answered your last question about starting services. You can use systemctl to “enable” or “disable” services. It may not be so obvious, but enable means the service will start on boot, and disabled means it will not. This is done separately from starting or stopping a service. So a started service can be disabled without stopping it, and a stopped service can be enabled without starting it, although it will start on the next boot.
To set a service to start on boot you can use systemctl like so:
systemctl enable sshd.service
This will create a symbolic link which activates the service or “unit” as it is called in systemd.
Likewise, to make sure a service does not start on boot (or disable), you can use systemctl like so:
systemctl disable sshd.service
You can check if a service is enabled or disable by using the “status” option to systemctl like this:
systemctl status sshd.service
Here is an example output of the status:
sshd.service - OpenSSH server daemon
Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled)
Active: active (running) since Tue 2014-07-22 20:43:21 EDT; 17min ago
Main PID: 4322 (sshd)
CGroup: /system.slice/sshd.service
└─4322 /usr/sbin/sshd -DJul 22 20:43:21 bighat systemd[1]: Started OpenSSH server daemon.
Jul 22 20:43:21 bighat [4322]: Server listening on 0.0.0.0 port 22.
Jul 22 20:43:21 bighat [4322]: Server listening on :: port 22.
The first line shows you the service you are querying the status of:
sshd.service - OpenSSH server daemon
The second line shows you if it is enabled (will start on boot) or disabled (won’t start on boot):
Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled)
The third line shows you if the daemon or service is currently running (and info about when it was started):
Active: active (running) since Tue 2014-07-22 20:43:21 EDT; 17min ago
The fourth, fifth and sixth lines show you process ID and related information:
Main PID: 4322 (sshd)
CGroup: /system.slice/sshd.service
└─4322 /usr/sbin/sshd -D
And the following lines are pulled from syslog as yet more information:
Jul 22 20:43:21 bighat systemd[1]: Started OpenSSH server daemon.
Jul 22 20:43:21 bighat [4322]: Server listening on 0.0.0.0 port 22.
Jul 22 20:43:21 bighat [4322]: Server listening on :: port 22.
NOTE: You will have to be root to perform all of the commands listed on this page. If you prefer you can prepend sudo in front of the commands to use sudo instead of directly accessing the root account. This works in Fedora 18 and above, Red Hat 7 and CentOS 7.
Leave a Reply Cancel reply
This site uses Akismet to reduce spam. Learn how your comment data is processed.
6 Comments
Join Our Newsletter
Categories
- Bash Scripting (17)
- Basic Commands (51)
- Featured (7)
- Just for Fun (5)
- Linux Quick Tips (98)
- Linux Tutorials (65)
- Miscellaneous (15)
- Network Tools (6)
- Reviews (2)
- Security (32)
Q. I also had same doubt and thanks for the explanation. I have still one Question regarding the sequence of the service starting in a particular run level. Here with systemd we have target but inside the target also how to set the sequence of service start as we use to do in rhel-6 setting ex. S31 , K30 .. ?
Thank you so much for listing the commands.
Thank you
I was wondering if there is a way that i can specify one service to always start before the other service? For eg. I have enabled both mongodb and celiometer service to start at boot time, but i want to ensure that everytime the mongodb service starts before the celiometer.
See here: https://www.putorius.net/2016/04/start-specifc-services-first-in-redhat.html
thanks.very useful
https://www.putorius.net/2014/07/start-services-on-boot-in-red-hat-7-or.html