@dncz explains his setup here: Rig total freeze, requires power reset - #9 by dncz
I started to replicate his setup, but realized my smart plugs do not work with IFFFT. One of my rigs has been crashing in the middle of the night and not restarting, so I wrote a simple cron script. I’m not entirely sure what happens to the system when it freezes up, so I don’t know whether the cron script will successfully run, but I guess I’ll find out. Here are the steps:
- Login to hiveos.farm (on a browser), click on your username in the top right corner, scroll down, and click on “Generate new Personal API-token.” Once it’s generated, click on “Show” and copy the 220 character API key and save it somewhere.
- Go to hiveos.farm and click on your farm, then copy and save your farm id from the url. Select each worker from the drop down list, then copy and save your worker id from the url. The format is:
https://the.hiveos.farm/farms/{$farmid}/workers/{$workerid}/
You can test whether the api is working with the following command in Terminal (replace {$apikey} and {$farmid} with that of your own api key and farm id):
curl -s -w '\n%{http_code}' -H 'Content-Type: application/json' -H 'Authorization: Bearer {$apikey}' https://api2.hiveos.farm/api/v2/farms/{$farmid}
- SSH into your rig and create a reboot script. For instance:
mkdir -p /home/user/scripts ; nano /home/user/scripts/worker1reboot.sh
Paste the following code into your script, replacing {$API-Key}, {$farmid}, and {$workerid} with that of your own api key, farm id, and worker id:
#!/bin/bash
worker_status=$( curl -s -w '\n%{http_code}' -H 'Content-Type: application/json' -H 'Authorization: Bearer {$apikey}' https://api2.hiveos.farm/api/v2/farms/{$farmid}/workers/{$workerid} | grep -o '"stats":{"online":[a-z]*' | sed 's/[ ":,{]//g;s/stats//;s/online//' )
datetime=$(date '+%Y-%m-%d_%H:%M:%S')
if [[ "$worker_status" = 'false' ]] ; then
echo "cron script initiated at $datetime" >> /home/user/worker1reboot.log
sleep 300
if [[ "$worker_status" = 'false' ]] ; then
echo "cron script restarted worker1 at $datetime" >> /home/user/worker1reboot.log
sudo reboot
fi
elif [[ "$worker_status" != 'true' ]] && [[ "$worker_status" != 'false' ]] ; then
echo "cron script initiated at $datetime, but was unable to check the online status of worker1" >> /home/user/worker1reboot.log
fi
- Save the script by pressing ctrl+x, then y, then enter. Then make the script executable:
chmod +x /home/user/scripts/worker1reboot.sh
- Create a new crontab with
crontab -e
. Scroll to the bottom of the window and press enter. Paste this on the last line:
*/5 * * * * /home/user/scripts/worker1reboot.sh
Assuming you’re editing the crontab with Internal File Editor, which is the default editor for hiveos, press enter again so there’s another blank line on the bottom, otherwise the editor will complain about it. Then press FN+F10 and then y to save your changes. The cron script will run every five minutes and check the online status of your worker. If the status shows offline, it will wait for five minutes and check the status again. If it’s still offline, it will reboot the rig.