-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuninstall.sh
More file actions
executable file
·153 lines (134 loc) · 5 KB
/
uninstall.sh
File metadata and controls
executable file
·153 lines (134 loc) · 5 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/bash
# Proxmox iSCSI Multipath Storage Plugin Uninstaller
# Run this script on each Proxmox VE node to remove the plugin
set -e
PLUGIN_DIR="/usr/share/perl5/PVE/Storage/Custom"
SCRIPT_INSTALL_DIR="/usr/local/bin"
SYSTEMD_DIR="/etc/systemd/system"
CONF_DIR="/etc/iscsi-mpath"
BACKUP_DIR="/var/lib/iscsi-mpath-plugin"
PVEMANAGERLIB="/usr/share/pve-manager/js/pvemanagerlib.js"
BACKUP_FILE="$BACKUP_DIR/pvemanagerlib.js.original"
MARKER_START="// ========== ISCSI-MPATH-PLUGIN-START =========="
MARKER_END="// ========== ISCSI-MPATH-PLUGIN-END =========="
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1"
}
error() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] ERROR: $1" >&2
}
warn() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] WARNING: $1" >&2
}
# Check if running as root
if [ "$EUID" -ne 0 ]; then
error "This script must be run as root"
exit 1
fi
log "Uninstalling Proxmox iSCSI Multipath Storage Plugin..."
# Stop and disable any active iscsi-mpath-connect services
log "Stopping iSCSI Multipath connection services..."
for service in /etc/systemd/system/multi-user.target.wants/iscsi-mpath-connect@*.service; do
if [ -L "$service" ]; then
instance=$(basename "$service" | sed 's/iscsi-mpath-connect@\(.*\)\.service/\1/')
log "Stopping iscsi-mpath-connect@$instance..."
systemctl stop "iscsi-mpath-connect@$instance" 2>/dev/null || true
systemctl disable "iscsi-mpath-connect@$instance" 2>/dev/null || true
fi
done
# Remove systemd service
log "Removing systemd service..."
if [ -f "$SYSTEMD_DIR/iscsi-mpath-connect@.service" ]; then
rm -f "$SYSTEMD_DIR/iscsi-mpath-connect@.service"
systemctl daemon-reload
fi
# Remove plugin
log "Removing ISCSIMultipathPlugin.pm..."
if [ -f "$PLUGIN_DIR/ISCSIMultipathPlugin.pm" ]; then
rm -f "$PLUGIN_DIR/ISCSIMultipathPlugin.pm"
fi
# Remove helper scripts
log "Removing helper scripts..."
rm -f "$SCRIPT_INSTALL_DIR/iscsi-connect.sh"
rm -f "$SCRIPT_INSTALL_DIR/iscsi-cluster-sync.sh"
rm -f "$SCRIPT_INSTALL_DIR/iscsi-rescan.sh"
# Ask about configuration directory
if [ -d "$CONF_DIR" ]; then
echo ""
read -p "Remove configuration directory $CONF_DIR? [y/N] " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
log "Removing configuration directory..."
rm -rf "$CONF_DIR"
else
log "Keeping configuration directory $CONF_DIR"
fi
fi
# Check for active iSCSI sessions
log "Checking for active iSCSI sessions..."
if command -v iscsiadm &> /dev/null; then
active_sessions=$(iscsiadm -m session 2>/dev/null | wc -l || echo "0")
if [ "$active_sessions" -gt 0 ]; then
warn "There are still $active_sessions active iSCSI session(s)."
warn "These were not disconnected. To disconnect manually, use:"
warn " iscsiadm -m node -T <target-iqn> -u"
warn " or: iscsiadm -m node --logoutall=all"
fi
fi
# Check for storage definitions
if [ -f /etc/pve/storage.cfg ]; then
iscsi_storage=$(grep -c "^iscsimpath:" /etc/pve/storage.cfg 2>/dev/null | head -1 | tr -d '\n' || echo "0")
iscsi_storage=${iscsi_storage:-0}
if [ "$iscsi_storage" -gt 0 ] 2>/dev/null; then
warn ""
warn "Found $iscsi_storage iSCSI Multipath storage definition(s) in /etc/pve/storage.cfg"
warn "These were not removed. Please remove them manually if needed."
fi
fi
# Restart pvedaemon to unload the plugin
log "Restarting pvedaemon..."
systemctl restart pvedaemon 2>/dev/null || warn "Failed to restart pvedaemon"
# Restore GUI (pvemanagerlib.js)
log "Checking for GUI modifications..."
if [ -f "$PVEMANAGERLIB" ] && grep -q "$MARKER_START" "$PVEMANAGERLIB"; then
if [ -f "$BACKUP_FILE" ]; then
log "Restoring original pvemanagerlib.js from backup..."
cp "$BACKUP_FILE" "$PVEMANAGERLIB"
log "Restarting pveproxy..."
systemctl restart pveproxy 2>/dev/null || warn "Failed to restart pveproxy"
else
log "Removing appended iSCSI Multipath GUI code..."
sed -i "/$MARKER_START/,/$MARKER_END/d" "$PVEMANAGERLIB"
log "Restarting pveproxy..."
systemctl restart pveproxy 2>/dev/null || warn "Failed to restart pveproxy"
fi
else
log "No GUI modifications found"
fi
# Clean up backup directory
if [ -d "$BACKUP_DIR" ]; then
echo ""
read -p "Remove backup directory $BACKUP_DIR? [y/N] " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
log "Removing backup directory..."
rm -rf "$BACKUP_DIR"
else
log "Keeping backup directory $BACKUP_DIR"
fi
fi
log ""
log "============================================"
log "Uninstallation complete!"
log "============================================"
log ""
log "Note: The following were NOT removed:"
log " - open-iscsi package and configuration"
log " - multipath-tools package and /etc/multipath.conf"
log " - /etc/iscsi/initiatorname.iscsi"
log " - Any active iSCSI sessions"
log " - Storage definitions in /etc/pve/storage.cfg"
log ""
log "To fully remove iSCSI/multipath support, also run:"
log " apt-get remove open-iscsi multipath-tools"
log ""