Help with scripting a pause/resume toggle in Ubuntu

Moderators: Site Moderators, PandeGroup

Help with scripting a pause/resume toggle in Ubuntu

Postby hiigaran » Thu Oct 18, 2018 4:39 am

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.
Last edited by hiigaran on Thu Oct 18, 2018 1:27 pm, edited 1 time in total.
User avatar
hiigaran
 
Posts: 134
Joined: Thu Nov 17, 2011 6:01 pm

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

Postby goodyca » Thu Oct 18, 2018 10:35 am

You can get the status of the folding client using telnet.

See:
https://www.reddit.com/r/foldingathome/ ... cpu_power/
goodyca
 
Posts: 139
Joined: Sun Dec 02, 2007 12:36 pm

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

Postby hiigaran » Thu Oct 18, 2018 1:27 pm

Sorry, I forgot to mention that I'm using Ubuntu, not Windows.
User avatar
hiigaran
 
Posts: 134
Joined: Thu Nov 17, 2011 6:01 pm

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

Postby SteveWillis » Thu Oct 18, 2018 2:07 pm

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
Image

1080 and 1080TI GPUs on Linux Mint
SteveWillis
 
Posts: 410
Joined: Fri Apr 15, 2016 12:42 am

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

Postby hiigaran » Thu Oct 18, 2018 2:18 pm

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?
User avatar
hiigaran
 
Posts: 134
Joined: Thu Nov 17, 2011 6:01 pm

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

Postby SteveWillis » Thu Oct 18, 2018 2:28 pm

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 ]]
SteveWillis
 
Posts: 410
Joined: Fri Apr 15, 2016 12:42 am

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

Postby hiigaran » Thu Oct 18, 2018 2:41 pm

Tricky in what sense? Does it not find the status 100% of the time?
User avatar
hiigaran
 
Posts: 134
Joined: Thu Nov 17, 2011 6:01 pm

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

Postby SteveWillis » Thu Oct 18, 2018 2:53 pm

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.
SteveWillis
 
Posts: 410
Joined: Fri Apr 15, 2016 12:42 am

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

Postby rwh202 » Thu Oct 18, 2018 5:31 pm

As goodyca has said, slot status is available over the api:

https://github.com/FoldingAtHome/fah-control/wiki/3rd-party-FAHClient-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
rwh202
 
Posts: 363
Joined: Mon Nov 15, 2010 8:51 pm
Location: South Coast, UK

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

Postby hiigaran » Fri Oct 19, 2018 1:10 am

Yes! slot-info is exactly what I'm looking for! Coding time!
User avatar
hiigaran
 
Posts: 134
Joined: Thu Nov 17, 2011 6:01 pm

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

Postby bruce » Fri Oct 19, 2018 6:17 pm

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.
bruce
 
Posts: 22441
Joined: Thu Nov 29, 2007 10:13 pm
Location: So. Cal.

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

Postby SteveWillis » Sat Oct 20, 2018 12:23 am

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.
SteveWillis
 
Posts: 410
Joined: Fri Apr 15, 2016 12:42 am

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

Postby bruce » Sat Oct 20, 2018 5:00 pm

In FAHControl, righ-click on one of the Slots.
bruce
 
Posts: 22441
Joined: Thu Nov 29, 2007 10:13 pm
Location: So. Cal.

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

Postby hiigaran » Thu Oct 25, 2018 4:34 pm

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?
User avatar
hiigaran
 
Posts: 134
Joined: Thu Nov 17, 2011 6:01 pm

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

Postby SteveWillis » Thu Oct 25, 2018 5:34 pm

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.
SteveWillis
 
Posts: 410
Joined: Fri Apr 15, 2016 12:42 am


Return to Discussions of General-FAH topics

Who is online

Users browsing this forum: Exabot [Bot], Yandex [Bot] and 2 guests

cron