forked from CryptoManufaktur-io/rp-ha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-ecsync.sh
executable file
·21 lines (20 loc) · 807 Bytes
/
check-ecsync.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/bin/sh
MIN_PEERS=10
SYNC=$(curl -s -m2 -N -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_syncing","params":[],"id":1}' "https://${HAPROXY_SERVER_NAME}")
echo "${SYNC}" | grep -q "result"
if [ $? -ne 0 ]; then
return 1
fi
SYNC=$(echo "${SYNC}" | jq .result)
PEERS_HEX=$(curl -s -m2 -N -X POST -H "Content-Type: application/json" -m 2 -d '{"jsonrpc":"2.0","method":"net_peerCount","params": [],"id":1}' "https://${HAPROXY_SERVER_NAME}")
echo "${PEERS_HEX}" | grep -q "result"
if [ $? -ne 0 ]; then
return 1
fi
PEERS_HEX=$(echo "${PEERS_HEX}" | jq -r .result | awk -F'0x' '{ print $2 }')
PEERS=$(echo "ibase=16; ${PEERS_HEX}" | awk '{ print $1 " " toupper($2) }' | bc -l)
if [ "${SYNC}" = "false" -a "${PEERS}" -ge "$MIN_PEERS" ]; then
return 0
else
return 1
fi