Files
proxmox/scripts/besu/restart-besu-reload-node-lists.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

110 lines
3.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# 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 the shared live VMID placement map.
#
# 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}/scripts/lib/load-project-env.sh"
SSH_OPTS="-o ConnectTimeout=20 -o ServerAliveInterval=15 -o ServerAliveCountMax=3 -o StrictHostKeyChecking=accept-new"
DRY_RUN=true
TARGET_VMIDS=()
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)
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 ""
ok=0
skip=0
fail=0
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 @ $host: skip (not running)"
((skip++)) || true
continue
fi
if $DRY_RUN; then
echo "VMID $vmid @ $host: [dry-run] would restart Besu"
((ok++)) || true
continue
fi
# 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:})"
((ok++)) || true
elif [[ "$result" == "NONE" ]]; then
echo "VMID $vmid @ $host: no Besu service found"
((skip++)) || true
else
echo "VMID $vmid @ $host: failed ($result)"
((fail++)) || true
fi
done
echo ""
echo "Summary: restarted=$ok skipped=$skip failed=$fail"