0

I'm trying to setup user level Services(Python/Java/Node JS Processes) which need to run all the time, until I stop explicitly. The service need to be start/stopped as non root user.

I've created service file under, ~/.config/systemd/user/. When I tried to load, systemctl --user daemon-reload, it's failing with the following error.

$ systemctl --user daemon-reload
Failed to get D-Bus connection: No such file or directory

I understand D-Bus won't run without Desktop session, but there is no Desktop session, it's one of the VMs provided by the Company. We don't enable Desktop sessions for the Linux servers.

$ ps -ef | grep systemd | grep -v grep
root          1      0  0 Jul25 ?        00:01:33 /usr/lib/systemd/systemd --switched-root --system --deserialize 22
root        544      1  0 Jul25 ?        00:00:33 /usr/lib/systemd/systemd-journald
root        591      1  0 Jul25 ?        00:00:03 /usr/lib/systemd/systemd-udevd
dbus        783      1  0 Jul25 ?        00:01:21 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation
root        857      1  0 Jul25 ?        00:00:34 /usr/lib/systemd/systemd-logind

How do I create user level services without Desktop session ?

1 Answer 1

0

It will work with just two commands.

cat << 'EOF' >> ~USERNAME/.profile
export XDG_RUNTIME_DIR=/run/user/$(id -u)
EOF
loginctl enable-linger $USERNAME
7
  • thanks for the quick response. $ export XDG_RUNTIME_DIR=/run/user/$(id -u) [root@myserver system]# loginctl enable-linger zeus $ ls /var/lib/systemd/linger/$USERNAME zeus Still, fails. $ systemctl --user daemon-reload Failed to get D-Bus connection: No such file or directory Commented Jul 31, 2022 at 3:20
  • imgur.com/L95Qx7p Tried your solution @crpb, but it didn't work. Commented Jul 31, 2022 at 3:28
  • hmm.. so no session is running for that user? i created one and it started w/o login. "testuser 469295 0.0 0.0 15396 7252 ? Ss 05:32 0:00 /lib/systemd/systemd --user" Commented Jul 31, 2022 at 3:53
  • Jul 31 05:32:33 intra2 useradd[469176]: new group: name=testuser, GID=2006 Jul 31 05:32:33 intra2 useradd[469176]: new user: name=testuser, UID=2006, GID=2006, home=/home/testuser, shell=/bin/zsh, from=/dev/pts/0 Jul 31 05:32:45 intra2 systemd: pam_unix(systemd-user:session): session opened for user testuser(uid=2006) by (uid=0) Commented Jul 31, 2022 at 3:53
  • And as for the "applications.services". i usually just create those in another folder and enable this file with that user when everything is setup. Commented Jul 31, 2022 at 3:59

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.