systemd ExecStartPost 似乎未被调用

systemd ExecStartPost 似乎未被调用

我使用以下配置来启动beanstalkd进程

[Service]
ExecStart=/usr/local/bin/beanstalkd 
ExecStartPost=pgrep beanstalkd > /var/run/beanstalkd.pid

最后一行应该在进程启动后生成一个 pidfile,但该文件却没有创建。为什么?

或者还有其他方法可以强制创建 pidfile systemd

答案1

systemd 不需要 Type=simple 服务的 pidfile。它将在前台管理守护进程。systemctl status SERVICE_NAME将显示主进程(以及 cgroup 中任何其他进程)的 pid。

为了完整起见,您的 ExecStartPost 行不起作用,因为 systemd 不使用 shell 来执行命令并且不执行 $PATH 查找,所以您必须使用ExecStartPost=/bin/sh -c "...",但正如我所说,该行是不必要的。

答案2

如果你仍然需要答案(或者其他人需要),你需要一个 shell 上下文来运行 pgrep,因此正确的命令应该是

ExecStartPost=/usr/bin/zsh -c 'pgrep process_name > /var/run/process_name.pid'

答案3

这表明执行顺序是从底部到顶部 http://lists.fedoraproject.org/pipermail/devel/2011-July/153897.html 您的 ExecStartPost 在 ExecStart 之前运行

相关内容