Auto Restarting Services in RHEL 7

If you are doing RHCE training or you are a Red Hat Certified Engineer. You know how to start system services using systemctl commands. But in case a service get crashed, how to configure auto restarting services in RHEL7.

Lets check example of ssh service first in our auto restarting services in RHEL7 topic.

Step #1 – Check the status of ssh service.


Step #2 – Get the pid of ssh serviceĀ 

getting pid of ssh service


Step #3 – Emulate the crash, by killing the ssh using kill command.

killing ssh service


Step #4 – Wait for approx 42 seconds and give the systemctl status sshd command again. You will see that ssh service is running again, automatically.

ssh service status using systemctl status sshd


Step #5 – Interesting and surprising, how the its auto restarting services in RHEL7? If you disable and enable the service again. You will notice its creating a link under /etc/systemd/system/ directory. This is the link, which is doing this magic.

creating link file for ssh service


Step #6 – Now lets go there and see what’s there in this file under /etc/systemd/system/multi-user.targets.wants/sshd.service


Step #7 – Lets cat this file and see what is making auto restarting services in RHEL7, in this case ssh service.

auto restarting services in rhel7

That’s why the ssh service restarted itself after 42 seconds after we had simulated the crash.


Now lets take one more example of NTP service. I am taking NTP as example for auto restarting services in RHEL7, as it require some additional configuration.

Step #1 – Install NTPĀ 

install ntp using yum install


Step #2 – Start the ntp service and make it configure to be available after the reboot.

starting and enabling ntp


Step #2 – Now create a directory /etc/systemd/system/ntpd.service.d/ and create a file restart.conf inside it, with these contents to auto restart it after 30 seconds of delay.

configuring ntp auto restart


ntp auto restart configuration file


Step #3 – Now reload the daemon and restart the ntp service.

reload the daemon


Step #4 – Now again get the pid of ntp and kill it.

get pid of ntp and kill it


Step #5 – Check the status and this time wait for 30 seconds for ntp to be active again.

check status of ntp

You can clearly see in the screen shot that ntp is looking into our “restart.conf” file for the auto restarting ntp service.


Step #6 – Check the status of ntp again. It should be auto restarted after 30 seconds of delay.

checking ntp status after auto restarting