总结:systemd 重新启动崩溃的服务几天后突然停止。
我有一个配置如下的服务:
[Unit]
[Service]
Restart=always
RestartSec=2
StartLimitIntervalSec=0
ExecStart=/usr/local/bin/node --max-old-space-size=4096 /home/somewhere/something.js
StandardOutput=null
StandardError=null
KillMode=process
[Install]
WantedBy=multi-user.target
此代码有时会崩溃(每天 1-2 次),因此需要Restart=always
。然而,偶尔此服务不会重新启动,以下是输出systemctl status
:
Loaded: loaded (/home/somewhere/something-systemd.service; bad; vendor preset: enabled)
Active: inactive (dead) (Result: exit-code) since Mon 2017-12-04 10:10:46 CET; 7s ago
Process: 333 ExecStart=/usr/local/bin/node --max-old-space-size=4096 /home/somewhere/something.js (code=exited, status=1/FAILURE)
Main PID: 333 (code=exited, status=1/FAILURE)
我的配置有错误吗?无论如何,如何强制 systemd 重新启动服务?
答案1
StartLimitIntervalSec=
属于 [Unit] 部分。请参阅https://www.freedesktop.org/software/systemd/man/systemd.unit.html#
[Unit] 部分选项
StartLimitIntervalSec=,StartLimitBurst=
配置单元启动速率限制。默认情况下,10 秒内启动超过 5 次的单元将不允许再启动任何次数,直到 10 秒间隔结束。...
像这样:
[Unit]
StartLimitIntervalSec=0
[Service]
Restart=always
RestartSec=2
ExecStart=/usr/local/bin/node --max-old-space-size=4096 /home/somewhere/something.js
StandardOutput=null
StandardError=null
KillMode=process
[Install]
WantedBy=multi-user.target