How to use Systemd to restart a service when not working?

On my server, I use elastic search, which is turned off regularly, and as a result, a 500 error occurs for my users. I understand that Systemd is now a help system for managing services.

How can I use Systemd to automatically restart the elastic search service when it crashes? I found ways to restart it, but not automatically, without checking if it was turned off.

+11
source share
3 answers

If you use the systemd service file to start the service, add the following lines to the service file from where you start the service

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

    Determines whether the service will be restarted when the service process ends, ends, or after a timeout. It takes one of the following values: no , on-success , on-failure , on-abnormal , on-watchdog , on-abort or always . If set to no (default).

  • RestartSec=

    Sets the timeout before restarting the service (according to Restart= ). Takes a value without units in seconds.

These two options should be under the [Service] tag in the service file.

+19
source

I used monit monit for this. A post in askfedoraproject tells me that this is still a good way to control processes and automatically restart them.

It provides good granularity of the monitoring functions, how to decide whether the process has completed, and the steps that need to be taken to restore it.

0
source

Systemctl - systems and services manager for Linux systems

Systemd Fundamentals: Features: 1. Parallel start of the system service at boot time 2. Demon activation requirement Service control logic 3.Dependecy

 * 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. 

System units: service, path, mount, snapshot, swap, timer, device, etc. Device type File extension Description Service block. Provision of services System maintenance. Target unit .TARGET Group of system units. Auto-tuning .automount Stand-alone file system point. Device device .device A device file recognized by the kernel. .Mount mounting block File system mount point. Path block. Track A file or directory in the file system. Unit: volume An externally created process. Slice Unit. Bunches A group of hierarchically organized units that manage system processes. Snapshot block .snapshot Saved state of systemd manager. Socket. Socket Inter-process communication socket. Exchange unit. Replacement Removable device or swap file. Timer .timer System timer.

file file Filelocation: / etc / systemd / system

Conf file: /etc/systemd/system.conf

Systemd provides a lot of functionality, basically you can manage all the resources of the linux system, which gives you a lot of functionality. We focus on managing system services 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 Starting a service. systemctl stop name.service Stop the service. systemctl restart name.service Service restart. systemctl try-restart name.service Restarts the service only if it is running. systemctl reload name.service Reloads the configuration. Status systemctl status.service systemctl is-active name.service Checks if the service is running. systemctl list-units --type service - all Displays the status of all services. systemctl Description systemctl enable name.service Enables the service. systemctl disable name.service Disables the service. Status systemctl status.service systemctl with name.service support Checks if the service is enabled. systemctl list-unit-files --type service Lists all services and checks, if enabled. system-dependency lists - after Lists the services that are ordered to run before the specified device. systemctl-dependency-list-to Lists the services that are ordered to run after the specified device.

0
source

Source: https://habr.com/ru/post/983593/


All Articles