Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not autostart with the systemd user service enabled #33

Open
bernharl opened this issue Jun 10, 2020 · 10 comments
Open

Does not autostart with the systemd user service enabled #33

bernharl opened this issue Jun 10, 2020 · 10 comments

Comments

@bernharl
Copy link

I'm running Manjaro KDE.

When booting after having run "systemctl --user enable nfancurve.service" the service still doesn't run. It works perfectly when running it manually after logging in though.

running "systemctl --user status nfancurve" without manually starting it says that it is inactive (dead).

I see that the service relies on graphical-session.target, which is also inactive for me even when logged in graphically.

I tried making the service not rely on graphical-session.target. It then autostarts correctly, but nfancurve itself crashed due to no available screen.

Is there a way to edit the service file so that it starts only when logged in graphically without relying on graphical-session.target? If not, is there a way to make graphical-session.target work properly with Manjaro KDE?

@nan0s7
Copy link
Owner

nan0s7 commented Jun 11, 2020

Hmm I'm not sure. I'll see if I can look into it, although I don't have much time right now.

In the meantime, you could set up a script that's executed by your display manager to just start the service after your user has logged in.

@stewbond
Copy link

I found this is the case in both kde/i3 and gnome in Debian 11 and Debian 10 (respectively):

$ 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: enabled)
   Active: inactive (dead)
     Docs: man:systemd.special(7)

Reading around, it sounds like graphical-session.target isn't really implemented per docs. Since this isn't really a GUI-based application, you should be able to WantedBy=default.target instead. This means it'll start as soon as the user logs in (instead of as soon as their desktop environment is available). You could maybe try After=graphical.target in the [Unit] section if you feel that you really do need the desktop environment available first.

@nan0s7
Copy link
Owner

nan0s7 commented Jul 13, 2020

Thanks for the information! Would you just remove the Requires=graphical-session.target or change it to something else? I personally don't use the service file, nor did I write it, so I haven't got the required knowledge for this part... :P

@Wout12345
Copy link

Wout12345 commented Aug 28, 2020

I had the same issue and managed to fix it by removing the Requires line from the service file and replacing graphical-session.target on both the After and WantedBy lines by default.target (more info: https://unix.stackexchange.com/questions/597990/enabled-systemd-user-service-doesnt-start-at-login/606777#606777). My service file now looks like this:

[Unit]
Description=Nfancurve service
After=default.target

[Service]
ExecStart=/bin/sh /usr/bin/nfancurve -c /etc/nfancurve.conf
KillSignal=SIGINT

[Install]
WantedBy=default.target

Could the service file please be fixed in the next update? :) Else updating my installed packages would overwrite the fix ...

@nan0s7
Copy link
Owner

nan0s7 commented Sep 11, 2020

Sorry for the huge delay! I've changed the service file to reflect your modifications, so hopefully it should work better now. Let me know how it goes for everyone here.

@frederikstroem
Copy link

frederikstroem commented Nov 25, 2021

Running nfancurve from AUR on Arch, with a GeForce GTX 1070 graphics card installed.

I finally managed to get nfancurve running! Wout12345's solution got me far, but without a 20 seconds sleep before starting the service, my service died after boot.

───────┬─────────────────────────────────────────────────────────────────
       │ File: /usr/lib/systemd/user/nfancurve.service
───────┼─────────────────────────────────────────────────────────────────
   1   │ [Unit]
   2   │ Description=Nfancurve service
   3   │ After=default.target
   4   │ 
   5   │ [Service]
   6   │ ExecStartPre=/bin/sleep 20
   7   │ ExecStart=/bin/sh /usr/bin/nfancurve -c /etc/nfancurve.conf
   8   │ KillSignal=SIGINT
   9   │ 
  10   │ [Install]
  11   │ WantedBy=default.target
───────┴─────────────────────────────────────────────────────────────────

After changing the file, I also had to reload my services.

❯ systemctl --user daemon-reload

And then finally reenable the nfancurve service to apply my changes.

❯ systemctl reenable --user nfancurve

And now everything seems to be working! 😅🥳

Thanks for the great software BTW! 👍 Makes me feel more at ease to not have my graphics card running burning hot all the time 🥵

@nan0s7
Copy link
Owner

nan0s7 commented Nov 26, 2021

Running nfancurve from AUR on Arch, with a GeForce GTX 1070 graphics card installed.

I finally managed to get nfancurve running! Wout12345's solution got me far, but without a 20 seconds sleep before starting the service, my service died after boot.

───────┬─────────────────────────────────────────────────────────────────
       │ File: /usr/lib/systemd/user/nfancurve.service
───────┼─────────────────────────────────────────────────────────────────
   1   │ [Unit]
   2   │ Description=Nfancurve service
   3   │ After=default.target
   4   │ 
   5   │ [Service]
   6   │ ExecStartPre=/bin/sleep 20
   7   │ ExecStart=/bin/sh /usr/bin/nfancurve -c /etc/nfancurve.conf
   8   │ KillSignal=SIGINT
   9   │ 
  10   │ [Install]
  11   │ WantedBy=default.target
───────┴─────────────────────────────────────────────────────────────────

After changing the file, I also had to reload my services.

❯ systemctl --user daemon-reload

And then finally reenable the nfancurve service to apply my changes.

❯ systemctl reenable --user nfancurve

And now everything seems to be working! sweat_smilepartying_face

Thanks for the great software BTW! +1 Makes me feel more at ease to not have my graphics card running burning hot all the time hot_face

Oh that's awesome to hear! Glad it is working now! :D

I shall update the service file with your modification now.

Thank you for looking into it and figuring it out!

@ReneHollander
Copy link
Contributor

a18602b implemented this change but I don't agree with it and it breaks my setup. Per https://www.freedesktop.org/software/systemd/man/systemd.special.html#graphical-session.target I think graphical-session.target is still the right target. The default.target doesn't imply a graphical session needs to be running, but would cause the nfancurve service to be started. AFAIK nvidia-settings still needs Xorg running (Wayland support seems to be in progress though), so I am not sure moving to default.target makes sense.

I had the same issue and managed to fix it by removing the Requires line from the service file and replacing graphical-session.target on both the After and WantedBy lines by default.target (more info: https://unix.stackexchange.com/questions/597990/enabled-systemd-user-service-doesnt-start-at-login/606777#606777). My service file now looks like this:

[Unit]
Description=Nfancurve service
After=default.target

[Service]
ExecStart=/bin/sh /usr/bin/nfancurve -c /etc/nfancurve.conf
KillSignal=SIGINT

[Install]
WantedBy=default.target

Could the service file please be fixed in the next update? :) Else updating my installed packages would overwrite the fix ...

Reading https://unix.stackexchange.com/questions/597990/enabled-systemd-user-service-doesnt-start-at-login/606777#606777 seems to indicate this target isn't properly implemented, but looking at the gnome source code shows this has been done for some time: https://github.com/search?q=org%3AGNOME+graphical-session&type=code

There is a good chance that slower distros didn't pick the change up yet though, so I am mostly speaking about Arch here.

Running nfancurve from AUR on Arch, with a GeForce GTX 1070 graphics card installed.

I finally managed to get nfancurve running! Wout12345's solution got me far, but without a 20 seconds sleep before starting the service, my service died after boot.

───────┬─────────────────────────────────────────────────────────────────
       │ File: /usr/lib/systemd/user/nfancurve.service
───────┼─────────────────────────────────────────────────────────────────
   1   │ [Unit]
   2   │ Description=Nfancurve service
   3   │ After=default.target
   4   │ 
   5   │ [Service]
   6   │ ExecStartPre=/bin/sleep 20
   7   │ ExecStart=/bin/sh /usr/bin/nfancurve -c /etc/nfancurve.conf
   8   │ KillSignal=SIGINT
   9   │ 
  10   │ [Install]
  11   │ WantedBy=default.target
───────┴─────────────────────────────────────────────────────────────────

After changing the file, I also had to reload my services.

❯ systemctl --user daemon-reload

And then finally reenable the nfancurve service to apply my changes.

❯ systemctl reenable --user nfancurve

And now everything seems to be working! sweat_smilepartying_face

Thanks for the great software BTW! +1 Makes me feel more at ease to not have my graphics card running burning hot all the time hot_face

Did you check if the graphical-session.target is reached? There might be a misconfiguration somewhere that delays the unit and causes nfancurve to never start for you with the original unit file.

Currently I am inclined to update the package on the AUR, but keep the unit file using graphical-session.target. If this keeps causing issues for Arch users I am willing to reconsider, but for now I believe Arch users shouldn't need to rely on default.target here.

archlinux-github pushed a commit to archlinux/aur that referenced this issue Aug 4, 2022
For now keeping the old service file. See nan0s7/nfancurve#33
nan0s7 added a commit that referenced this issue Aug 8, 2022
@nan0s7
Copy link
Owner

nan0s7 commented Aug 8, 2022

@ReneHollander I've reverted the changes to the service file, and added information about how one may workaround the issues on their system to the readme file. New release created.

Thanks for looking into it. I know the Nvidia API requires a graphical session so that all the commands work, however the ones used in this script technically do not require it. Hopefully in the future I can find a way to circumvent nvidia-smi so it's usable on a headless system.

@ReneHollander
Copy link
Contributor

Thanks for reverting. In case there are more issues reported here I will try to be more responsive to investigate the systemd dependency issues again.

I updated the AUR package as well :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants