1

I'm trying to set up some user services using Ansible and systemd.

On Ubuntu and RHEL 7 I'm getting

# systemctl --user status
Failed to get D-Bus connection: Connection refused

For Ubuntu I clarified the error, it's because of this:

https://docs.ansible.com/ansible/latest/modules/systemd_module.html

run systemctl within a given service manager scope, either as the default system scope (system), the current user's scope (user), or the scope of all users (global). For systemd to work with 'user', the executing user must have its own instance of dbus started (systemd requirement). The user dbus process is normally started during normal login, but not during the run of Ansible tasks. Otherwise you will probably get a 'Failed to connect to bus: no such file or directory' error.

Basically DBus needs to be started before systemd --user can work. I'm not sure how to do that either, but I can work around it in other ways, I think.

However, the main blocker right now is: how do I check, generically, for the availability of the functionality?

I tried systemctl show and there's no explicit "user" feature. Is the flag the "+PAM" from the Features line? I know that systemd uses PAM at least partially to implement it, I don't know if it's needed for other features.

How can I check that "my" systemd supports --user in a reliable manner? Is there a file I could check? A command? Something else? DBus voodoo?

oblio
  • 111
  • 2
  • Systemd user instance is not optional, something just killed your user-level dbus, which should be started by systemd user instance – 炸鱼薯条德里克 Jan 22 '20 at 14:20
  • Or you fail to connect because you're not the same user as the systemd user instance – 炸鱼薯条德里克 Jan 22 '20 at 14:21
  • I noticed the target user doesn't have /run/user/*, maybe that's related to the DBus issue you mention? Are there any proper tutorials for running DBus manually, if need be? – oblio Jan 22 '20 at 16:04
  • 1
    Does this answer your question? [How do I setup user autostart and properly configure systemd user services?](https://unix.stackexchange.com/questions/434494/how-do-i-setup-user-autostart-and-properly-configure-systemd-user-services) Or https://unix.stackexchange.com/a/477049/5132 . Or https://unix.stackexchange.com/a/431915/5132 . – JdeBP Jan 22 '20 at 17:19
  • you shouldn't, as I said, logind feature and systemd per-user instance is not optional, `systemctl --user` is always available as long as you've logged in. But when you're not, it isn't supposed to work and will not work. – 炸鱼薯条德里克 Jan 24 '20 at 01:43
  • So from an automation tool POV, I'd have to have my scripts login and start everything? Not very automation friendly. Do you happen to know how this can be done? I'm not sure what to Google... – oblio Jan 24 '20 at 15:05
  • @JdeBP, yes, I think those questions combined answer my question. I can probably work it out on my own to combine them into a solution, thanks a lot! – oblio Jan 24 '20 at 15:07

0 Answers0