小编Bri*_*ian的帖子

systemctl 服务 systemd-notify 不适用于非 root 用户

我有一个关于 Red Hat Enterprise Linux 7 上的服务单元和 bash 脚本的简单示例,Type=notify我正在尝试使用它来工作。

当服务单元配置为以 root 身份启动脚本时,一切都会按预期进行。添加的时候User=testuser就失败了。当脚本最初启动时(如进程列表中所示),systemctl服务从未收到指示就绪的通知消息,因此它挂起并最终超时。

[Unit]
Description=My Test
[Service]
Type=notify
User=testuser
ExecStart=/home/iatf/test.sh
[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

当以 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 …
Run Code Online (Sandbox Code Playgroud)

bash systemd rhel7 systemctl

6
推荐指数
1
解决办法
4247
查看次数

标签 统计

bash ×1

rhel7 ×1

systemctl ×1

systemd ×1