fix(health): verify-lxc-configs-on-hosts optional --vmid filter

Add usage/help and limit checks to specific VMIDs when iterating hosts.

Made-with: Cursor
This commit is contained in:
defiQUG
2026-04-12 06:44:13 -07:00
parent 282256a387
commit f06e084e2f

View File

@@ -1,8 +1,10 @@
#!/usr/bin/env bash
# Verify every RPC (and optionally other) VM has an LXC config file on its Proxmox host.
# Verify every RPC VM has an LXC config file on its Proxmox host.
# SSHs to each host and checks pct config <vmid> for expected VMIDs on that host.
# Run from project root.
# Usage: ./scripts/health/verify-lxc-configs-on-hosts.sh
# Usage:
# ./scripts/health/verify-lxc-configs-on-hosts.sh
# ./scripts/health/verify-lxc-configs-on-hosts.sh --vmid 2301
set -euo pipefail
@@ -26,6 +28,45 @@ RED='\033[0;31m'
GREEN='\033[0;32m'
CYAN='\033[0;36m'
NC='\033[0m'
TARGET_VMIDS=()
usage() {
cat <<'EOF'
Usage: ./scripts/health/verify-lxc-configs-on-hosts.sh [--vmid <N>]
Options:
--vmid <N> Limit to one VMID; repeatable
EOF
}
while [[ $# -gt 0 ]]; do
case "$1" in
--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 -e "${CYAN}=== Verify LXC config files on Proxmox hosts ===${NC}"
echo ""
@@ -34,6 +75,7 @@ ok=0
fail=0
for entry in "${RPC_NODES[@]}"; do
IFS=: read -r vmid host <<< "$entry"
selected_vmid "$vmid" || continue
ssh_target="${PROXMOX_SSH_USER}@${host}"
out=$(ssh $SSH_OPTS "$ssh_target" "pct config $vmid 2>&1" || true)
if echo "$out" | grep -q "Configuration file.*does not exist\|No such file"; then