1

I need to check a program that has a systemd unit under user namespace and this is my monit conf (systemd conf works without any problem):

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

This conf does not work because I get the error Failed to connect to bus: No such file or directory. I get the same error if I run the follow command sudo /usr/bin/systemctl --user -q is-active foo, so seems that the directive as uid pioz and gid pioz does not work. If I change the config like this, all works well.

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

Any idea why as uid does not work?

Pioz
  • 103
  • 7
  • have you ever been able to figure it out? @Pioz – pragmatic_programmer May 23 '21 at 11:29
  • Could you be running into an issue where monit executes programs with very few [environment variables](https://mmonit.com/monit/documentation/monit.html#ENVIRONMENT) and so no DBUS info is present whereas using `su` causes an environment to be setup? May be able to debug using [the monit FAQ](https://mmonit.com/wiki/Monit/FAQ#execution). – Dan May 18 '22 at 01:42

0 Answers0