Skip to content

Instantly share code, notes, and snippets.

@stralex7
Last active April 12, 2018 11:48
Show Gist options
  • Save stralex7/29b02159af174eff1556bb62da480077 to your computer and use it in GitHub Desktop.
Save stralex7/29b02159af174eff1556bb62da480077 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import socket
import json
import time
import os
import sys
# reset if mh drops below this num
min_hashes=61900
# time for reboot + claymore to get share and start hashing
loop_seconds = 60
delay_seconds = 90
host='127.0.0.1'
port=8080
def check_rig(host,port):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.connect((host, port))
print("connected")
s.send('{"id":0,"jsonrpc":"2.0","method":"miner_getstat1"}\n'.encode("utf-8"))
j=s.recv(2048)
s.close()
resp=json.loads(j.decode("utf-8"))
resp=resp['result']
res0 = resp[2].split(';')
hashes = int(res0[0])
print("KH/s=" + str(hashes) + " Accepted:" +res0[1]+" Rejected:"+res0[2])
hash_ok=min_hashes < hashes
print("hashes ok is: " + str(hash_ok))
sys.stdout.flush()
return hash_ok
except TimeoutError:
print("connection timeout")
sys.stdout.flush()
except ConnectionRefusedError:
print("connection refused")
sys.stdout.flush()
except:
print("exception")
sys.stdout.flush()
return False
print("Initial start delay")
sys.stdout.flush()
time.sleep(delay_seconds)
# main loop
while True:
if not check_rig(host,port):
print("resetting rig")
os.system('/sbin/reboot')
# else:
# print("rig ok!")
# print( "loop sleep" )
time.sleep(loop_seconds)
@stralex7
Copy link
Author

stralex7 commented Apr 12, 2018

Enable logs from previous boots:

 mkdir /var/log/journal
 systemd-tmpfiles --create --prefix /var/log/journal
 systemctl restart systemd-journald

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment