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

systemd stops restarting service

· 52CE 我爱测

tl;dr: systemd restarts a crashing service for days and then suddenly stops. I've got a service configured as follows: [Unit] [Service] Restart=always RestartSec=2 StartLimitIntervalSec=0 ExecStart=/usr/local/bin/node --max-old-s…

问题原文

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

tl;dr: systemd restarts a crashing service for days and then suddenly stops.

I've got a service configured as follows:

[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

This code crashes sometimes (1-2 times a day), hence the need to Restart=always. Yet once in a while this service doesn't get restarted and here's the output of 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)

Is there a mistake in my configuration? How do I force systemd to restart a service no matter what?

已采纳解答

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

StartLimitIntervalSec= belongs to the [Unit] section. See https://www.freedesktop.org/software/systemd/man/systemd.unit.html#

[Unit] Section Options

StartLimitIntervalSec=, StartLimitBurst=

Configure unit start rate limiting. By default, units which are started more than 5 times within 10 seconds are not permitted to start any more times until the 10 second interval ends. ...

Like this:

[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

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

资料来源与适用范围

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

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

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