68 lines
2.7 KiB
Bash
68 lines
2.7 KiB
Bash
|
|
#!/usr/bin/env bash
|
||
|
|
# Restart Blockscout on VMID 5000 to resume indexing and reduce indexer lag.
|
||
|
|
# Run from project root. Requires SSH to r630-02 (192.168.11.12) or run on Proxmox host.
|
||
|
|
# Usage: bash scripts/fix-explorer-indexer-lag.sh
|
||
|
|
|
||
|
|
set -euo pipefail
|
||
|
|
|
||
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||
|
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
||
|
|
source "${PROJECT_ROOT}/config/ip-addresses.conf" 2>/dev/null || true
|
||
|
|
|
||
|
|
VMID=5000
|
||
|
|
PROXMOX_R630_02="${PROXMOX_HOST_R630_02:-192.168.11.12}"
|
||
|
|
IP_BLOCKSCOUT="${IP_BLOCKSCOUT:-192.168.11.140}"
|
||
|
|
|
||
|
|
run_in_5000() {
|
||
|
|
if command -v pct &>/dev/null; then
|
||
|
|
pct exec $VMID -- bash -c "$1"
|
||
|
|
else
|
||
|
|
ssh -o ConnectTimeout=10 -o StrictHostKeyChecking=no root@"${PROXMOX_R630_02}" "pct exec $VMID -- bash -c '$1'"
|
||
|
|
fi
|
||
|
|
}
|
||
|
|
|
||
|
|
echo "=== Fix Explorer Indexer Lag (restart Blockscout) ==="
|
||
|
|
echo "VMID: $VMID, host: ${PROXMOX_R630_02}"
|
||
|
|
echo ""
|
||
|
|
|
||
|
|
# 1. Restart Blockscout (systemctl or docker-compose)
|
||
|
|
echo "[1] Restarting Blockscout..."
|
||
|
|
if run_in_5000 "systemctl restart blockscout 2>/dev/null || true"; then
|
||
|
|
echo " systemctl restart blockscout sent"
|
||
|
|
else
|
||
|
|
echo " systemctl not available or failed, trying docker-compose..."
|
||
|
|
fi
|
||
|
|
|
||
|
|
# If systemctl exists but service uses docker-compose, restart docker stack
|
||
|
|
if run_in_5000 "cd /opt/blockscout 2>/dev/null && (docker-compose restart blockscout 2>/dev/null || docker compose restart blockscout 2>/dev/null)" 2>/dev/null; then
|
||
|
|
echo " docker-compose restart blockscout sent"
|
||
|
|
fi
|
||
|
|
|
||
|
|
echo "[2] Waiting 15s for indexer to resume..."
|
||
|
|
sleep 15
|
||
|
|
|
||
|
|
# 3. Quick lag check
|
||
|
|
echo "[3] Checking lag (RPC vs Blockscout)..."
|
||
|
|
RPC_BLOCK=$(curl -sf --max-time 10 -X POST -H "Content-Type: application/json" \
|
||
|
|
-d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' \
|
||
|
|
"http://${RPC_2201:-192.168.11.221}:8545" 2>/dev/null | sed -n 's/.*"result":"\(0x[0-9a-fA-F]*\)".*/\1/p')
|
||
|
|
EXPLORER_BLOCK=$(curl -sf --max-time 10 "http://${IP_BLOCKSCOUT}:4000/api/v2/stats" 2>/dev/null | sed -n 's/.*"total_blocks"\s*:\s*"\([0-9]*\)".*/\1/p')
|
||
|
|
[ -z "$EXPLORER_BLOCK" ] && EXPLORER_BLOCK=$(curl -sf --max-time 10 "http://${IP_BLOCKSCOUT}:4000/api/v2/stats" 2>/dev/null | sed -n 's/.*"total_blocks"\s*:\s*\([0-9]*\).*/\1/p')
|
||
|
|
|
||
|
|
if [ -n "$RPC_BLOCK" ] && [ -n "$EXPLORER_BLOCK" ]; then
|
||
|
|
RPC_DEC=$((RPC_BLOCK))
|
||
|
|
LAG=$((RPC_DEC - EXPLORER_BLOCK))
|
||
|
|
echo " RPC block: $RPC_DEC, Explorer block: $EXPLORER_BLOCK, lag: $LAG"
|
||
|
|
if [ "$LAG" -le 500 ] 2>/dev/null; then
|
||
|
|
echo " OK (lag <= 500)"
|
||
|
|
else
|
||
|
|
echo " Lag still > 500; indexer may need more time to catch up. Re-run daily check in a few minutes."
|
||
|
|
fi
|
||
|
|
else
|
||
|
|
echo " Could not read blocks (RPC or Blockscout unreachable from this host)"
|
||
|
|
fi
|
||
|
|
|
||
|
|
echo ""
|
||
|
|
echo "=== Done ==="
|
||
|
|
echo "Re-run daily check: bash scripts/maintenance/daily-weekly-checks.sh daily"
|