Guest User

PS3_miner_watchdog

a guest
Mar 4th, 2012
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.30 KB | None | 0 0
  1. #!/bin/bash
  2. # A watchdog for minerd
  3. # v0.0.1 by MasTi
  4. #
  5. # Q: why? I never ever even thought about a watchdog, minerd runs rockstable since months on all my rigs, never had any issues with it!
  6. # A: You are right, same here, however my Fat Lady (Playstation 3) seems to have some stability problems!
  7. #    Probably because it was not designed to run 24/7 under full workload so once in a while (about 1-2 times a day)
  8. #    one of the SPU threads on the Cell Processor suddenly stops working but minerd continues to run!
  9. #    This will leave you with ~6kh/s less mining power and you probably won't even notice it because there are still 40 kh/s left :D
  10. #    Well, to fire and forget minerd like on other systems I set up this little watchdog. Thats it! Enjoy!
  11. #
  12. #
  13. ##
  14. ###
  15. ####
  16. ##### EDIT THIS !! Your pool and user credentials.
  17. ####
  18. ###
  19. ##
  20. #
  21. # URL
  22. desturl="http://somepool.bit"
  23. #
  24. # Port
  25. destport="1234"
  26. #
  27. # username
  28. username="me"
  29. #
  30. # password
  31. password="mysecret"
  32. #
  33. ##
  34. ###
  35. ####
  36. ##### Advanced config! - Normally no need to change!
  37. ####
  38. ###
  39. ##
  40. #
  41. # Watchdog scan period
  42. # check every x seconds - 60 is really enough
  43. scantime="60"
  44. #
  45. # check for Stalerate in percent - To "disable" set to e.g. 100
  46. # 0.5 is a good but still high value, but you can set it to whatever you want.
  47. # if the watchdog determines a higher value it will stop the miner and let the system cool down the specified amout of seconds
  48. maxstalerate="0.44"
  49. #
  50. # Time for the system to cool down
  51. # stops miner for x seconds before restarting it
  52. cooldowntime="30"
  53. #
  54. # path to the miner - need only be changed if the miner is not the same directory as this script
  55. minerpath="./"
  56. #
  57. # miner executable _without_ any slashes or path - just the name
  58. miner="minerd"
  59. #
  60. # overviewlogfile - an overview of performed actions by the watchdog in a simple logfile
  61. overviewlogfile="./overview"
  62. #
  63. ##
  64. ###
  65. ####
  66. ##### Do NOT edit anything below this line!
  67. ####
  68. ###
  69. ##
  70. #
  71. # logfile (needed for watchdog(this script))
  72. minerlogfile="./log"
  73. datenow=`date`
  74. echo "WATCHDOG: $datenow - Starting $miner on $desturl:$destport - Worker: $username"
  75. echo "WATCHDOG: $datenow - watchdog interval set to $scantime seconds."
  76. echo "WATCHDOG: $datenow - cooldown time on error set to $cooldowntime seconds."
  77. echo "WATCHDOG: $datenow - thread watchdog enabled."
  78. echo "WATCHDOG: $datenow - stalerate watchdog enabled - limit at $maxstalerate%."
  79. echo "WATCHDOG: $datenow - NOTE: You have to kill the $miner process manually"
  80. echo "WATCHDOG: $datenow - NOTE: if you exit this script by pressing strg+c"
  81. echo "WATCHDOG: $datenow - NOTE: To do this just type the following into a console"
  82. echo "WATCHDOG: $datenow - NOTE: killall $miner"
  83. echo "WATCHDOG: $datenow - NOTE: Thanks for reading this, have a nice day!"
  84.  
  85. echo "WATCHDOG: $datenow - Starting $miner on $desturl:$destport - Worker: $username" >> $overviewlogfile
  86. echo "WATCHDOG: $datenow - watchdog interval set to $scantime seconds." >> $overviewlogfile
  87. echo "WATCHDOG: $datenow - cooldown time on error set to $cooldowntime seconds." >> $overviewlogfile
  88. echo "WATCHDOG: $datenow - thread watchdog enabled." >> $overviewlogfile
  89. echo "WATCHDOG: $datenow - stalerate watchdog enabled - limit at $maxstalerate%." >> $overviewlogfile
  90.  
  91. $minerpath$miner --url $desturl:$destport --userpass $username:$password 2>> $minerlogfile >/dev/null &
  92. while :
  93. do
  94.     pidofminer=`pidof $miner`
  95.     sleep $scantime
  96.     datenow=`date`
  97.     nullhashes=`cat ./log | tail -n 20 | grep "0.00 khash" | wc -l`
  98.     if [ "$nullhashes" -ne "0" ]; then
  99.         timecode=`date`
  100.         echo "WATCHDOG: $datenow - Detected non working thread!! :( - Restarting!"
  101.         echo "WATCHDOG: $datenow - Stopping miner for $cooldowntime seconds to let the system cool down a little..."
  102.         echo "WATCHDOG: $datenow - Switching to new logfile. Compressing old logfile to $minerlogfile-$timecode.bz2"
  103.         echo "WATCHDOG: $datenow - Detected non working thread!! :( - Restarting!" >> $overviewlogfile
  104.         kill $pidofminer >/dev/null
  105.         mv $minerlogfile $minerlogfile-"$timecode"
  106.         bzip2 -z -f -q -s -9 $minerlogfile-"$timecode"
  107.         sleep $cooldowntime
  108.         $minerpath$miner --url $desturl:$destport --userpass $username:$password 2>> $minerlogfile &
  109.     fi
  110.     yays=`cat $minerlogfile | grep yay | wc -l`
  111.     boos=`cat $minerlogfile | grep boo | wc -l`
  112.     stalerate=`echo "scale=2; $boos*100/$yays" | bc -l `
  113.     staleratetrue=`echo "scale=2; $stalerate>$maxstalerate" | bc`
  114.     echo "WATCHDOG: $datenow - Threads: OK! - Stalerate: 0$stalerate% of allowed $maxstalerate% (Shares: $yays accepted - $boos rejected)"
  115.     if [ "$staleratetrue" = "1" ]; then
  116.         staleratetrue="0"
  117.         timecode=`date`
  118.         echo "WATCHDOG: $datenow - Stalerate 0$stalerate% ($boos/$yays) higher than allowed! ($maxstalerate%) - Restarting!"
  119.         echo "WATCHDOG: $datenow - Stopping miner for $cooldowntime seconds to let the system cool down a little..."
  120.         echo "WATCHDOG: $datenow - Switching to new logfile. Compressing old logfile to $minerlogfile-$timecode.bz2"
  121. [D      echo "WATCHDOG: $datenow - Stalerate 0$stalerate% ($boos/$yays) higher than allowed! ($maxstalerate%) - Restarting!" >> $overviewlogfile
  122.         kill $pidofminer >/dev/null
  123.         mv $minerlogfile $minerlogfile-"$timecode" >/dev/null
  124.         bzip2 -z -f -q -s -9 $minerlogfile-"$timecode"
  125.         sleep $cooldowntime
  126.         $minerpath$miner --url $desturl:$destport --userpass $username:$password 2>> $minerlogfile &
  127.     fi
  128. done
Add Comment
Please, Sign In to add comment