tl;dr
Change WantedBy=graphical-session.target
to WantedBy=default.target
.
Hypothesis
I suspect your problem is with the [Install]
section of your service file. Installing it based on multi-user.target
might be quite normal for system units, but the equivalent for user-units is default.target
. See the systemd.special(7) manpage for details.
| system target | near-equivalent user target |
|-------------------|-----------------------------|
| multi-user.target | default.target |
| graphical.target | graphical-session.target |
Other targets that may also be interesting to you are graphical-session-pre.target
or xdg-desktop-autostart.target
.
default.target MVCE
Here's a minimal example I just tried on my Debian 11 machine:
The service file:
$ systemctl --user cat simpleuser.service
# /home/stew/.config/systemd/user/simpleuser.service
[Unit]
Description=Simple User Service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/true
[Install]
WantedBy=default.target
I installed it with:
$ systemctl --user enable simpleuser.service
Created symlink /home/stew/.config/systemd/user/default.target.wants/simpleuser.service → /home/stew/.config/systemd/user/simpleuser.service.
I performed a reboot and I can see that the service is active:
$ systemctl --user status simpleuser.service
● simpleuser.service - Simple User Service
Loaded: loaded (/home/stew/.config/systemd/user/simpleuser.service; enabled; vendor preset: enable>
Active: active (exited) since Sun 2020-07-12 10:12:54 CEST; 13min left
Process: 1127 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 1127 (code=exited, status=0/SUCCESS)
Jul 12 10:12:54 stewbian systemd[1106]: Starting Simple User Service...
Jul 12 10:12:54 stewbian systemd[1106]: Finished Simple User Service.
If you're wondering about the (exited)
substate: If you use something like Type=simple
and ExecStart=/bin/sleep infinity
, then you'll get (running)
instead.
graphical-session.target problems
I found your question in the form of a bug report on github.
If you're installing based on graphical-session.target, then it's possible that isn't starting. I just ran this on my KDE/i3 setup and reproduced on a vanilla Gnome3 setup.
$ systemctl --user status graphical-session.target
● graphical-session.target - Current graphical user session
Loaded: loaded (/usr/lib/systemd/user/graphical-session.target; static; vendor preset: disabled)
Active: inactive (dead)
Docs: man:systemd.special(7)
It sounds like DEs don't really implement this target per its design. In that case, you may be better-off using WantedBy=default.target
. Your script doesn't look GUI-based so I bet default.target
would be fine. Otherwise, you could consider using After=graphical.target
in your [Unit]
section.
According to systemd.special(7) manpage, graphical-session.target
should be BoundBy=
the DE (i.e. {gnome,kde,xfce}-session.target
). This way, when Gnome starts, it will raise graphical-session.target. When I inspect the dbus objects I clearly see no relationships with any target which would raise it.
$ busctl introspect --user org.freedesktop.systemd1 \
/org/freedesktop/systemd1/unit/graphical_2dsession_2etarget \
org.freedesktop.systemd1.Unit
NAME TYPE SIGNATURE RESULT/VALUE FLAGS
.ActiveState property s "inactive" emits-change
.After property as 2 "simpleuser.service" "basic.target" const
.Before property as 1 "shutdown.target" const
.BindsTo property as 0 const
.BoundBy property as 0 const
.Conflicts property as 1 "shutdown.target" const
.ConsistsOf property as 2 "gnome-terminal-server.service" "duns… const
.Description property s "Current graphical user session" const
.Documentation property as 1 "man:systemd.special(7)" const
.LoadState property s "loaded" const
.Names property as 1 "graphical-session.target" const
.PartOf property as 0 const
.RequiredBy property as 0 const
.Requires property as 1 "basic.target" const
.SubState property s "dead" emits-change
.UnitFilePreset property s "disabled" -
.UnitFileState property s "static" -
.WantedBy property as 0 const
.Wants property as 1 "simpleuser.service" const
I did some digging into the mailing lists and found that {gnome,kde,xfce}-session.target
was proposed only four years ago with the intention that gnome, kde, xfce would ship the *.target
files. It hasn't happened (yet). Therefore, even though it's documented, it's incomplete. Therefore you shouldn't use graphical-session.target
yet.
systemctl status nfancurve
? Add all of that to your question. – Nasir Riley Jul 11 '20 at 21:23systemctl --user status nfancurve.service
, since it's a user service.systemctl status nfancurve
outputsUnit nfancurve.service could not be found.
. – Wout12345 Jul 12 '20 at 7:21systemctl --user cat nfancurve.service
, What's in the[Install]
section of the unit? – Stewart Jul 12 '20 at 7:41/usr/lib/systemd/user/nfancurve.service
(the unit file, I assume?) matchesnfancurve.service
from that repository. I'll add the information about the package and installation to my question. – Wout12345 Jul 12 '20 at 17:19WantedBy=graphical-session.target
. – Wout12345 Jul 12 '20 at 17:21