![尽管 Restart=always,Systemd 也不会重新启动服务](https://linux22.com/image/677715/%E5%B0%BD%E7%AE%A1%20Restart%3Dalways%EF%BC%8CSystemd%20%E4%B9%9F%E4%B8%8D%E4%BC%9A%E9%87%8D%E6%96%B0%E5%90%AF%E5%8A%A8%E6%9C%8D%E5%8A%A1.png)
这是我的 systemd 服务的单元文件:
[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
该单元在 15 天前出现故障,并且 systemd 未重新启动它,尽管上述单元文件中有“Restart=always”。
以下是该服务的状态输出:
salt:/srv # systemctl status autossh@eins-work
[email protected] - Tunnel For eins-work
Loaded: loaded (/etc/systemd/system/[email protected]; 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/[email protected]/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 protected] entered failed state
有关的:https://serverfault.com/a/563401/90324
如何配置 systemd 服务以便在出现故障时始终重新启动?
答案1
服务连续启动失败次数过多,所以 systemd 放弃尝试。这就是意思Result: start-limit
。
请注意,已配置
Restart=
且达到启动限制的单元将不再尝试重新启动;但是,它们仍可在稍后手动重新启动,从此时起,重新启动逻辑将再次激活。请注意,这systemctl reset-failed
将导致服务的重新启动率计数器被刷新,如果管理员想要手动启动单元并且启动限制会干扰这一点,这将非常有用。
您应该解决导致服务无法启动的问题。
如果你需要调整 systemd 尝试重启失败服务的次数和速度,请参阅和StartLimitInterval=
选项StartLimitBurst=
StartLimitAction=
。