Files
proxmox/scripts/besu/restart-besu-reload-node-lists.sh
defiQUG bea1903ac9
Some checks failed
Deploy to Phoenix / deploy (push) Has been cancelled
Sync all local changes: docs, config, scripts, submodule refs, verification evidence
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-21 15:46:06 -08:00

64 lines
2.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# Restart Besu on all 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.
#
# Usage: bash scripts/besu/restart-besu-reload-node-lists.sh [--dry-run]
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
DRY_RUN=false
[[ "${1:-}" == "--dry-run" ]] && DRY_RUN=true
# 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 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 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 2305 2306 2307 2308 2400 2402 2403; do HOST_BY_VMID[$v]="${PROXMOX_ML110:-${PROXMOX_HOST_ML110:-192.168.11.10}}"; 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)
SSH_OPTS="-o ConnectTimeout=8 -o StrictHostKeyChecking=accept-new"
echo "Restarting Besu on all 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
host="${HOST_BY_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 (1505-1508, 2500-2505)
result=$(ssh $SSH_OPTS "root@$host" "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"