【发布时间】:2019-11-25 08:38:16
【问题描述】:
我有一个在 Red Hat Enterprise Linux 7 上使用 Type=notify 的服务单元和 bash 脚本的简单示例,我正在尝试开始工作。
当服务单元配置为以 root 身份启动脚本时,一切都会按预期进行。添加User=testuser 时失败。虽然脚本最初启动(如进程列表所示),systemctl 服务从未收到指示就绪的通知消息,因此它挂起并最终超时。
[Unit]
Description=My Test
[Service]
Type=notify
User=testuser
ExecStart=/home/iatf/test.sh
[Install]
WantedBy=multi-user.target
Test.sh(由具有执行权限的testuser拥有)
#!/bin/bash
systemd-notify --status="Starting..."
sleep 5
systemd-notify --ready --status="Started"
while [ 1 ] ; do
systemd-notify --status="Processing..."
sleep 3
systemd-notify --status="Waiting..."
sleep 3
done
当以 root 身份运行时 systemctl status test 会显示从我的 test.sh bash 脚本发送的正确状态和状态消息。当User=testuser 服务挂起然后超时,journalctl -xe 报告:
Jul 15 13:37:25 tstcs03.ingdev systemd[1]: Cannot find unit for notify message of PID 7193.
Jul 15 13:37:28 tstcs03.ingdev systemd[1]: Cannot find unit for notify message of PID 7290.
Jul 15 13:37:31 tstcs03.ingdev systemd[1]: Cannot find unit for notify message of PID 7388.
Jul 15 13:37:34 tstcs03.ingdev systemd[1]: Cannot find unit for notify message of PID 7480.
我不确定这些 PID 是什么,因为它们没有出现在 ps -ef 列表中
【问题讨论】:
标签: bash systemd rhel7 systemctl