Created
September 1, 2018 16:58
-
-
Save YihaoPeng/204550320b4dad672d68e541cf15df37 to your computer and use it in GitHub Desktop.
getwork-monitor-eth-parity.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Parity's getwork RPC is often stuck in a block number | |
# So I wrote a script to monitor and automatically restart it | |
# | |
# @copyright btc.com | |
# @author Yihao Peng <yihao.peng@bitmain.com> | |
# @since 2018-07 | |
# | |
# bash /work/script/getwork-monitor-eth-parity.sh >>/work/script/logs/getwork-monitor-eth-parity.log 2>&1 | |
# | |
SROOT=$(cd $(dirname "$0"); pwd) | |
cd $SROOT | |
# parity docker name | |
DOCKER_NAME="eth-parity" | |
# parity RPC URL | |
RPC_URL="http://localhost:8545/" | |
################################# | |
blockNumber=`curl -s -S --max-time 5 --data-binary '{"jsonrpc": "2.0", "method": "eth_blockNumber", "params": [], "id": 1}' -H 'content-type: application/json' "$RPC_URL" 2>/dev/null | jq -r '.result'` | |
let blockNumber=$blockNumber | |
getWorkNumber=`curl -s -S --max-time 5 --data-binary '{"jsonrpc": "2.0", "method": "eth_getWork", "params": [], "id": 1}' -H 'content-type: application/json' "$RPC_URL" 2>/dev/null | jq -r '.result[3]'` | |
let getWorkNumber=$getWorkNumber | |
if [ "$getWorkNumber" = "0" ]; then | |
echo "$DOCKER_NAME still sync... blockNumber: $blockNumber, getworkNumber: $getWorkNumber" | |
exit 1 | |
fi | |
let diff=$blockNumber-$getWorkNumber | |
DATE=`date "+%Y-%m-%d %H:%M:%S"` | |
if [ $diff -ge 5 ]; then | |
echo "[$DATE] getwork stuck: blockNumber: $blockNumber, getworkNumber: $getWorkNumber, diff: $diff" | |
echo -n "[$DATE] docker restarted: " | |
docker restart "$DOCKER_NAME" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment