-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcluster-killer.sh
109 lines (92 loc) · 3.28 KB
/
cluster-killer.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/bash
# Jan Gebser - Brainhub24.com
# Email: [email protected]
# About this Tool:
# - This is the secure decommissioning of a single Proxmox node from a cluster, including a configuration dump.
# PROXMOX Community
# Idea: I created this tiny tool based on the commands i found in the following thread.
# Topic: https://forum.proxmox.com/threads/remove-or-reset-cluster-configuration.114260/
# Function to log messages
log_message() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1"
}
# Function to check if running as root
check_root() {
if [ "$(id -u)" != "0" ]; then
echo "Error: This script must be run as root" >&2
exit 1
fi
}
# Function to check if this is a Proxmox system
check_proxmox() {
if [ ! -f "/usr/bin/pvesh" ]; then
echo "Error: This doesn't appear to be a Proxmox system" >&2
exit 1
fi
}
# Function to backup configuration
backup_config() {
local backup_dir="/root/cluster-backup-$(date '+%Y%m%d_%H%M%S')"
log_message "Creating backup at $backup_dir"
mkdir -p "$backup_dir"
if [ -d "/etc/corosync" ]; then
cp -r /etc/corosync/* "$backup_dir/" 2>/dev/null
fi
if [ -f "/etc/pve/corosync.conf" ]; then
cp /etc/pve/corosync.conf "$backup_dir/" 2>/dev/null
fi
}
# Main decommission function
decommission_node() {
log_message "Starting cluster decommission process"
# Stop cluster services
log_message "Stopping cluster services"
systemctl stop pve-cluster corosync
# Run pmxcfs in local mode
log_message "Starting pmxcfs in local mode"
pmxcfs -l &
sleep 2
# Remove cluster configuration
log_message "Removing cluster configuration files"
rm -f /etc/corosync/* 2>/dev/null
rm -f /etc/pve/corosync.conf 2>/dev/null
# Kill pmxcfs
log_message "Terminating pmxcfs process"
killall pmxcfs 2>/dev/null
# Restart cluster service
log_message "Restarting PVE cluster service"
systemctl start pve-cluster
# Verify cluster service is running
if systemctl is-active --quiet pve-cluster; then
log_message "PVE cluster service successfully restarted"
else
log_message "Warning: PVE cluster service failed to restart"
return 1
fi
}
# Main execution
main() {
check_root
check_proxmox
echo "WARNING: This script will remove this node from its cluster configuration."
echo "Make sure all VMs and resources are properly migrated before proceeding."
echo "A backup of the current configuration will be created."
read -p "Do you want to continue? (y/N): " confirm
if [[ ! $confirm =~ ^[Yy]$ ]]; then
log_message "Operation cancelled by user"
exit 0
fi
backup_config
if decommission_node; then
log_message "Node successfully removed from cluster"
echo "----------------------------------------------------------------"
echo "Node has been successfully removed from the cluster configuration."
echo "Backup of the original configuration is available in /root/"
echo "----------------------------------------------------------------"
else
log_message "Error: Decommission process failed"
echo "Error: Decommission process encountered issues. Check the logs."
exit 1
fi
}
main