Created
May 18, 2026 18:05
-
-
Save aerodomigue/e56b0937004e6e203ab39995cc550b96 to your computer and use it in GitHub Desktop.
Gracefully shutdown an entire Proxmox VE cluster. Stops HA services (pve-ha-lrm, pve-ha-crm) on all nodes first, then shuts down remote nodes before the local node. Supports --dry-run. Requires SSH key exchange between nodes (default in Proxmox clusters) and node hostnames resolvable via /etc/hosts or DNS.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # cluster-shutdown-all - Éteint proprement tout le cluster Proxmox | |
| # Stoppe le HA sur tous les nœuds puis les éteint un par un | |
| # Requiert les clés SSH root échangées entre nœuds (par défaut dans un cluster Proxmox) | |
| # Usage: cluster-shutdown-all [--dry-run] | |
| set -e | |
| DRY_RUN=false | |
| [ "$1" = "--dry-run" ] && DRY_RUN=true | |
| LOCAL=$(hostname) | |
| NODES=$(ls -1 /etc/pve/nodes/) | |
| # Vérifier que le nœud local est bien dans la liste | |
| if ! echo "$NODES" | grep -q "^${LOCAL}$"; then | |
| echo "ERROR: Local node $LOCAL not found in cluster nodes" | |
| exit 1 | |
| fi | |
| echo "=== cluster-shutdown-all ===" | |
| echo "Local node: $LOCAL" | |
| echo "Detected nodes:" | |
| for node in $NODES; do | |
| if [ "$node" = "$LOCAL" ]; then | |
| echo " - $node (local)" | |
| else | |
| echo " - $node (remote)" | |
| fi | |
| done | |
| if $DRY_RUN; then | |
| for node in $NODES; do | |
| if [ "$node" != "$LOCAL" ]; then | |
| echo "[DRY-RUN] Would stop pve-ha-lrm pve-ha-crm on $node via SSH" | |
| fi | |
| done | |
| echo "[DRY-RUN] Would stop pve-ha-lrm pve-ha-crm on $LOCAL" | |
| for node in $NODES; do | |
| if [ "$node" != "$LOCAL" ]; then | |
| echo "[DRY-RUN] Would shutdown $node via SSH" | |
| fi | |
| done | |
| echo "[DRY-RUN] Would shutdown $LOCAL (last)" | |
| echo "=== Dry run complete, no action taken ===" | |
| exit 0 | |
| fi | |
| # Confirmation | |
| echo "" | |
| read -p "Are you sure you want to shutdown the entire cluster? (yes/no): " CONFIRM | |
| if [ "$CONFIRM" != "yes" ]; then | |
| echo "Aborted." | |
| exit 0 | |
| fi | |
| # Stopper le HA sur les nœuds distants | |
| for node in $NODES; do | |
| if [ "$node" != "$LOCAL" ]; then | |
| echo "Stopping HA on $node..." | |
| ssh "$node" "systemctl stop pve-ha-lrm pve-ha-crm" & | |
| fi | |
| done | |
| echo "Stopping HA locally..." | |
| systemctl stop pve-ha-lrm pve-ha-crm | |
| # Attendre que les stops SSH finissent | |
| wait | |
| # Éteindre les nœuds distants | |
| for node in $NODES; do | |
| if [ "$node" != "$LOCAL" ]; then | |
| echo "Shutting down $node..." | |
| ssh "$node" "/sbin/shutdown -h now" & | |
| fi | |
| done | |
| # Attendre que les commandes SSH soient envoyées | |
| sleep 2 | |
| # Éteindre le nœud local en dernier | |
| echo "Shutting down $LOCAL..." | |
| /sbin/shutdown -h now |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment