1

I need a script to run at startup with sudo permissions that changes GPU power limits and KEEPS the GPU power limits set as long the computer is on. The power limits reset to factory defaults after the computer fully boots.

I tried putting the script in /etc as rc.local after seeing this Q and A, and it sets the power limits where I want them but only for about two seconds. If I press esc during the boot process I can see the script setting the GPU power limits but after the computer is fully booted and I open a terminal and type nvidia-smi to look at the power caps they are back to their factory defaults as if my script never ran.

The contents of my script...

#!/bin/sh -e

sudo nvidia-smi -i 0 -pl 250 sudo nvidia-smi -i 1 -pl 289 sudo nvidia-smi -i 2 -pl 244 sudo nvidia-smi -i 3 -pl 260 exit 0

I can manually run this script after startup with a sudo ./script.sh in the commandline and it does what I want to, but I need it to run automatically when I'm not there to type my password. Can nvidia-smi be made to run without the need for sudo?

I also tried running the script in systemd with the accepted answer here, but it didn't work.

Unit]
Description=Spark service

[Service] ExecStart=/path/to/spark/all.sh

[Install] WantedBy=multi-user.target

chmod u+x /path/to/all.sh Start it:

sudo systemctl start myfirst Enable it to run at boot:

sudo systemctl enable myfirst

I'm sure this is also running the script because I put a sleep for 20 seconds in the script and it takes 20 extra seconds to startup, but again, no power limits are changed when the computer has started.

Ant
  • 171
  • You could install it as a systemd system-level service. – Stephen Boston Apr 20 '21 at 02:15
  • Is that in another Q and A out there like the one I cited? – Ant Apr 20 '21 at 02:35
  • You already know how to run a root-level script at boot. Seems like your real question should be "what's happening later during boot that reverts the settings?" – user535733 Apr 20 '21 at 02:49
  • I was thinking something like this : https://www.shellhacks.com/systemd-service-file-example/ You can find lots of info on systemd services.I believe systemd deprecates rc.local or requires you to enable rc.local. Consider also https://www.linuxbabe.com/linux-server/how-to-enable-etcrc-local-with-systemd – Stephen Boston Apr 20 '21 at 04:05
  • @StephenBoston I tried something like this and it didn't change the GPU power limits. I can't display what I did because I seem to have broken my last Ubuntu install with Coolbits and had to wipe the disk and re-install. I'm out of my depth here. – Ant Apr 21 '21 at 01:40
  • @StephenBoston I'll give you the green check if you want to put the above into systemd. I could try doing it in systemd in the OP. – Ant Apr 21 '21 at 01:49
  • It would be most helpful if you explained how you solved the issue. I may misunderstand but it sounds as if you still have a problem? – Stephen Boston Apr 21 '21 at 02:32
  • @StephenBoston Thank you for responding. I did NOT solve it. I just updated the answer after working with your suggestion. Like my other attempt, it is close, it is doing something before startup but when the OS is fully started the power limits are not my power limits, they are the default power limits I don't want. There is no kind of permission I can give the file to run nvidia-smi without me having to type the password? – Ant Apr 21 '21 at 02:45
  • Check all configuration files for nvidia? Also you don't need to use sudo in a system service because it is running as root. – Stephen Boston Apr 21 '21 at 03:40

0 Answers0