2020-08-24 01:26:26 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -x
|
|
|
|
set -e
|
|
|
|
|
2021-04-11 00:51:26 +00:00
|
|
|
# Try to get peer info - if it fails serice will restart until bitcoin is ready
|
2020-08-24 01:26:26 +00:00
|
|
|
bitcoin-cli getpeerinfo
|
|
|
|
|
2021-04-11 00:51:26 +00:00
|
|
|
# Give bitcoin some time to start
|
2020-08-24 01:26:26 +00:00
|
|
|
sleep 2m
|
|
|
|
|
|
|
|
# Check if btc has peers
|
|
|
|
while true; do
|
|
|
|
echo "Checking Bitcoin peer count..."
|
|
|
|
PEER_COUNT=$(bitcoin-cli getpeerinfo | grep "id" | wc -l)
|
|
|
|
if [ "$PEER_COUNT" -lt "3" ]; then
|
|
|
|
echo "$PEER_COUNT peers. Try adding one."
|
|
|
|
|
|
|
|
RANDOM_PEER=$(shuf /usr/share/mynode/bitcoin_peers.txt | head -n 1)
|
|
|
|
echo "Attempting to add peer $RANDOM_PEER"
|
|
|
|
|
|
|
|
bitcoin-cli addnode "$RANDOM_PEER" "onetry"
|
|
|
|
|
|
|
|
sleep 1m
|
|
|
|
else
|
|
|
|
echo "We have $PEER_COUNT peers!"
|
|
|
|
sleep 60m
|
|
|
|
fi
|
|
|
|
done
|