Guest User

Untitled

a guest
Apr 12th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. POST_INIT_SYNC_DELAY=60
  4. POLL_DELAY=60
  5. STALL_THRESHOLD=5
  6.  
  7. if [ -z `pidof btcd` ]; then
  8. echo "Starting btcd"
  9. nohup btcd --datadir=.. --rpcuser=.. --rpcpass=.. &
  10. sleep $POST_INIT_SYNC_DELAY
  11. fi
  12.  
  13. stalls=0
  14. while true; do
  15. start=`btcctl --rpcuser=.. --rpcpass=.. getinfo | grep blocks | cut -f 4 -d ' ' | cut -f 1 -d ','`
  16. sleep $POLL_DELAY
  17. end=`btcctl --rpcuser=.. --rpcpass=.. getinfo | grep blocks | cut -f 4 -d ' ' | cut -f 1 -d ','`
  18. echo "Processed $((end - start)) blocks in the last $POLL_DELAY seconds"
  19. if [[ "$start" == "$end" ]]; then
  20. if (( stalls > STALL_THRESHOLD )); then
  21. echo "Too many stalls detected. Restarting btcd..."
  22. kill `pidof btcd`
  23. sleep 10
  24. nohup btcd --datadir=.. --rpcuser=.. --rpcpass=.. &
  25. stalls=0
  26. else
  27. syncnode=`btcctl getpeerinfo | grep '"syncnode": true' -B 18 | grep '"addr":' | cut -f4 -d '"' | cut -f1 -d ':'`
  28. echo "Found syncnode: $syncnode"
  29. if [ -z "$syncnode" ]; then
  30. echo "Stall detected, but no syncnode found. Restarting btcd..."
  31. kill `pidof btcd`
  32. sleep 10
  33. nohup btcd --datadir=.. --rpcuser=.. --rpcpass=.. &
  34. stalls=0
  35. else
  36. echo "Stall detected! Evicting potentially bad node $syncnode"
  37. btcctl --rpcuser=.. --rpcpass=.. node disconnect $syncnode
  38. stalls=$(( stalls + 1 ))
  39. fi
  40. fi
  41. fi
  42. done
Add Comment
Please, Sign In to add comment