mirror of
https://github.com/mynodebtc/mynode.git
synced 2024-11-15 18:02:49 +00:00
29 lines
697 B
Bash
Executable File
29 lines
697 B
Bash
Executable File
#!/bin/bash
|
|
|
|
set -x
|
|
set -e
|
|
|
|
# Try to get peer info - if it fails serice will restart until bitcoin is ready
|
|
bitcoin-cli getpeerinfo
|
|
|
|
# Give bitcoin 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 |