Page 1 of 1

Help with scripting a pause/resume toggle in Ubuntu

Posted: Thu Oct 18, 2018 4:39 am
by hiigaran
On one of my Linux systems, I've got a CPU and GPU core running most of the time. However, for gaming purposes, or when GPU folding interferes with video playback on my browser, I pause the GPU slot. To do this, I have the following custom hotkeys:

Ctrl + F12: FAH Pause:

Code: Select all

sh -c "FAHClient --send-pause; notify-send \"Folding Paused\""
F12: FAH Resume:

Code: Select all

sh -c "FAHClient --send-unpause; notify-send \"Folding Resumed\""
This works just fine. However, I have a lot of hotkeys, many of which toggle on/off states like the above. In an effort to save on available keys, I was wondering if anyone knew how to combine the two commands into one key, so that, for example, pressing F12 the first time will pause, and pressing it a second time will unpause.

Now, considering that FAHControl shows the state of each slot, such as whether it is running, paused, finishing, or failed, there must be a way to get that same information via the command line. Question is, what do I type to obtain the state of slot x? If I can get that data, I should be able to write a simple if/then statement to create a toggle.

Re: Help with scripting a pause/resume toggle in Ubuntu

Posted: Thu Oct 18, 2018 10:35 am
by goodyca
You can get the status of the folding client using telnet.

See:
https://www.reddit.com/r/foldingathome/ ... cpu_power/

Re: Help with scripting a pause/resume toggle in Ubuntu

Posted: Thu Oct 18, 2018 1:27 pm
by hiigaran
Sorry, I forgot to mention that I'm using Ubuntu, not Windows.

Re: Help with scripting a pause/resume toggle in Ubuntu

Posted: Thu Oct 18, 2018 2:07 pm
by SteveWillis
Personally I'd set it to run on idle instead of pause since I am confident that at some point I'd forget to set it back to fold and not notice till the next day.

On Linux I'd use this, setting a flag in my home directory to indicate the status:
if [ -e $HOME/idleflag ] ; then FAHClient --send-command "options idle=false" ;rm $HOME/idleflag;else FAHClient --send-command "options idle=true";touch $HOME/idleflag; fi

Unfortunately if you are running more than one gpu that sets all the slots to idle.
With your pause command you can actually pause just one slot
FAHClient --send-pause 0

Re: Help with scripting a pause/resume toggle in Ubuntu

Posted: Thu Oct 18, 2018 2:18 pm
by hiigaran
Yeah, I was trying to avoid a script that creates a flag like that. Even after a solid hour of searching, I found nothing that could suggest some sort of "FAHClient --slot-status" command, but I'm fairly certain there has to be something. How else does FAHControl know?

Re: Help with scripting a pause/resume toggle in Ubuntu

Posted: Thu Oct 18, 2018 2:28 pm
by SteveWillis
I've been writing scripts for folding for a year and I've never found anything to indicate status. You can grep in the log.txt file but that can be tricky. I do that some in my reboot.sh script that I link to in my signature.

if [[ $(grep $FS $logFileToRead|tail -1 |grep -c "Paused") == 1 ]]

Re: Help with scripting a pause/resume toggle in Ubuntu

Posted: Thu Oct 18, 2018 2:41 pm
by hiigaran
Tricky in what sense? Does it not find the status 100% of the time?

Re: Help with scripting a pause/resume toggle in Ubuntu

Posted: Thu Oct 18, 2018 2:53 pm
by SteveWillis
Just depends on what you are looking for. The example I gave you is pretty reliable. Dealing with finishing slots, not so much. If you ever have problems with slots that quit folding you ought to have a look at my script. It executes reboots and client restarts as necessary when a folding slot gets hung up for a variety of reasons. Granted that if you don't OC (which I no longer do) the problems are a lot less. I still haven't worked out the bugs with dealing with slots set to finish.

Instead of defining hot keys I deal with a lot of tasks by defining custom launchers in a panel that I locate at the top of my screen.

Re: Help with scripting a pause/resume toggle in Ubuntu

Posted: Thu Oct 18, 2018 5:31 pm
by rwh202
As goodyca has said, slot status is available over the api:

https://github.com/FoldingAtHome/fah-co ... Client-API

slot-info returns:

Code: Select all

[
  {
    "id": "01",
    "status": "RUNNING",
    "description": "gpu:0:GP104 [GeForce GTX 1080] 8873",
    "options": {},
    "reason": "",
    "idle": False
  },
  {
    "id": "02",
    "status": "PAUSED",
    "description": "gpu:2:GP104 [GeForce GTX 1080] 8873",
    "options": {},
    "reason": "finished",
    "idle": False
  }
]
Should be relatively easy to parse for "status" on a slot by slot basis

Re: Help with scripting a pause/resume toggle in Ubuntu

Posted: Fri Oct 19, 2018 1:10 am
by hiigaran
Yes! slot-info is exactly what I'm looking for! Coding time!

Re: Help with scripting a pause/resume toggle in Ubuntu

Posted: Fri Oct 19, 2018 6:17 pm
by bruce
SteveWillis wrote:Personally I'd set it to run on idle instead of pause since I am confident that at some point I'd forget to set it back to fold and not notice till the next day.
Setting your GPU slot to idle is still a rational idea. Setting the slot for your gaming GPU to TRUE will suspend that slot whenever the Mouse/Keyboard are active, so it will certainly pause when you start gaming and resume folding when the gaming session ends. The only drawback is that it will also pause if you use the Mouse/Keyboard for Internet/email/etc. so you'll have to turn on/off IDLE as noted above unless you don't do much internet/email/etc. on that machine.

If you have more than one GPU, you can leave the non-gaming GPU(s) to IDLE=FALSE and they'll keep folding -- if, of course, your game doesn't need all GPUs.

Re: Help with scripting a pause/resume toggle in Ubuntu

Posted: Sat Oct 20, 2018 12:23 am
by SteveWillis
I couldn't figure out how to set just one gpu to "on idle" Everything I tried was all gpus or none. Pause, on the other hand, let me do that.

Re: Help with scripting a pause/resume toggle in Ubuntu

Posted: Sat Oct 20, 2018 5:00 pm
by bruce
In FAHControl, righ-click on one of the Slots.

Re: Help with scripting a pause/resume toggle in Ubuntu

Posted: Thu Oct 25, 2018 4:34 pm
by hiigaran
Alright, I've got most of the script made. The part I'm having trouble with is actually parsing the slot-info output. Anyone know how to store the "status" value of a specific "id", without the need to install additional packages?

Code: Select all

#nc output:

nc localhost 36330 <<EOF
slot-info
exit
EOF

#Store status in FAHSlotStatus variable:

?

#If/then statement to toggle Folding state:

if [ $(FAHSlotStatus) = "PAUSED" ]
then
FAHClient --send-unpause
notify-send "Folding Resumed"
elif [ $(FAHSlotStatus) = "RUNNING" ]
then
FAHClient --send-pause 1
notify-send "GPU Folding Paused"
fi
I used nc instead of telnet in the first part of the code, since it was easier to get the JSON output, but I don't actually know how to parse it. Then again, perhaps I'm going a completely wrong direction. Scripting isn't my strong point, I'm afraid. Maybe someone else might know how to finish this?

Re: Help with scripting a pause/resume toggle in Ubuntu

Posted: Thu Oct 25, 2018 5:34 pm
by SteveWillis
bruce wrote:In FAHControl, righ-click on one of the Slots.
The issue was doing it with a script or from the command line since he wanted to do it with a hot key.