受欢迎的博客标签

How to restart systemd service in case of failure on Ubuntu

Published

Configure systemd service to be restarted in case of failure.


By default, the service will be marked as failed after five consecutive starts in ten seconds.

 

Automatically restarting Home Assistant on failure
If you want to restart the Home Assistant service automatically after a crash, add the following lines to the [Service] section of your unit file:

Restart=always
RestartSec=5s

for example

[Unit]
Description=Frp Server Service
After=network.target

[Service]
Type=simple
User=nobody
Restart=always
RestartSec=5s
ExecStart=/usr/local/frp/frps -c /usr/local/frp/frps.ini

[Install]
WantedBy=multi-user.target

 

sudo systemctl daemon-reload

test

sudo systemctl stop frpc.service

 

sudo systemctl status frpc.service

 

restart policy

no: process is never restarted
on-success: process is restarted when it exits cleanly
on-failure: process is restarted when it fails
on-watchdog: when watchdog monitoring is enabled, restart the process when the watchdog timeout expires
always: process is always restarted

 

https://sleeplessbeastie.eu/2020/12/11/how-to-restart-systemd-service-in-case-of-failure/

https://bbs.archlinux.org/viewtopic.php?id=210503