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:
defiQUG
2026-04-12 06:44:12 -07:00
parent cc6821ebad
commit 282256a387
6 changed files with 368 additions and 89 deletions

View File

@@ -1,34 +1,80 @@
#!/usr/bin/env bash
# Set max-peers=40 in Besu config on all running Besu nodes (in-place sed).
# Set max-peers=40 in Besu config on selected running Besu nodes (in-place sed).
# Run after repo configs are updated; then restart Besu with restart-besu-reload-node-lists.sh.
# See: docs/08-monitoring/PEER_CONNECTIONS_PLAN.md
#
# Usage: ./scripts/maintenance/set-all-besu-max-peers-32.sh [--dry-run]
# Usage:
# ./scripts/maintenance/set-all-besu-max-peers-32.sh
# ./scripts/maintenance/set-all-besu-max-peers-32.sh --vmid 2301
# ./scripts/maintenance/set-all-besu-max-peers-32.sh --apply --vmid 2301
# Requires: SSH to Proxmox hosts (r630-01, r630-02, r630-03).
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
source "${PROJECT_ROOT}/scripts/lib/load-project-env.sh"
DRY_RUN=false
[[ "${1:-}" == "--dry-run" ]] && DRY_RUN=true
DRY_RUN=true
TARGET_VMIDS=()
TARGET_MAX_PEERS=40
declare -A HOST_BY_VMID
for v in 1000 1001 1002 1500 1501 1502 2101 2103 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 2103 2201 2301 2303 2304 2305 2306 2307 2308 2400 2401 2402 2403 2500 2501 2502 2503 2504 2505)
BESU_VMIDS=(1000 1001 1002 1003 1004 1500 1501 1502 1503 1504 1505 1506 1507 1508 2101 2102 2103 2201 2301 2303 2304 2305 2306 2307 2308 2400 2401 2402 2403)
SSH_OPTS="-o ConnectTimeout=8 -o StrictHostKeyChecking=accept-new"
usage() {
cat <<'EOF'
Usage: ./scripts/maintenance/set-all-besu-max-peers-32.sh [--apply] [--dry-run] [--vmid <N>]
Options:
--dry-run Print intended actions only (default)
--apply Update max-peers 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
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 "Set max-peers=${TARGET_MAX_PEERS} on all Besu nodes (dry-run=$DRY_RUN)"
echo ""
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
@@ -62,5 +108,5 @@ for vmid in "${BESU_VMIDS[@]}"; do
done
echo ""
echo "Done. Restart Besu on all nodes to apply: ./scripts/besu/restart-besu-reload-node-lists.sh"
echo "Done. Restart Besu on selected nodes to apply: ./scripts/besu/restart-besu-reload-node-lists.sh --apply [--vmid <N>]"
echo ""