Running a user-level services in Rocky 9

I could not find any documentation on correct setting systemctl --user in a non-desktop setup of rocky linux 9

I’m trying to run test services under a non-priveleged user (gitlab-runner). Unfortunately I have no idea of the correct way to do so.

sh-5.1$ systemctl --user
Failed to connect to bus: No medium found

I’ve checked the dbus launched, and here it is. however it is running under a special “dbus” user, and not my own (ssm-user, or gitlab-runner user)

sh-5.1$ ps aux | grep dbus
dbus         772  0.0  0.0  10808  4536 ?        Ss   Nov12   0:00 /usr/bin/dbus-broker-launch --scope system --audit
dbus         778  0.0  0.0   5132  2832 ?        S    Nov12   0:00 dbus-broker --log 4 --controller 9 --machine-id ec2a795dd342a229ae604c7a0c9b1237 --max-bytes 536870912 --max-fds 4096 --max-matches 131072 --audit

I’ve checked the dbus.service, and looks like it is in place

sh-5.1$ cat /etc/systemd/user/dbus.service
[Unit]
Description=D-Bus User Message Bus
Documentation=man:dbus-broker-launch(1)
DefaultDependencies=false
Before=basic.target shutdown.target
Requires=dbus.socket
Conflicts=shutdown.target

[Service]
Type=notify
Sockets=dbus.socket
ExecStart=/usr/bin/dbus-broker-launch --scope user
ExecReload=/usr/bin/busctl --user call org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus ReloadConfig

[Install]
Alias=dbus.service

so, how could I launch it for a user? What is the expected flow?

# loginctl enable-linger `id -u yourUserName`

and

reboot

@Ritov
I’ve enalbed the lingering and rebooted. Nothing have changed, unfortunately.

Validated with below after reboot

 loginctl show-user ssm-user -p Linger
Linger=yes

Is there any documentation on dbus (or dbus-broker) debugging? I am trying to find any logs, but don’t understand where it could go.

Problem solved, thank you @Ritov .

(Feeling a great temptation skip problem solution and root cause description but i am not such an evil person).

Beside lingering another item is required: user must be logged in through logind. This could be checked by typing

$ whoami
test
$ loginctl list-sessions
SESSION  UID USER SEAT TTY
    c15 1009 test      pts/0

1 sessions listed.

but in my case i was seeing the following behavior

sh-5.1$ whoami
ssm-user
sh-5.1$ loginctl list-sessions
No sessions.
sh-5.1$ sudo su gitlab-runner
bash-5.1$ whoami
gitlab-runner
bash-5.1$ loginctl list-sessions
SESSION UID USER SEAT TTY
    c16   0 root      pts/0

1 sessions listed.

So basically, ssm console which is using ssm user does not using logind to log on. And switching user through sudo su creates a session for a root, not for a user you’re switching to.

TLDR:
To run user services you need

  1. enable lingering via
loginctl enable-linger username

log as user either via

su username

or via normal ssh.

Running “sudo su username” will create dbus for root and will block you from running systemctl --user!!!

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.