3

currently using RHEL 7.9, I had to activate the systemctl user mode creating a service called [email protected] which is not the problem but I think is linked following this guide: https://serverfault.com/questions/936985/cannot-use-systemctl-user-due-to-failed-to-get-d-bus-connection-permission

I created a test service:

[Unit] Description=Foo [Service] ExecStart=/home/glcmsd/test.sh [Install] WantedBy=multi-user.target 

where test.sh is

#!/bin/bash sleep 2h 

I then run

systemctl daemon-reload --user systectl start test --user systemctl enable test --user 

the service is working correctly

-bash-4.2$ systemctl status test --user ● test.service - Foo Loaded: loaded (/home/glcmsd/.config/systemd/user/test.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2022-04-08 10:14:38 BST; 5s ago Main PID: 97445 (test.sh) CGroup: /user.slice/user-1258074.slice/[email protected]/test.service ├─97445 /bin/bash /home/glcmsd/test.sh └─97446 sleep 2h 

then run sudo reboot and when I check the status of the service is dead inactive

-bash-4.2$ systemctl status test --user ● test.service - Foo Loaded: loaded (/home/glcmsd/.config/systemd/user/test.service; enabled; vendor preset: enabled) Active: inactive (dead) 

Any clue on how I can debug it or what I am doing wrong?

EDIT: I did the same test on rhel 8.2 which it doesn't require to follow the guide and I get the same result

EDIT2: Thank you for answering, it was very helpful. Trying to follow Torin's solution, it worked for RHEL 8.2 but not for 7.9 This is the implementation in 8.2:

$ cat /home/glcmsd/.config/systemd/user/test.service [Unit] Description=Foo [Service] ExecStart=/home/glcmsd/test.sh [Install] WantedBy=default.target $ systemctl stop test --user $ systemctl disable test --user Removed /home/glcmsd/.config/systemd/user/multi-user.target.wants/test.service. $ systemctl daemon-reload --user $ systemctl status test --user ● test.service - Foo Loaded: loaded (/home/glcmsd/.config/systemd/user/test.service; disabled; vendor preset: enabled) Active: inactive (dead) Apr 08 12:10:52 npc027161 systemd[2187]: Started Foo. Apr 08 13:23:08 npc027161 systemd[2187]: Stopping Foo... Apr 08 13:23:08 npc027161 systemd[2187]: Stopped Foo. $ systemctl start test --user $ systemctl enable test --user Created symlink /home/glcmsd/.config/systemd/user/default.target.wants/test.service → /home/glcmsd/.config/systemd/user/test.service. [glcmsd@npc027161 ~]$ systemctl status test --user ● test.service - Foo Loaded: loaded (/home/glcmsd/.config/systemd/user/test.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2022-04-08 13:24:59 BST; 27s ago Main PID: 16291 (test.sh) CGroup: /user.slice/user-1258074.slice/[email protected]/test.service ├─16291 /bin/bash /home/glcmsd/test.sh └─16292 sleep 2h Apr 08 13:24:59 npc027161 systemd[2187]: Started Foo. $ sudo reboot ################################################################################# [glcmsd@npc027161 ~]$ systemctl status test --user ● test.service - Foo Loaded: loaded (/home/glcmsd/.config/systemd/user/test.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2022-04-08 13:27:16 BST; 5s ago Main PID: 1798 (test.sh) CGroup: /user.slice/user-1258074.slice/[email protected]/test.service ├─1798 /bin/bash /home/glcmsd/test.sh └─1801 sleep 2h Apr 08 13:27:16 npc027161 systemd[1777]: Started Foo. [glcmsd@npc027161 ~]$ 

This is the same implementation on 7.9:

-bash-4.2$ cat /home/glcmsd/.config/systemd/user/test.service [Unit] Description=Foo [Service] ExecStart=/home/glcmsd/test.sh [Install] WantedBy=default.target -bash-4.2$ vi /home/glcmsd/.config/systemd/user/test.service -bash-4.2$ systemctl stop test --user -bash-4.2$ systemctl disable test --user Removed symlink /home/glcmsd/.config/systemd/user/multi-user.target.wants/test.service. -bash-4.2$ systemctl daemon-reload --user -bash-4.2$ -bash-4.2$ systemctl status test --user ● test.service - Foo Loaded: loaded (/home/glcmsd/.config/systemd/user/test.service; disabled; vendor preset: enabled) Active: inactive (dead) -bash-4.2$ systemctl start test --user -bash-4.2$ systemctl enable test --user Created symlink from /home/glcmsd/.config/systemd/user/default.target.wants/test.service to /home/glcmsd/.config/systemd/user/test.service. -bash-4.2$ systemctl status test --user ● test.service - Foo Loaded: loaded (/home/glcmsd/.config/systemd/user/test.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2022-04-08 13:29:46 BST; 20s ago Main PID: 3369 (test.sh) CGroup: /user.slice/user-1258074.slice/[email protected]/test.service ├─3369 /bin/bash /home/glcmsd/test.sh └─3370 sleep 2h -bash-4.2$ sudo reboot ################################################################################# -bash-4.2$ systemctl status test --user ● test.service - Foo Loaded: loaded (/home/glcmsd/.config/systemd/user/test.service; enabled; vendor preset: enabled) Active: inactive (dead) 

EDIT3: For now I abandoned using systemd in user mode on the rhel7.9. I noticed there are some difference with the systemd versions. Rhel 7.9 has systemd 219 the 8.2 has 239. systemd239 seems allows user mode by creating 2 services one for enabling lingering at boot. and another one creates a runtime dir for the user. I noticed there is also an runtime dir executable file in 239 that is not present on 219. Don't know what to do at this point. apologies if the last edit is not precise, going to update it later adding some more info

3
  • Probably just a copy/paste typo, but I think systemctl daemon-relaod --user should be systemctl daemon-reload --user Commented Apr 8, 2022 at 13:05
  • after following Torin answer the commands were without typo and still issue persist. (output in EDIT2) Commented Apr 8, 2022 at 13:15
  • Instead of adding "edits" at the end of your question, rewrite your question so that it describes a single coherent and up to date issue. We don't really do interactive debugging sessions here and you seem to ask new questions in your edits. This makes it very difficult to come up with a single answer that would answer all the questions. Commented Apr 17, 2022 at 16:50

1 Answer 1

1

multi-user.target is a system target and probably isn't what you want.

From systemd.special(7):

Special User Units

When systemd runs as a user instance, the following special units are available:

default.target
This is the main target of the user session, started by default. Various services that compose the normal user session should be pulled into this target. In this regard, default.target is similar to multi-user.target in the system instance, but it is a real unit, not an alias.

In addition, the following units are available which have definitions similar to their system counterparts: exit.target, shutdown.target, sockets.target, timers.target, paths.target, bluetooth.target, printer.target, smartcard.target, sound.target.

So you'll want to switch to WantedBy=default.target instead.

1
  • That solved the issue for RHEL 8.2 but on RHEL 7.9 the issue persisted. I provided the commands I run on the EDIT2 Commented Apr 8, 2022 at 12:56

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.