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
This commit is contained in:
@@ -1,42 +1,89 @@
|
||||
#!/usr/bin/env bash
|
||||
# Fix all Besu nodes: deploy canonical node lists, normalize config (TOML permissions path,
|
||||
# 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 [--dry-run] [--no-restart]
|
||||
# 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}/config/ip-addresses.conf" 2>/dev/null || true
|
||||
source "${PROJECT_ROOT}/scripts/lib/load-project-env.sh"
|
||||
|
||||
DRY_RUN=false
|
||||
DRY_RUN=true
|
||||
NO_RESTART=false
|
||||
for arg in "${@:-}"; do
|
||||
[[ "$arg" == "--dry-run" ]] && DRY_RUN=true
|
||||
[[ "$arg" == "--no-restart" ]] && NO_RESTART=true
|
||||
done
|
||||
|
||||
# Same host/VMID as deploy-besu-node-lists-to-all.sh
|
||||
declare -A HOST_BY_VMID
|
||||
for v in 1000 1001 1002 1500 1501 1502 2101 2500 2501 2502 2503 2504 2505; do HOST_BY_VMID[$v]="${PROXMOX_R630_01:-${PROXMOX_HOST_R630_01:-192.168.11.11}}"; done
|
||||
for v in 2201 2303 2305 2306 2307 2308 2401; do HOST_BY_VMID[$v]="${PROXMOX_R630_02:-${PROXMOX_HOST_R630_02:-192.168.11.12}}"; done
|
||||
for v in 1003 1004 1503 1504 1505 1506 1507 1508 2102 2301 2304 2400 2402 2403; do HOST_BY_VMID[$v]="${PROXMOX_R630_03:-${PROXMOX_HOST_R630_03:-192.168.11.13}}"; done
|
||||
|
||||
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 2500 2501 2502 2503 2504 2505)
|
||||
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 all Besu nodes ==="
|
||||
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 all nodes"
|
||||
echo " 3. Restart Besu on selected nodes"
|
||||
if $DRY_RUN; then echo " [DRY-RUN]"; fi
|
||||
if $NO_RESTART; then echo " [NO-RESTART]"; fi
|
||||
echo ""
|
||||
@@ -44,14 +91,19 @@ echo ""
|
||||
# Step 1: Deploy node lists
|
||||
echo "--- Step 1: Deploy static-nodes.json and permissions-nodes.toml ---"
|
||||
if ! $DRY_RUN; then
|
||||
bash "${PROJECT_ROOT}/scripts/deploy-besu-node-lists-to-all.sh" 2>/dev/null || true
|
||||
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
|
||||
host="${HOST_BY_VMID[$vmid]:-}"
|
||||
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
|
||||
@@ -69,12 +121,16 @@ 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"
|
||||
echo "Run: bash scripts/besu/restart-besu-reload-node-lists.sh --apply [--vmid <N>]"
|
||||
exit 0
|
||||
fi
|
||||
echo "--- Step 3: Restart Besu on all nodes ---"
|
||||
echo "--- Step 3: Restart Besu on selected nodes ---"
|
||||
if ! $DRY_RUN; then
|
||||
bash "${PROJECT_ROOT}/scripts/besu/restart-besu-reload-node-lists.sh" 2>/dev/null || true
|
||||
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."
|
||||
|
||||
@@ -1,30 +1,75 @@
|
||||
#!/usr/bin/env bash
|
||||
# Restart Besu on all nodes that receive the node-list deploy so they reload
|
||||
# Restart Besu on selected nodes that receive the node-list deploy so they reload
|
||||
# /etc/besu/static-nodes.json and /etc/besu/permissions-nodes.toml.
|
||||
# Uses same host/VMID list as scripts/deploy-besu-node-lists-to-all.sh.
|
||||
# Uses the shared live VMID placement map.
|
||||
#
|
||||
# Usage: bash scripts/besu/restart-besu-reload-node-lists.sh [--dry-run]
|
||||
# Usage:
|
||||
# bash scripts/besu/restart-besu-reload-node-lists.sh
|
||||
# bash scripts/besu/restart-besu-reload-node-lists.sh --vmid 2301
|
||||
# bash scripts/besu/restart-besu-reload-node-lists.sh --apply --vmid 2301
|
||||
|
||||
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
|
||||
source "${PROJECT_ROOT}/scripts/lib/load-project-env.sh"
|
||||
|
||||
SSH_OPTS="-o ConnectTimeout=20 -o ServerAliveInterval=15 -o ServerAliveCountMax=3 -o StrictHostKeyChecking=accept-new"
|
||||
|
||||
DRY_RUN=false
|
||||
[[ "${1:-}" == "--dry-run" ]] && DRY_RUN=true
|
||||
DRY_RUN=true
|
||||
TARGET_VMIDS=()
|
||||
|
||||
# Same VMID -> host as deploy-besu-node-lists-to-all.sh
|
||||
declare -A HOST_BY_VMID
|
||||
for v in 1000 1001 1002 1500 1501 1502 2101 2103; do HOST_BY_VMID[$v]="${PROXMOX_R630_01:-${PROXMOX_HOST_R630_01:-192.168.11.11}}"; done
|
||||
for v in 2201 2303 2305 2306 2307 2308 2401; do HOST_BY_VMID[$v]="${PROXMOX_R630_02:-${PROXMOX_HOST_R630_02:-192.168.11.12}}"; done
|
||||
for v in 1003 1004 1503 1504 1505 1506 1507 1508 1509 1510 2102 2301 2304 2400 2402 2403; do HOST_BY_VMID[$v]="${PROXMOX_R630_03:-${PROXMOX_HOST_R630_03:-192.168.11.13}}"; done
|
||||
usage() {
|
||||
cat <<'EOF'
|
||||
Usage: bash scripts/besu/restart-besu-reload-node-lists.sh [--apply] [--dry-run] [--vmid <N>]
|
||||
|
||||
Options:
|
||||
--dry-run Print intended actions only (default)
|
||||
--apply Restart Besu on selected nodes
|
||||
--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
|
||||
;;
|
||||
--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
|
||||
|
||||
BESU_VMIDS=(1000 1001 1002 1003 1004 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 2101 2102 2103 2201 2301 2303 2304 2305 2306 2307 2308 2400 2401 2402 2403)
|
||||
|
||||
echo "Restarting Besu on all nodes (to reload static-nodes.json and permissions-nodes.toml)"
|
||||
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
|
||||
}
|
||||
|
||||
echo "Restarting Besu on selected nodes (to reload static-nodes.json and permissions-nodes.toml)"
|
||||
if $DRY_RUN; then echo " [dry-run]"; fi
|
||||
echo ""
|
||||
|
||||
@@ -32,7 +77,8 @@ ok=0
|
||||
skip=0
|
||||
fail=0
|
||||
for vmid in "${BESU_VMIDS[@]}"; do
|
||||
host="${HOST_BY_VMID[$vmid]:-}"
|
||||
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
|
||||
@@ -45,7 +91,7 @@ for vmid in "${BESU_VMIDS[@]}"; do
|
||||
((ok++)) || true
|
||||
continue
|
||||
fi
|
||||
# Detect Besu unit: besu-validator, besu-sentry, besu-rpc, or generic besu.service (1505-1508, 2500-2505)
|
||||
# Detect Besu unit: besu-validator, besu-sentry, besu-rpc, or generic besu.service.
|
||||
result=$(ssh $SSH_OPTS "root@$host" "timeout 180 pct exec $vmid -- bash -c 'svc=\$(systemctl list-units --type=service --no-legend 2>/dev/null | grep -iE \"besu-validator|besu-sentry|besu-rpc|besu\\.service\" | head -1 | awk \"{print \\\$1}\"); if [ -n \"\$svc\" ]; then systemctl restart \"\$svc\" && echo \"OK:\$svc\"; else echo \"NONE\"; fi'" 2>/dev/null || echo "FAIL")
|
||||
if [[ "$result" == OK:* ]]; then
|
||||
echo "VMID $vmid @ $host: restarted (${result#OK:})"
|
||||
|
||||
Reference in New Issue
Block a user