Skip to content
Advertisement

How to restart a service using sytemd when it crashed based on only certain signals

Basically, I just want to achieve the same functionality as that of init.d’s monitor using systemd

I have a service which runs as a daemon. If that service crashes due to some reason, I want to restart it using systemd.

When I went through other questions and answers related to this, I found that we can add the following in the unit of that service.

Restart=always
RestartSec=0

But does this restart only when we there is a crash ? Or even if it is killed ?

Is there anyway to restart it based on certain signals like SIGTERM, SIGINT or SIGHUP ?

Advertisement

Answer

according to standard documentation, the condition for service restart occur on exit, kill and timeout. So, your question is answered. When it crashed, it exits, when is killed, yes, it is restarted.

Restart= Configures whether the service shall be restarted when the service process exits, is killed, or a timeout is reached….

Have a look here for more information and details (https://www.freedesktop.org/software/systemd/man/systemd.service.html)

About sending a signal, the process follows the signal handling procedures that it was designed to follow.

This is regardless the systemd controller and effects. Just consider that when you send a signal, you actually send it to the process itself. It does not reach the systemd process at all.

Advertisement