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
systemctl daemon-relaod --usershould besystemctl daemon-reload --user