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
- BTCCTL='docker exec btcd btcctl --rpcuser=YOUR_USER --rpcpass=YOUR_PASS --rpccert=/rpc/rpc.cert '
- stalls=0
- echo "Starting watcher..."
- while true; do
- start=`$BTCCTL getinfo | jq -r .blocks`
- sleep $POLL_DELAY
- end=`$BTCCTL getinfo | jq -r .blocks`
- 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..."
- docker restart btcd
- stalls=0
- else
- syncnode=`eval "$BTCCTL getpeerinfo | jq -r '.[] | select(.syncnode == true) | .addr' | cut -f1 -d:"`
- if [ -z "$syncnode" ]; then
- echo "Stall detected, but no syncnode found. Restarting btcd..."
- docker restart btcd
- stalls=0
- else
- echo "Stall detected! Evicting potentially bad node $syncnode"
- eval "$BTCCTL node disconnect $syncnode"
- stalls=$(( stalls + 1 ))
- fi
- fi
- fi
- done
Add Comment
Please, Sign In to add comment