I'm trying to set up user-level services, using this answer to a similar question. I have create the required files and rebooted.
I'm making progress because I now get "Failed to get D-bus connection: permission denied" when it was "Failed to get D-bus connection: connection refused", but I'm stumped because I don't know what object it is trying to access (file? socket?) and so cannot even check current permissions. Any ideas?
So far I have added:
loginctl enable-linger userservice
/usr/lib/systemd/user/dbus.service (-rw-r–r– root root)
[Unit]
Description=D-Bus User Message Bus
Requires=dbus.socket
[Service]
ExecStart=/usr/bin/dbus-daemon --session --address=systemd: --nofork --nopidfile --systemd-activation
ExecReload=/usr/bin/dbus-send --print-reply --session --type=method_call --dest=org.freedesktop.DBus / org.freedesktop.DBus.ReloadConfig
[Install]
Also=dbus.socket
/usr/lib/systemd/user/dbus.socket (-rw-r–r– root root)
[Unit]
Description=D-Bus User Message Bus Socket
[Socket]
ListenStream=%t/bus
ExecStartPost=-/bin/systemctl --user set-environment DBUS_SESSION_BUS_ADDRESS=unix:path=%t/bus
[Install]
WantedBy=sockets.target
Also=dbus.service
/home/userservice/.config/systemd/user/userservice.service
[Unit]
Description=Test user-level service
[Service]
Type=dbus
BusName=com.wtf.service
ExecStart=/home/userservice/userservice.py
Restart=on-failure
[Install]
WantedBy=default.target
Not added any links elsewhere…
To make it fail:
systemctl --user status
Edit 2018-10-25:
Added export XDG_RUNTIME_DIR=/run/user/$(id -u)
to .bashrc
. The variable is set and now I get: Failed to get D-us connection: no such file or directory
. Strangely, neither man systemctl
nor systemctl --help
mention the --user
option, while both mention --system
and specify that this is the default (so what are the other options).
Using RHEL 7.4 (with systemd 219
as reported by systemctl --version
) with SELinux.
Best Answer
I've noticed the tableau server uses --user systemd services - they even have a note about this in their docs: https://help.tableau.com/current/server-linux/en-us/systemd_user_service_error.htm
How they do it (example is with a userid 29575)
After you create that file:
And you'll need to set XDG_RUNTIME_DIR in env of that user via bashrc or similar:
I've tested in on a recent RHEL 7.8 and it works as expected, I can run "systemctl --user status" as my user after doing this.