大网数据广告活动
服务器运维问答

Systemd does not restart service, although Restart=always

· 52CE 我爱测

Here is my unit file of a systemd service: [Unit] Description=Tunnel For %i After=network.target [Service] User=autossh ExecStart=/usr/bin/autossh -M 0 -N -o "ExitOnForwardFailure yes" -o "ConnectTimeout=1" -o "ServerAliveInterva…

问题原文

原帖链接 · guettli · CC BY-SA 3.0

Here is my unit file of a systemd service:

[Unit]
Description=Tunnel For %i
After=network.target

[Service]
User=autossh
ExecStart=/usr/bin/autossh -M 0 -N -o "ExitOnForwardFailure yes" -o "ConnectTimeout=1" -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -R 40443:installserver:40443 -R 8080:installserver:8080 tunnel@%i
Restart=always

[Install]
WantedBy=multi-user.target

The unit failed 15 days ago and systemd did not restart it, although "Restart=always" is in above unit file.

Here the status output of this service:

salt:/srv # systemctl status autossh@eins-work
[email omitted] - Tunnel For eins-work
      Loaded: loaded (/etc/systemd/system/autossh@.service; enabled)
      Active: failed (Result: start-limit) since Wed, 2016-02-10 14:33:34 CET; 2 weeks and 1 days ago
    Main PID: 17980 (code=exited, status=0/SUCCESS)
      CGroup: name=systemd:/system/autossh@.service/eins-work

Feb 10 14:33:34 salt systemd[1]: Stopping Tunnel For eins-work...
Feb 10 14:33:34 salt systemd[1]: Starting Tunnel For eins-work...
Feb 10 14:33:34 salt systemd[1]: Failed to start Tunnel For eins-work.
Feb 10 14:33:34 salt systemd[1]: Unit [email omitted] entered failed state

Related: https://serverfault.com/a/563401/90324

How to configure a systemd service to always restart if something fails?

社区高分解答

原帖链接 · Michael Hampton · CC BY-SA 3.0

The service failed to start too many times in a row, and so systemd gave up trying. This is what Result: start-limit means.

Note that units which are configured for Restart= and which reach the start limit are not attempted to be restarted anymore; however, they may still be restarted manually at a later point, from which point on, the restart logic is again activated. Note that systemctl reset-failed will cause the restart rate counter for a service to be flushed, which is useful if the administrator wants to manually start a unit and the start limit interferes with that.

You should resolve the problem that is causing the service to fail to start.

If you need to tune how many times and how quickly systemd attempts to restart a failing service, see the StartLimitInterval=, StartLimitBurst= and StartLimitAction= options.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-02-25)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。