Files
proxmox/scripts/maintenance/fix-core-rpc-2101.sh
defiQUG dbd517b279 Sync workspace: config, docs, scripts, CI, operator rules, and submodule pointers.
- Update dbis_core, cross-chain-pmm-lps, explorer-monorepo, metamask-integration, pr-workspace/chains
- Omit embedded publish git dirs and empty placeholders from index

Made-with: Cursor
2026-04-12 06:12:20 -07:00

118 lines
4.6 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/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] [--apply] [--restart-only]
# --dry-run Print actions only; do not run.
# --apply Perform mutations (required when PROXMOX_SAFE_DEFAULTS=1 is set).
# --restart-only Skip pct start; only restart Besu service inside CT.
# Env: PROXMOX_SAFE_DEFAULTS=1 — default to dry-run unless --apply or PROXMOX_OPS_APPLY=1.
# PROXMOX_OPS_ALLOWED_VMIDS — optional allowlist (e.g. only 2101 for this script).
# 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)"
# shellcheck source=../lib/proxmox-production-guard.sh
source "${PROJECT_ROOT}/scripts/lib/proxmox-production-guard.sh"
[[ -f "${PROJECT_ROOT}/scripts/lib/load-project-env.sh" ]] && source "${PROJECT_ROOT}/scripts/lib/load-project-env.sh" 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
APPLY=false
EXPLICIT_DRY=false
RESTART_ONLY=false
for a in "$@"; do
case "$a" in
--dry-run) DRY_RUN=true; EXPLICIT_DRY=true ;;
--apply) APPLY=true; DRY_RUN=false ;;
--restart-only) RESTART_ONLY=true ;;
esac
done
# PROXMOX_OPS_APPLY=1 acts like --apply unless operator explicitly passed --dry-run
if [[ "$EXPLICIT_DRY" != true ]] && pguard_mutations_allowed; then
APPLY=true
DRY_RUN=false
fi
if [[ "$EXPLICIT_DRY" != true ]] && pguard_safe_defaults_enabled && [[ "$APPLY" != true ]]; then
DRY_RUN=true
fi
if ! pguard_vmid_allowed "$VMID"; then
exit 2
fi
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 3090s)..."
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 3060s 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 ""