Some checks failed
Deploy to Phoenix / deploy (push) Has been cancelled
Co-authored-by: Cursor <cursoragent@cursor.com>
104 lines
6.4 KiB
Bash
Executable File
104 lines
6.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Fix VMID 2101 (rpc-http-prv) Besu crash: NoClassDefFoundError com.sun.jna.Native.
|
|
# Reinstalls Besu in the container (clean tarball) to get consistent JNA/libs, then restarts.
|
|
#
|
|
# Usage: ./scripts/maintenance/fix-rpc-2101-jna-reinstall.sh [--dry-run]
|
|
# Requires: SSH to r630-01. Run from project root (LAN).
|
|
# If the container has read-only root, the script checks /tmp and /opt writability and exits with
|
|
# instructions. Make the CT writable (Proxmox host: remount or CT config) then re-run. See 502_DEEP_DIVE §Read-only CT.
|
|
# See: docs/00-meta/502_DEEP_DIVE_ROOT_CAUSES_AND_FIXES.md
|
|
|
|
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:-192.168.11.11}"
|
|
RPC_IP="${RPC_CORE_1:-192.168.11.211}"
|
|
BESU_VERSION="${BESU_VERSION:-23.10.3}"
|
|
GENESIS_SRC="${PROJECT_ROOT}/smom-dbis-138-proxmox/config/genesis.json"
|
|
STATIC_SRC="${PROJECT_ROOT}/config/besu-node-lists/static-nodes.json"
|
|
PERMS_SRC="${PROJECT_ROOT}/config/besu-node-lists/permissions-nodes.toml"
|
|
SSH_OPTS="-o ConnectTimeout=15 -o StrictHostKeyChecking=accept-new"
|
|
|
|
DRY_RUN=false
|
|
[[ "${1:-}" == "--dry-run" ]] && DRY_RUN=true
|
|
|
|
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"; }
|
|
|
|
echo ""
|
|
echo "=== Fix 2101 Besu JNA (reinstall Besu in CT) ==="
|
|
echo " Host: $HOST VMID: $VMID BESU_VERSION: $BESU_VERSION dry-run: $DRY_RUN"
|
|
echo ""
|
|
|
|
if ! ssh $SSH_OPTS "root@$HOST" "echo OK" &>/dev/null; then
|
|
log_err "Cannot SSH to $HOST. Run from LAN."
|
|
exit 1
|
|
fi
|
|
|
|
status=$(ssh $SSH_OPTS "root@$HOST" "pct status $VMID 2>/dev/null | awk '{print \$2}'" 2>/dev/null || echo "")
|
|
if [[ "$status" != "running" ]]; then
|
|
log_err "Container $VMID is not running. Start it first: ssh root@$HOST pct start $VMID"
|
|
exit 1
|
|
fi
|
|
|
|
# Require writable /tmp and /opt in CT (install script and JNA need them)
|
|
if ! ssh $SSH_OPTS "root@$HOST" "pct exec $VMID -- bash -c 'touch /tmp/.w && rm -f /tmp/.w'" 2>/dev/null; then
|
|
log_err "Container $VMID /tmp is not writable. Make the CT writable (see docs/00-meta/502_DEEP_DIVE_ROOT_CAUSES_AND_FIXES.md §Read-only CT) then re-run."
|
|
exit 1
|
|
fi
|
|
if ! ssh $SSH_OPTS "root@$HOST" "pct exec $VMID -- bash -c 'touch /opt/.w 2>/dev/null && rm -f /opt/.w'" 2>/dev/null; then
|
|
log_warn "Container $VMID /opt may be read-only. Install will need /opt writable. If it fails, make CT writable and re-run."
|
|
fi
|
|
|
|
if $DRY_RUN; then
|
|
log_info "Would: stop besu-rpc, backup /opt/besu, run install-besu-in-ct-standalone.sh (NODE_TYPE=rpc), deploy genesis/node lists, start besu-rpc"
|
|
exit 0
|
|
fi
|
|
|
|
log_info "Stopping Besu in $VMID..."
|
|
ssh $SSH_OPTS "root@$HOST" "pct exec $VMID -- systemctl stop besu-rpc.service besu.service 2>/dev/null; true"
|
|
|
|
log_info "Backing up /opt/besu and reinstalling..."
|
|
ssh $SSH_OPTS "root@$HOST" "pct exec $VMID -- bash -c 'mv /opt/besu /opt/besu.bak.\$(date +%s) 2>/dev/null; true'"
|
|
|
|
# Push script to container /tmp (writable; avoid /root which may be read-only)
|
|
scp -q $SSH_OPTS "${PROJECT_ROOT}/scripts/install-besu-in-ct-standalone.sh" "root@${HOST}:/tmp/"
|
|
ssh $SSH_OPTS "root@$HOST" "pct push $VMID /tmp/install-besu-in-ct-standalone.sh /tmp/install-besu-in-ct-standalone.sh && pct exec $VMID -- env NODE_TYPE=rpc BESU_VERSION=$BESU_VERSION TMPDIR=/tmp bash /tmp/install-besu-in-ct-standalone.sh" || { log_err "Besu install failed"; exit 1; }
|
|
log_ok "Besu reinstalled"
|
|
|
|
# Ensure JNA can write native lib (Besu uses java.io.tmpdir; default /tmp may be ro in some CTs)
|
|
ssh $SSH_OPTS "root@$HOST" "pct exec $VMID -- bash -c 'mkdir -p /data/besu/tmp; chown besu:besu /data/besu/tmp; grep -q java.io.tmpdir /etc/systemd/system/besu-rpc.service || sed -i \"s|BESU_OPTS=-Xmx2g -Xms1g|BESU_OPTS=-Xmx2g -Xms1g -Djava.io.tmpdir=/data/besu/tmp|\" /etc/systemd/system/besu-rpc.service; systemctl daemon-reload'"
|
|
|
|
# Ensure config and data exist; deploy genesis and node lists if present in repo
|
|
if [[ -f "$GENESIS_SRC" ]] && [[ -f "$STATIC_SRC" ]] && [[ -f "$PERMS_SRC" ]]; then
|
|
log_info "Deploying genesis and node lists..."
|
|
scp -q $SSH_OPTS "$GENESIS_SRC" "$STATIC_SRC" "$PERMS_SRC" "root@${HOST}:/tmp/"
|
|
ssh $SSH_OPTS "root@$HOST" "pct push $VMID /tmp/genesis.json /etc/besu/genesis.json && pct push $VMID /tmp/static-nodes.json /etc/besu/static-nodes.json && pct push $VMID /tmp/permissions-nodes.toml /etc/besu/permissions-nodes.toml && pct exec $VMID -- chown -R besu:besu /etc/besu"
|
|
fi
|
|
|
|
# Ensure config-rpc.toml exists (standalone script expects it). If 2101 had a different name, copy first existing toml to config-rpc.toml
|
|
ssh $SSH_OPTS "root@$HOST" "pct exec $VMID -- bash -c 'if [ ! -f /etc/besu/config-rpc.toml ] && [ -f /etc/besu/config.toml ]; then cp /etc/besu/config.toml /etc/besu/config-rpc.toml; fi; if [ ! -f /etc/besu/config-rpc.toml ]; then echo \"data-path=/data/besu\" > /etc/besu/config-rpc.toml; echo \"genesis-file=/etc/besu/genesis.json\" >> /etc/besu/config-rpc.toml; echo \"network-id=138\" >> /etc/besu/config-rpc.toml; echo \"rpc-http-enabled=true\" >> /etc/besu/config-rpc.toml; echo \"rpc-http-host=0.0.0.0\" >> /etc/besu/config-rpc.toml; echo \"rpc-http-port=8545\" >> /etc/besu/config-rpc.toml; fi; chown besu:besu /etc/besu/config-rpc.toml 2>/dev/null; true'"
|
|
|
|
# VMID 2101 = Core RPC at 192.168.11.211; ensure p2p-host is correct (not .250 / RPC_ALLTRA_1)
|
|
ssh $SSH_OPTS "root@$HOST" "pct exec $VMID -- bash -c 'if grep -q \"^p2p-host=\" /etc/besu/config-rpc.toml; then sed -i \"s|^p2p-host=.*|p2p-host=\\\"'"$RPC_IP"'\\\"|\" /etc/besu/config-rpc.toml; else echo \"p2p-host=\\\"'"$RPC_IP"'\\\"\" >> /etc/besu/config-rpc.toml; fi'"
|
|
log_info "Set p2p-host=$RPC_IP in config-rpc.toml"
|
|
|
|
log_info "Starting besu-rpc..."
|
|
ssh $SSH_OPTS "root@$HOST" "pct exec $VMID -- systemctl daemon-reload && pct exec $VMID -- systemctl start besu-rpc.service"
|
|
log_ok "besu-rpc started. Waiting 45s for RPC to bind..."
|
|
sleep 45
|
|
|
|
resp=$(ssh $SSH_OPTS "root@$HOST" "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}:8545/ 2>/dev/null" || true)
|
|
if echo "$resp" | grep -q '"result"'; then
|
|
log_ok "RPC responding: $resp"
|
|
else
|
|
log_warn "RPC not yet responding. Check: pct exec $VMID -- journalctl -u besu-rpc -n 30"
|
|
fi
|
|
echo ""
|