Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Systemd to restart a service when down? [closed]

On my server I use elasticSearch which regularly goes down and the result is a 500 error for my users. I understand Systemd is now the reference for managing services.

How can I use Systemd to restart my elastic search service automatically when it goes down? I found ways to restart it, but not automatically without me checking if it's down.

like image 200
Sébastien Avatar asked Mar 10 '15 12:03

Sébastien


2 Answers

If you are using a systemd service file to start your service, then add the lines below to your service file from where you are starting your service:

[Service]
Type=simple
ExecStart=here will be your service executable name
Restart=always
RestartSec=0
  • Restart=

    Configures whether the service shall be restarted when the service process exits, is killed, or a timeout is reached. Takes one of the following values: no, on-success, on-failure, on-abnormal, on-watchdog, on-abort or always. If set to no (the default).

  • RestartSec=

    Configures the time to sleep before restarting a service (as configured with Restart=). Takes a unit-less value in seconds.

These two options have to be under the [Service] tag in a service file.

like image 144
Rathin Paul Avatar answered Oct 17 '22 09:10

Rathin Paul


I have used monit monit for this. A post at askfedoraproject suggests to me that this is still a good way to monitor processes and automatically restart them.

It provides good granular configuration of the monitoring functions, how to decide if a process has failed, and actions to be taken to recover it.

like image 1
rolinger Avatar answered Oct 17 '22 10:10

rolinger