Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- POST_INIT_SYNC_DELAY=60
- POLL_DELAY=60
- STALL_THRESHOLD=5
- if [ -z `pidof btcd` ]; then
- echo "Starting btcd"
- nohup btcd --datadir=.. --rpcuser=.. --rpcpass=.. &
- sleep $POST_INIT_SYNC_DELAY
- fi
- stalls=0
- while true; do
- start=`btcctl --rpcuser=.. --rpcpass=.. getinfo | grep blocks | cut -f 4 -d ' ' | cut -f 1 -d ','`
- sleep $POLL_DELAY
- end=`btcctl --rpcuser=.. --rpcpass=.. getinfo | grep blocks | cut -f 4 -d ' ' | cut -f 1 -d ','`
- echo "Processed $((end - start)) blocks in the last $POLL_DELAY seconds"
- if [[ "$start" == "$end" ]]; then
- if (( stalls > STALL_THRESHOLD )); then
- echo "Too many stalls detected. Restarting btcd..."
- kill `pidof btcd`
- sleep 10
- nohup btcd --datadir=.. --rpcuser=.. --rpcpass=.. &
- stalls=0
- else
- syncnode=`btcctl getpeerinfo | grep '"syncnode": true' -B 18 | grep '"addr":' | cut -f4 -d '"' | cut -f1 -d ':'`
- echo "Found syncnode: $syncnode"
- if [ -z "$syncnode" ]; then
- echo "Stall detected, but no syncnode found. Restarting btcd..."
- kill `pidof btcd`
- sleep 10
- nohup btcd --datadir=.. --rpcuser=.. --rpcpass=.. &
- stalls=0
- else
- echo "Stall detected! Evicting potentially bad node $syncnode"
- btcctl --rpcuser=.. --rpcpass=.. node disconnect $syncnode
- stalls=$(( stalls + 1 ))
- fi
- fi
- fi
- done
Add Comment
Please, Sign In to add comment