Some checks failed
Deploy to Phoenix / deploy (push) Has been cancelled
Co-authored-by: Cursor <cursoragent@cursor.com>
94 lines
3.7 KiB
Bash
Executable File
94 lines
3.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
||
# Fix Core Besu RPC on VMID 2101 (Chain 138 admin/deploy — RPC_URL_138).
|
||
# Starts container if stopped, starts/restarts Besu service, verifies RPC.
|
||
#
|
||
# Usage: ./scripts/maintenance/fix-core-rpc-2101.sh [--dry-run] [--restart-only]
|
||
# --dry-run Print actions only; do not run.
|
||
# --restart-only Skip pct start; only restart Besu service inside CT.
|
||
# Requires: SSH to r630-01 (key-based). Run from LAN or VPN.
|
||
#
|
||
# See: docs/00-meta/502_DEEP_DIVE_ROOT_CAUSES_AND_FIXES.md (rpc-http-prv)
|
||
# docs/04-configuration/RPC_ENDPOINTS_MASTER.md (2101 = Core RPC)
|
||
|
||
set -euo pipefail
|
||
|
||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
||
[[ -f "${PROJECT_ROOT}/config/ip-addresses.conf" ]] && source "${PROJECT_ROOT}/config/ip-addresses.conf" 2>/dev/null || true
|
||
|
||
VMID=2101
|
||
HOST="${PROXMOX_HOST_R630_01:-${PROXMOX_R630_01:-192.168.11.11}}"
|
||
RPC_IP="${RPC_CORE_1:-192.168.11.211}"
|
||
RPC_PORT=8545
|
||
|
||
DRY_RUN=false
|
||
RESTART_ONLY=false
|
||
for a in "$@"; do [[ "$a" == "--dry-run" ]] && DRY_RUN=true; [[ "$a" == "--restart-only" ]] && RESTART_ONLY=true; done
|
||
|
||
log_info() { echo -e "\033[0;34m[INFO]\033[0m $1"; }
|
||
log_ok() { echo -e "\033[0;32m[✓]\033[0m $1"; }
|
||
log_warn() { echo -e "\033[0;33m[⚠]\033[0m $1"; }
|
||
log_err() { echo -e "\033[0;31m[✗]\033[0m $1"; }
|
||
|
||
run_ssh() { ssh -o ConnectTimeout=10 -o StrictHostKeyChecking=no root@"$HOST" "$@"; }
|
||
|
||
echo ""
|
||
echo "=== Fix Core Besu RPC (VMID $VMID @ $HOST) ==="
|
||
echo " RPC: http://${RPC_IP}:${RPC_PORT} dry-run=$DRY_RUN restart-only=$RESTART_ONLY"
|
||
echo ""
|
||
|
||
# 1. SSH check
|
||
if ! run_ssh "echo OK" &>/dev/null; then
|
||
log_err "Cannot SSH to $HOST. Run from LAN with key-based auth."
|
||
exit 1
|
||
fi
|
||
|
||
# 2. Container status
|
||
status=$(run_ssh "pct status $VMID 2>/dev/null | awk '{print \$2}'" 2>/dev/null || echo "missing")
|
||
if [[ "$status" != "running" ]]; then
|
||
if $RESTART_ONLY; then
|
||
log_err "Container $VMID is not running (status: ${status:-missing}). Omit --restart-only to start container first."
|
||
exit 1
|
||
fi
|
||
if $DRY_RUN; then
|
||
log_info "Would run: pct start $VMID (current: $status)"
|
||
else
|
||
log_info "Starting container $VMID..."
|
||
run_ssh "pct start $VMID" && log_ok "Container started" || { log_err "pct start failed"; exit 1; }
|
||
log_info "Waiting 15s for CT to boot..."
|
||
sleep 15
|
||
fi
|
||
else
|
||
log_ok "Container $VMID is running"
|
||
fi
|
||
|
||
if $DRY_RUN; then
|
||
log_info "Would: start/restart Besu service in $VMID, then verify eth_chainId at http://${RPC_IP}:${RPC_PORT}"
|
||
echo ""
|
||
exit 0
|
||
fi
|
||
|
||
# 3. Start or restart Besu (try besu-rpc then besu)
|
||
svc=$(run_ssh "pct exec $VMID -- bash -c 'systemctl list-units --type=service --no-legend 2>/dev/null | grep -iE \"besu-rpc|besu\\.service\" | head -1 | awk \"{print \\\$1}\"'" 2>/dev/null || echo "")
|
||
if [[ -z "$svc" ]]; then
|
||
run_ssh "pct exec $VMID -- systemctl start besu 2>/dev/null" && log_ok "Started besu" || true
|
||
else
|
||
run_ssh "pct exec $VMID -- systemctl restart $svc" && log_ok "Restarted $svc" || run_ssh "pct exec $VMID -- systemctl start besu" && log_ok "Started besu"
|
||
fi
|
||
|
||
log_info "Waiting 60s for Besu to bind (RPC may take 30–90s)..."
|
||
sleep 60
|
||
|
||
# 4. Verify RPC
|
||
resp=$(run_ssh "curl -s -X POST -H 'Content-Type: application/json' -d '{\"jsonrpc\":\"2.0\",\"method\":\"eth_chainId\",\"params\":[],\"id\":1}' --connect-timeout 5 http://${RPC_IP}:${RPC_PORT}/ 2>/dev/null" || true)
|
||
if echo "$resp" | grep -q '"result"'; then
|
||
chain_hex=$(echo "$resp" | sed -n 's/.*"result":"\(0x[0-9a-fA-F]*\)".*/\1/p')
|
||
log_ok "RPC responding: eth_chainId = $chain_hex (Chain 138 = 0x8a)"
|
||
else
|
||
log_warn "RPC not yet responding. Wait 30–60s and re-run or check: pct exec $VMID -- systemctl status besu-rpc; pct exec $VMID -- ss -tlnp | grep 8545"
|
||
fi
|
||
|
||
echo ""
|
||
log_ok "Done. Set RPC_URL_138=http://${RPC_IP}:${RPC_PORT} for deploy/scripts."
|
||
echo ""
|