nan0s7 / nfancurve

A small and lightweight POSIX script for using a custom fan curve in Linux for those with an Nvidia GPU.
GNU General Public License v3.0
314 stars 57 forks source link

Exit script #34

Open MichalRybecky opened 3 years ago

MichalRybecky commented 3 years ago

Hello! I have added the temp.sh script to run as pre-run script for games through Lutris. It works great, but I have problem that I don't know how to exit it so the fans would come back to normal mode. I have tried adding post-exit bash scripts that had only pkill temp, trying kill -INT $(pgrep temp.sh) or even looking into the temp.sh script. Because I have very little knowledge about this, I wasn't able to find anything useful there. Is there any way that I can exit this script from other bash script? Thanks a lot, love your work btw!

nan0s7 commented 3 years ago

pkill temp will certainly stop the script, but it won't trigger the finish() function, which resets all the values to their defaults. But kill -INT $(pgrep temp) works fine for me (you only need the extra .sh if you have another process called temp, so it's probably wise just to use the full temp.sh).

The finish() function does activate upon an INT kill, so that's why the regular pkill command doesn't activate it.

If the kill -INT $(pgrep temp.sh) isn't working, double check that you're not running temp.sh with sudo permissions.

If that still doesn't work, feel free to show me the code you're using and how you've set it up. :)

PS. if it's not working, check if pgrep temp or pgrep temp.sh returns anything (should be a number).

MichalRybecky commented 3 years ago

So the way I have set it up is that I have created additional script called temp_kill.sh with nothing more than kill -INT $(pgrep temp.sh) in it. Lutris runs this script when the game is closed.

I have done some more testing and turns out that kill -INT $(pgrep temp.sh) does work only when I manually run it using terminal, or when I run the temp_kill.sh script. If the script is activated by Lutris at the game exit, it kills the command but probably does not activate finish() function (not sure how to check if this function is activated or not, but since it doesn't come back to auto mode, I would assume it doesn't).

I have played with pgrep temp.sh as well. When the game starts, I can hear my fans speed up (I have set fan speed to 100 for testing so I am able to hear it) and this command returns a numeric value. If I run temp_kill.sh script while the game runs, it kills the temp.sh and fans return to auto mode. pgrep temp.sh does not return any value anymore. But if I exit the game, Lutris executes temp_kill.sh, pgrep temp.sh does not return any value, but fans do not return to auto mode, they are still doing 100% speed (so probably finish() function wasn't activated).

Not really sure why is this possible, maybe there is a problem with how Lutris runs these scripts, as when I run the kill script manually, it works. My thoughts are to implement the finish() function to my temp_kill.sh script, although that might not be necessary if I can kill the script properly.

nan0s7 commented 3 years ago

Sorry for the delay in responce; had a busy week.

Yeah it really does sound like Lutris isn't executing the script properly. Perhaps it's running the script in another session of some sort, and can't see the temp.sh script?

What you could do is have a script that manages, or launches beside Lutris. Then have it watch and wait until Lutris closes and can kill the script. Unless there is some sort of option in Lutris to set the working directory or something like that. To be honest I don't know enough about Lutris; I'll have to look into it when I'm not busy.

Sorry this is a bit difficult to get working how you want :/

MichalRybecky commented 3 years ago

No worries! I will spend some time to (hopefully) find some reasonable solution. When I do, I'll be sure to post it here. Thanks for your time!