Help with scripting a pause/resume toggle in Ubuntu

Moderators: Site Moderators, FAHC Science Team

Post Reply
hiigaran
Posts: 134
Joined: Thu Nov 17, 2011 6:01 pm

Help with scripting a pause/resume toggle in Ubuntu

Post 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.
Last edited by hiigaran on Thu Oct 18, 2018 1:27 pm, edited 1 time in total.
goodyca
Posts: 187
Joined: Sun Dec 02, 2007 12:36 pm

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

Post by goodyca »

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

See:
https://www.reddit.com/r/foldingathome/ ... cpu_power/
hiigaran
Posts: 134
Joined: Thu Nov 17, 2011 6:01 pm

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

Post by hiigaran »

Sorry, I forgot to mention that I'm using Ubuntu, not Windows.
SteveWillis
Posts: 389
Joined: Fri Apr 15, 2016 12:42 am
Hardware configuration: PC 1:
Linux Mint 17.3
three gtx 1080 GPUs One on a powered header
Motherboard = [MB-AM3-AS-SB-990FXR2] qty 1 Asus Sabertooth 990FX(+59.99)
CPU = [CPU-AM3-FX-8320BR] qty 1 AMD FX 8320 Eight Core 3.5GHz(+41.99)

PC2:
Linux Mint 18
Open air case
Motherboard: ASUS Crosshair V Formula-Z AM3+ AMD 990FX SATA 6Gb/s USB 3.0 ATX AMD
AMD FD6300WMHKBOX FX-6300 6-Core Processor Black Edition with Cooler Master Hyper 212 EVO - CPU Cooler with 120mm PWM Fan
three gtx 1080,
one gtx 1080 TI on a powered header

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

Post 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
Image

1080 and 1080TI GPUs on Linux Mint
hiigaran
Posts: 134
Joined: Thu Nov 17, 2011 6:01 pm

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

Post 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?
SteveWillis
Posts: 389
Joined: Fri Apr 15, 2016 12:42 am
Hardware configuration: PC 1:
Linux Mint 17.3
three gtx 1080 GPUs One on a powered header
Motherboard = [MB-AM3-AS-SB-990FXR2] qty 1 Asus Sabertooth 990FX(+59.99)
CPU = [CPU-AM3-FX-8320BR] qty 1 AMD FX 8320 Eight Core 3.5GHz(+41.99)

PC2:
Linux Mint 18
Open air case
Motherboard: ASUS Crosshair V Formula-Z AM3+ AMD 990FX SATA 6Gb/s USB 3.0 ATX AMD
AMD FD6300WMHKBOX FX-6300 6-Core Processor Black Edition with Cooler Master Hyper 212 EVO - CPU Cooler with 120mm PWM Fan
three gtx 1080,
one gtx 1080 TI on a powered header

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

Post 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 ]]
Image

1080 and 1080TI GPUs on Linux Mint
hiigaran
Posts: 134
Joined: Thu Nov 17, 2011 6:01 pm

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

Post by hiigaran »

Tricky in what sense? Does it not find the status 100% of the time?
SteveWillis
Posts: 389
Joined: Fri Apr 15, 2016 12:42 am
Hardware configuration: PC 1:
Linux Mint 17.3
three gtx 1080 GPUs One on a powered header
Motherboard = [MB-AM3-AS-SB-990FXR2] qty 1 Asus Sabertooth 990FX(+59.99)
CPU = [CPU-AM3-FX-8320BR] qty 1 AMD FX 8320 Eight Core 3.5GHz(+41.99)

PC2:
Linux Mint 18
Open air case
Motherboard: ASUS Crosshair V Formula-Z AM3+ AMD 990FX SATA 6Gb/s USB 3.0 ATX AMD
AMD FD6300WMHKBOX FX-6300 6-Core Processor Black Edition with Cooler Master Hyper 212 EVO - CPU Cooler with 120mm PWM Fan
three gtx 1080,
one gtx 1080 TI on a powered header

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

Post 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.
Image

1080 and 1080TI GPUs on Linux Mint
rwh202
Posts: 410
Joined: Mon Nov 15, 2010 8:51 pm
Hardware configuration: 8x GTX 1080
3x GTX 1080 Ti
3x GTX 1060
Various other bits and pieces
Location: South Coast, UK

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

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

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

Post by hiigaran »

Yes! slot-info is exactly what I'm looking for! Coding time!
bruce
Posts: 20824
Joined: Thu Nov 29, 2007 10:13 pm
Location: So. Cal.

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

Post 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.
SteveWillis
Posts: 389
Joined: Fri Apr 15, 2016 12:42 am
Hardware configuration: PC 1:
Linux Mint 17.3
three gtx 1080 GPUs One on a powered header
Motherboard = [MB-AM3-AS-SB-990FXR2] qty 1 Asus Sabertooth 990FX(+59.99)
CPU = [CPU-AM3-FX-8320BR] qty 1 AMD FX 8320 Eight Core 3.5GHz(+41.99)

PC2:
Linux Mint 18
Open air case
Motherboard: ASUS Crosshair V Formula-Z AM3+ AMD 990FX SATA 6Gb/s USB 3.0 ATX AMD
AMD FD6300WMHKBOX FX-6300 6-Core Processor Black Edition with Cooler Master Hyper 212 EVO - CPU Cooler with 120mm PWM Fan
three gtx 1080,
one gtx 1080 TI on a powered header

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

Post 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.
Image

1080 and 1080TI GPUs on Linux Mint
bruce
Posts: 20824
Joined: Thu Nov 29, 2007 10:13 pm
Location: So. Cal.

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

Post by bruce »

In FAHControl, righ-click on one of the Slots.
hiigaran
Posts: 134
Joined: Thu Nov 17, 2011 6:01 pm

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

Post 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?
SteveWillis
Posts: 389
Joined: Fri Apr 15, 2016 12:42 am
Hardware configuration: PC 1:
Linux Mint 17.3
three gtx 1080 GPUs One on a powered header
Motherboard = [MB-AM3-AS-SB-990FXR2] qty 1 Asus Sabertooth 990FX(+59.99)
CPU = [CPU-AM3-FX-8320BR] qty 1 AMD FX 8320 Eight Core 3.5GHz(+41.99)

PC2:
Linux Mint 18
Open air case
Motherboard: ASUS Crosshair V Formula-Z AM3+ AMD 990FX SATA 6Gb/s USB 3.0 ATX AMD
AMD FD6300WMHKBOX FX-6300 6-Core Processor Black Edition with Cooler Master Hyper 212 EVO - CPU Cooler with 120mm PWM Fan
three gtx 1080,
one gtx 1080 TI on a powered header

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

Post 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.
Image

1080 and 1080TI GPUs on Linux Mint
Post Reply