You are not logged in.

#1 2022-07-31 06:06:33

ElegantConsulting
Member
Registered: 2022-02-22
Posts: 12

[Solved] nvidia-settings won't run via systemd

Hello,
I'm completely lost. I don't understand how systemd and x/wayland/whatever-graphical-system-we-use-now works in general. I can write a basic service to run a script or command, but that's about it.

I wrote a script to start my gpus fans.

/root/nvidiafans/startfans.sh

nvidia-settings -c :1 -a [gpu:0]/GPUFanControlState=1 -a [fan]/GPUTargetFanSpeed=55

It works fine if I run it in gnome from the terminal as root. If I try to run it from a basic service, it complains and won't work. I've tried searching in the wiki, forum, and online to no avail. I can't seem to find anything that addresses my issue.

/etc/systemd/system/nvidiafans.service

[Unit]
Description=fan autostart

[Service]
Type=oneshot
ExecStart=/bin/sh /root/nvidiafans/startfans.sh

[Install]
WantedBy=graphical.target

systemctl status nvidiafans.service

Job for nvidiafans.service failed because the control process exited with error code.
See "systemctl status nvidiafans.service" and "journalctl -xeu nvidiafans.service" for details.
× nvidiafans.service - fan autostart
     Loaded: loaded (/etc/systemd/system/nvidiafans.service; disabled; vendor preset: disabled)
     Active: failed (Result: exit-code) since Sun 2022-07-31 02:02:04 EDT; 5ms ago
    Process: 13280 ExecStart=/bin/sh /root/nvidiafans/startfans.sh (code=exited, status=1/FAILURE)
   Main PID: 13280 (code=exited, status=1/FAILURE)
        CPU: 18ms

Jul 31 02:02:04 Juliet systemd[1]: Starting fan autostart...
Jul 31 02:02:04 Juliet sh[13281]: Authorization required, but no authorization protocol specified
Jul 31 02:02:04 Juliet sh[13281]: ERROR: Error resolving target specification 'gpu:0' (No targets match target specification), specified in assignment '[gpu:>
Jul 31 02:02:04 Juliet systemd[1]: nvidiafans.service: Main process exited, code=exited, status=1/FAILURE
Jul 31 02:02:04 Juliet systemd[1]: nvidiafans.service: Failed with result 'exit-code'.
Jul 31 02:02:04 Juliet systemd[1]: Failed to start fan autostart.

Last edited by ElegantConsulting (2022-08-14 06:02:33)

Offline

#2 2022-07-31 06:22:02

d_fajardo
Member
Registered: 2017-07-28
Posts: 1,652

Re: [Solved] nvidia-settings won't run via systemd

/root/nvidiafans/startfans.sh

You normally don't access the /root folder like this as it is auto-populated by root.
Try putting the script locally and call it from there.

Offline

#3 2022-08-01 21:10:32

ElegantConsulting
Member
Registered: 2022-02-22
Posts: 12

Re: [Solved] nvidia-settings won't run via systemd

I tried moving everything to the home directory of my local user, and changing ownership to my local user. I am getting the same result hmm

Offline

#4 2022-08-02 05:50:25

seth
Member
Registered: 2012-09-03
Posts: 58,806

Re: [Solved] nvidia-settings won't run via systemd

It doesn't matter where you put the script (though "/root/nvidiafans/" is a weird position and "/usr/local/bin" would be more common) and in this case what the scripts rights are (as you're explicitly invoking it w/ /bin/sh and as root)
The problem is *when* it's executed and "Error resolving target specification 'gpu:0'" says "too early" (before the GPU is ready)
https://bbs.archlinux.org/viewtopic.php … 7#p1558317 went for looping until the GPU is ready and you can use https://wiki.archlinux.org/title/Kernel … _KMS_start to make that happen faster.

Online

#5 2022-08-03 05:56:31

ElegantConsulting
Member
Registered: 2022-02-22
Posts: 12

Re: [Solved] nvidia-settings won't run via systemd

Thank you dfarjardo and seth, I appreciate the general info. That clarifies much. I appreciate the workaround as well and will give it a shot.

I'm a little confused how the GPU isn't ready when I am invoking the graphical.target. Am I using the wrong target? Is there a different Keyword I should be using? Maybe:

[Install]
After=graphical.target

Last edited by ElegantConsulting (2022-08-03 05:56:46)

Offline

#6 2022-08-03 06:13:06

seth
Member
Registered: 2012-09-03
Posts: 58,806

Online

#7 2022-08-03 06:17:11

ElegantConsulting
Member
Registered: 2022-02-22
Posts: 12

Re: [Solved] nvidia-settings won't run via systemd

I did not enable it. Sorry, I was trying to ask a followup/different question about systemd. Please let me rephrase the question: is there a built in way for service to run after gdm starts/is running?

Offline

#8 2022-08-03 06:37:38

seth
Member
Registered: 2012-09-03
Posts: 58,806

Re: [Solved] nvidia-settings won't run via systemd

That would not suffice since GDM will start the display server (and probably wait for the GPU in doing so) but you could try running this in /etc/gdm/Init/Default

Online

#9 2022-08-03 06:42:28

ElegantConsulting
Member
Registered: 2022-02-22
Posts: 12

Re: [Solved] nvidia-settings won't run via systemd

Ah, I see. That makes sense. I wasn't aware GDM had its own script system. I'll look into that and try it! Thanks.

Offline

#10 2022-08-14 05:22:01

ElegantConsulting
Member
Registered: 2022-02-22
Posts: 12

Re: [Solved] nvidia-settings won't run via systemd

Adding the code to the end of /etc/gdm/Init/Default worked great! Thanks!

Offline

#11 2022-08-14 05:59:19

seth
Member
Registered: 2012-09-03
Posts: 58,806

Re: [Solved] nvidia-settings won't run via systemd

Greta.
Please always remember to mark resolved threads by editing your initial posts subject - so others will know that there's no task left, but maybe a solution to find.
Thanks.

Online

Board footer

Powered by FluxBB