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

Systemd `ExecStartPost` timed out

· 52CE 我爱测

I'm having trouble using ExecStartPost in a systemd service. Even with the following simple command: ExecStartPost=/bin/sh -c "exit 0" ... when I start the service, I get a "time out" error: start-post operation timed out. Stoppi…

问题原文

原帖链接 · Nikolas Stevenson-Molnar · CC BY-SA 4.0

I'm having trouble using ExecStartPost in a systemd service. Even with the following simple command:

ExecStartPost=/bin/sh -c "exit 0"

... when I start the service, I get a "time out" error:

start-post operation timed out. Stopping.

Here is my full service definition. mbtileserver is a blocking program, not a daemon.

[Unit]
Description=mbtileserver daemon
After=network.target

[Service]
Type=simple
PIDFile=/home/crp/var/run/mbtileserver.pid
User=crp
Group=crp
WorkingDirectory=/home/crp
ExecStart=/home/crp/go/bin/mbtileserver -d /home/crp/tiles/ -p 8080 -s "eGJ0NwI9_OyxHEFvBcU-9zR6O89z_S0RNfIOSP3utSU"
ExecStartPost=/bin/sh -c "exit 0"
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

How do I create an ExecStartPost that doesn't time out?

已采纳解答

原帖链接 · Nikolas Stevenson-Molnar · CC BY-SA 4.0

I eventually discovered that the problem was that PIDFile didn't exist. This doesn't appear to be documented, but you need a valid PIDFile in order to use ExecStartPost (possibly no PIDFile would work, but an missing file definitely doesn't work).

Ironically, I was going to use ExecStartPost to create the pid file, but wanted to try it with something simple (originally had an echo) first.

Changing ExecStartPost to the following made the service work:

ExecStartPost=/bin/sh -c "pgrep -o mbtileserver > /home/crp/var/run/mbtileserver.pid"

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

资料来源与适用范围

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

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

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