Files
proxmox/scripts/besu/fix-all-besu-nodes.sh
defiQUG 282256a387 fix(scripts): Besu fleet ops use load-project-env and scoped VMIDs
Prefer load-project-env over raw ip-addresses.conf; add --vmid/--apply patterns
and safer dry-run defaults across fix-all-besu, static-nodes reload, node-list
deploy, max-peers rollout, rolling upgrade, and permissions verification.

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

137 lines
4.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# Fix selected Besu nodes: deploy canonical node lists, normalize config (TOML permissions path,
# remove tx-pool-min-score, ensure genesis), then restart Besu.
# Run from project root.
# Usage:
# bash scripts/besu/fix-all-besu-nodes.sh
# bash scripts/besu/fix-all-besu-nodes.sh --vmid 2301 --no-restart
# bash scripts/besu/fix-all-besu-nodes.sh --apply --vmid 2301
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
cd "$PROJECT_ROOT"
source "${PROJECT_ROOT}/scripts/lib/load-project-env.sh"
DRY_RUN=true
NO_RESTART=false
TARGET_VMIDS=()
BESU_VMIDS=(1000 1001 1002 1003 1004 1500 1501 1502 1503 1504 1505 1506 1507 1508 2101 2102 2201 2301 2303 2304 2305 2306 2307 2308 2400 2401 2402 2403)
STATIC="${PROJECT_ROOT}/config/besu-node-lists/static-nodes.json"
PERMS="${PROJECT_ROOT}/config/besu-node-lists/permissions-nodes.toml"
SSH_OPTS="-o ConnectTimeout=8 -o StrictHostKeyChecking=accept-new"
usage() {
cat <<'EOF'
Usage: bash scripts/besu/fix-all-besu-nodes.sh [--apply] [--dry-run] [--no-restart] [--vmid <N>]
Options:
--dry-run Print intended actions only (default)
--apply Perform fixes on selected nodes
--no-restart Skip restart step
--vmid <N> Limit to one VMID; repeatable
EOF
}
while [[ $# -gt 0 ]]; do
case "$1" in
--dry-run)
DRY_RUN=true
shift
;;
--apply)
DRY_RUN=false
shift
;;
--no-restart)
NO_RESTART=true
shift
;;
--vmid)
[[ $# -ge 2 ]] || { usage >&2; exit 2; }
TARGET_VMIDS+=("$2")
shift 2
;;
-h|--help)
usage
exit 0
;;
*)
echo "Unknown argument: $1" >&2
usage >&2
exit 2
;;
esac
done
selected_vmid() {
local vmid="$1"
[[ ${#TARGET_VMIDS[@]} -eq 0 ]] && return 0
local wanted
for wanted in "${TARGET_VMIDS[@]}"; do
[[ "$vmid" == "$wanted" ]] && return 0
done
return 1
}
if [[ ! -f "$STATIC" ]] || [[ ! -f "$PERMS" ]]; then
echo "ERROR: Missing $STATIC or $PERMS" >&2
exit 1
fi
echo "=== Fix selected Besu nodes ==="
echo " 1. Deploy node lists to all nodes"
echo " 2. Fix config on each node (permissions TOML path, remove tx-pool-min-score, genesis)"
echo " 3. Restart Besu on selected nodes"
if $DRY_RUN; then echo " [DRY-RUN]"; fi
if $NO_RESTART; then echo " [NO-RESTART]"; fi
echo ""
# Step 1: Deploy node lists
echo "--- Step 1: Deploy static-nodes.json and permissions-nodes.toml ---"
if ! $DRY_RUN; then
deploy_args=(--apply)
for vmid in "${TARGET_VMIDS[@]}"; do
deploy_args+=(--vmid "$vmid")
done
bash "${PROJECT_ROOT}/scripts/deploy-besu-node-lists-to-all.sh" "${deploy_args[@]}" 2>/dev/null || true
fi
echo ""
# Step 2: Fix config on each running node (permissions path, remove tx-pool-min-score, genesis)
echo "--- Step 2: Fix config on each node ---"
for vmid in "${BESU_VMIDS[@]}"; do
selected_vmid "$vmid" || continue
host="$(get_host_for_vmid "$vmid")"
[[ -z "$host" ]] && continue
running=$(ssh $SSH_OPTS "root@$host" "pct status $vmid 2>/dev/null | awk '{print \$2}'" 2>/dev/null || echo "")
if [[ "$running" != "running" ]]; then
echo " VMID $vmid: skip (not running)"
continue
fi
if $DRY_RUN; then
echo " VMID $vmid: [dry-run] would fix config"
continue
fi
ssh $SSH_OPTS "root@$host" "pct exec $vmid -- bash -c 'for f in /etc/besu/*.toml /config/*.toml; do [ -f \"\$f\" ] || continue; sed -i \"s|permissions-nodes-config-file=.*|permissions-nodes-config-file=\\\"/etc/besu/permissions-nodes.toml\\\"|\" \"\$f\"; sed -i \"/^tx-pool-min-score=/d\" \"\$f\"; sed -i \"s|static-nodes-file=.*|static-nodes-file=\\\"/etc/besu/static-nodes.json\\\"|\" \"\$f\"; done; [ -f /etc/besu/genesis.json ] && [ ! -f /genesis/genesis.json ] && cp /etc/besu/genesis.json /genesis/genesis.json 2>/dev/null; true'" 2>/dev/null && echo " VMID $vmid: config fixed" || echo " VMID $vmid: config fix skipped/failed"
done
echo ""
# Step 3: Restart Besu
if $NO_RESTART; then
echo "--- Step 3: skipped (--no-restart) ---"
echo "Run: bash scripts/besu/restart-besu-reload-node-lists.sh --apply [--vmid <N>]"
exit 0
fi
echo "--- Step 3: Restart Besu on selected nodes ---"
if ! $DRY_RUN; then
restart_args=(--apply)
for vmid in "${TARGET_VMIDS[@]}"; do
restart_args+=(--vmid "$vmid")
done
bash "${PROJECT_ROOT}/scripts/besu/restart-besu-reload-node-lists.sh" "${restart_args[@]}" 2>/dev/null || true
fi
echo ""
echo "Done."