18

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.

3 Answers 3

29

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.

3
  • can you ellaborate on how to do this when starting from scratch? using apt-get install system-sysv gets me a "Package 'systemd-sysv' has no installation candidate"
    – Sébastien
    Mar 10, 2015 at 14:33
  • Starting from scratch -- didnt understand... Linux comes with a system framework component called systemD. Kernel starts this nd once systemD is up, it starts all services on booting of a device. SystemD is a replacement of System V init. is systemD available in your linux platform. If yes then this is just few line changes in service file to get it worked. Mar 11, 2015 at 6:00
  • nice, I could make that work. I needed to switch from linux 14.04 to 14.10 and then most of useful services already have their unit file under /run/systemd/generator.late
    – Sébastien
    Apr 1, 2015 at 13:30
1

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.

0

Systemctl - System and Service manager for linux systems

Basics about systemd: Features: 1.Parallel startup of system service at boot time 2.On demand activation of daemons 3.Dependecy based service control logic

* limited support at runlevel
* panic is not support panic command(systemctl no custom commands)
* systemctl can only communicate with services which are started by systemd
* sysd stop only running services
* system services don't inherit any context like HOME or PATH variable
* All services subject to default timeout of 5 minutes can be configured.These prevents from system to freeze in case of some application stop to respond.

Systemd units: service , path, mount, snapshot, swap, timer, device etc Unit Type File Extension Description Service unit .service A system service. Target unit .target A group of systemd units. Automount unit .automount A file system automount point. Device unit .device A device file recognized by the kernel. Mount unit .mount A file system mount point. Path unit .path A file or directory in a file system. Scope unit .scope An externally created process. Slice unit .slice A group of hierarchically organized units that manage system processes. Snapshot unit .snapshot A saved state of the systemd manager. Socket unit .socket An inter-process communication socket. Swap unit .swap A swap device or a swap file. Timer unit .timer A systemd timer.

unit file's Filelocation: /etc/systemd/system

Conf file: /etc/systemd/system.conf

Systemd provides a lot of functionallity basically you can control all the resouces of linux system that gives you give a lot of functionality.We are focussing on managing system service in this article.

for more details: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/chap-managing_services_with_systemd

MANAGING SYSTEM SERVICES: systemctl Description systemctl start name.service Starts a service. systemctl stop name.service Stops a service. systemctl restart name.service Restarts a service. systemctl try-restart name.service Restarts a service only if it is running. systemctl reload name.service Reloads configuration. systemctl status name.service systemctl is-active name.service Checks if a service is running. systemctl list-units --type service --all Displays the status of all services. systemctl Description systemctl enable name.service Enables a service. systemctl disable name.service Disables a service. systemctl status name.service systemctl is-enabled name.service Checks if a service is enabled. systemctl list-unit-files --type service Lists all services and checks if they are enabled. systemctl list-dependencies --after Lists services that are ordered to start before the specified unit. systemctl list-dependencies --before Lists services that are ordered to start after the specified unit.

Not the answer you're looking for? Browse other questions tagged or ask your own question.