使用 monit 检查 systemd 单元

使用 monit 检查 systemd 单元

我需要检查一个在用户命名空间下有 systemd 单元的程序,这是我的 monit conf(systemd conf 工作没有任何问题):

check program foo with path "/usr/bin/systemctl --user -q is-active foo" as uid pioz and gid pioz
  start program = "/usr/bin/systemctl --user start foo" as uid pioz and gid pioz
  stop program = "/usr/bin/systemctl --user stop foo" as uid pioz and gid pioz
  if status != 0 then restart
  if 5 restarts within 5 cycles then timeout

这个conf不起作用,因为我收到错误Failed to connect to bus: No such file or directory。如果我运行 follow 命令sudo /usr/bin/systemctl --user -q is-active foo,我会得到同样的错误,所以看起来该指令as uid pioz and gid pioz不起作用。如果我像这样更改配置,一切都会正常。

check program foo with path "/bin/su -c '/usr/bin/systemctl --user -q is-active foo' pioz"
  start program = "/bin/su -c '/usr/bin/systemctl --user start foo' pioz"
  stop program = "/bin/su -c '/usr/bin/systemctl --user stop foo' pioz"
  if status != 0 then restart
  if 5 restarts within 5 cycles then timeout

知道为什么as uid不起作用吗?

相关内容