mynode/rootfs/standard/usr/bin/mynode_add_bitcoin_peers.sh
2020-08-23 20:26:26 -05:00

29 lines
699 B
Bash
Executable File

#!/bin/bash
set -x
set -e
# Try to get peer info - if it fails serice will restart until bitcoind is ready
bitcoin-cli getpeerinfo
# Give bitcoind some time to start
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