|
| 1 | +#!/bin/bash |
| 2 | +# Script to verify Docker network configuration for electrs |
| 3 | + |
| 4 | +echo "=== DOCKER NETWORK DIAGNOSTIC ===" |
| 5 | +echo "" |
| 6 | + |
| 7 | +# Check if electrs network exists |
| 8 | +echo "1. Checking electrs-network..." |
| 9 | +docker network inspect electrs-network > /dev/null 2>&1 |
| 10 | +if [ $? -eq 0 ]; then |
| 11 | + echo " ✓ electrs-network exists" |
| 12 | + |
| 13 | + # Get gateway IP |
| 14 | + GATEWAY_IP=$(docker network inspect electrs-network | grep -i gateway | head -1 | awk '{print $2}' | tr -d '",') |
| 15 | + echo " Gateway IP: $GATEWAY_IP" |
| 16 | + |
| 17 | + # Check what's configured in docker-compose.yml |
| 18 | + CONFIGURED_IP=$(grep "daemon-rpc-addr" docker-compose.yml | grep -oP '\d+\.\d+\.\d+\.\d+' | head -1) |
| 19 | + echo " Configured IP in docker-compose.yml: $CONFIGURED_IP" |
| 20 | + |
| 21 | + if [ "$GATEWAY_IP" != "$CONFIGURED_IP" ]; then |
| 22 | + echo " ⚠ WARNING: Gateway IP mismatch!" |
| 23 | + echo " The configured IP ($CONFIGURED_IP) doesn't match the actual gateway ($GATEWAY_IP)" |
| 24 | + echo " This will cause connection failures!" |
| 25 | + echo "" |
| 26 | + echo " Fix: Update docker-compose.yml:" |
| 27 | + echo " Change: --daemon-rpc-addr=$CONFIGURED_IP:8332" |
| 28 | + echo " To: --daemon-rpc-addr=$GATEWAY_IP:8332" |
| 29 | + else |
| 30 | + echo " ✓ Gateway IP matches configuration" |
| 31 | + fi |
| 32 | +else |
| 33 | + echo " ✗ electrs-network does not exist" |
| 34 | + echo " Run: docker-compose up -d (this will create the network)" |
| 35 | +fi |
| 36 | + |
| 37 | +echo "" |
| 38 | +echo "2. Testing bitcoind connection from host..." |
| 39 | +BITCOIND_RESPONSE=$(curl -s --user bitcoinrpc:cab44cb7d0ee18fe1c556ae50bae373c8ea81212179c09cfbdee9425dfcbd516 --data-binary '{"jsonrpc":"1.0","id":"test","method":"getblockchaininfo","params":[]}' -H 'content-type: text/plain;' --max-time 5 http://localhost:8332/ 2>&1) |
| 40 | +if echo "$BITCOIND_RESPONSE" | grep -q "result"; then |
| 41 | + echo " ✓ Bitcoind RPC is accessible from host" |
| 42 | +else |
| 43 | + echo " ✗ Bitcoind RPC is NOT accessible from host" |
| 44 | + echo " Response: $BITCOIND_RESPONSE" |
| 45 | +fi |
| 46 | + |
| 47 | +echo "" |
| 48 | +echo "3. Testing bitcoind connection from Docker network..." |
| 49 | +if [ ! -z "$GATEWAY_IP" ]; then |
| 50 | + DOCKER_TEST=$(docker run --rm --network electrs-network curlimages/curl:latest curl -s --max-time 5 --user bitcoinrpc:cab44cb7d0ee18fe1c556ae50bae373c8ea81212179c09cfbdee9425dfcbd516 --data-binary '{"jsonrpc":"1.0","id":"test","method":"getblockchaininfo","params":[]}' -H 'content-type: text/plain;' http://$GATEWAY_IP:8332/ 2>&1) |
| 51 | + if echo "$DOCKER_TEST" | grep -q "result"; then |
| 52 | + echo " ✓ Bitcoind RPC is accessible from Docker network at $GATEWAY_IP:8332" |
| 53 | + else |
| 54 | + echo " ✗ Bitcoind RPC is NOT accessible from Docker network at $GATEWAY_IP:8332" |
| 55 | + echo " This is the problem! Check bitcoind firewall/rpcallowip settings" |
| 56 | + fi |
| 57 | +fi |
| 58 | + |
| 59 | +echo "" |
| 60 | +echo "4. Checking electrs container network..." |
| 61 | +ELECTRS_IP=$(docker inspect electrs --format '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' 2>/dev/null) |
| 62 | +if [ ! -z "$ELECTRS_IP" ]; then |
| 63 | + echo " Electrs container IP: $ELECTRS_IP" |
| 64 | + echo " ✓ Electrs container is running" |
| 65 | +else |
| 66 | + echo " ✗ Electrs container is not running" |
| 67 | +fi |
| 68 | + |
| 69 | +echo "" |
| 70 | +echo "5. Checking for connection issues..." |
| 71 | +CONNECTION_COUNT=$(ss -tnp | grep :8332 | grep ESTAB | wc -l) |
| 72 | +FIN_WAIT=$(ss -tnp | grep :8332 | grep FIN-WAIT | wc -l) |
| 73 | +echo " Established connections to bitcoind: $CONNECTION_COUNT" |
| 74 | +echo " Connections in FIN-WAIT state: $FIN_WAIT" |
| 75 | +if [ "$FIN_WAIT" -gt 10 ]; then |
| 76 | + echo " ⚠ WARNING: Many connections in FIN-WAIT state - connection cleanup issues" |
| 77 | +fi |
| 78 | + |
| 79 | +echo "" |
| 80 | +echo "=== SUMMARY ===" |
| 81 | +if [ "$GATEWAY_IP" != "$CONFIGURED_IP" ] && [ ! -z "$GATEWAY_IP" ] && [ ! -z "$CONFIGURED_IP" ]; then |
| 82 | + echo "⚠ ACTION REQUIRED: Update docker-compose.yml with correct gateway IP: $GATEWAY_IP" |
| 83 | + echo "" |
| 84 | + echo "Run this command to fix:" |
| 85 | + echo "sed -i 's|--daemon-rpc-addr=$CONFIGURED_IP:8332|--daemon-rpc-addr=$GATEWAY_IP:8332|g' docker-compose.yml" |
| 86 | +else |
| 87 | + echo "✓ Network configuration looks correct" |
| 88 | +fi |
| 89 | + |
0 commit comments