Little script I wrote :
#!/usr/bin/python2.7
# Licensed to WTFPL ( http://www.wtfpl.net/about/ )
import sys
import signal
import datetime
import pexpect
import time
cmd = "./jhProtominer"
args = [ "-o", "http://ypool.net:10034",
"-u", "your_worker",
"-p", "your_password",
"-t", "4",
"-m512" ]
SHARE_LOG = True
if SHARE_LOG:
logfile=open('./ypool.log', 'a', buffering=1)
# Signal handling
def signal_handler(signum,frame):
if protominer.isalive():
global stop
if signum == 2:
#print("\nProgram received SIGINT signal")
protominer.sendintr()
else:
#print("Program received SIGTERM signal")
protominer.terminate()
stop = True
signal.signal(signal.SIGTERM, signal_handler)
signal.signal(signal.SIGINT, signal_handler)
# Main loop
number = 0
stop = False
while not stop:
protominer = pexpect.spawn(cmd,args,timeout=None,logfile=sys.stdout)
line = protominer.readline()
while line:
try:
line = line.decode()
except:
pass
if "Connection to server lost" in line or "Connection attempt failed" in line:
if SHARE_LOG:
lost_time = datetime.datetime.now() \
.strftime('[ERROR] %Y-%m-%d %H:%M:%S CONNECTION DOWN\n') \
.encode('utf8')
logfile.write(lost_time)
print ("Connection down")
break
if SHARE_LOG:
if "Share found!" in line:
number += 1
share = "[INFO] %Y-%m-%d %H:%M:%S SHARE : " + str(number) + "\n"
newshare_time = datetime.datetime.now() \
.strftime(share) \
.encode('utf8')
logfile.write(newshare_time)
line = protominer.readline()
if protominer.isalive():
protominer.terminate()
try:
protominer.wait()
except pexpect.ExceptionPexpect, e:
if e.value != 'Cannot wait for dead child process.':
raise
if stop:
print("Exiting...")
else:
if SHARE_LOG:
restart_time = datetime.datetime.now() \
.strftime('[INFO] %Y-%m-%d %H:%M:%S RESTART\n') \
.encode('utf8')
logfile.write(restart_time)
print("Restarting in 10s...")
time.sleep(10)
if SHARE_LOG:
logfile.close()
If the connection attempt fails or the connection is lost it restarts the miner in 10s. If the miner is killed ( like with pkill ), it automatically restarts it too. If the script is killed, it ensures that the miner is stopped properly before exiting.
If SHARE_LOG is set to True, each time it finds a share, it logs the time and share number to ypool.log, also logs connection down and restart times ( maybe I ll disable this because when the pool goes down for a long time that's a lot of useless writing ).
If you want to give it a try you need pexpect installed, if you have pip just do pip install pexpect.