Hello everyone,
I solved the issue by doing the following, and it seems to work perfectly:
I created a custom shutdown script located at /usr/local/bin/nut-emergency-cleanup.sh:
#!/bin/bash
# 1. Force eject all mounted ISOs/CDs across VMs
xe vm-cd-eject --multiple 2>/dev/null
# 2. Find all PBDs connected to NFS, ISO, SMB, or iSCSI storage types and unplug them
NETWORK_PBDS=$(xe pbd-list currently-attached=true | grep -B 1 -E "storage-type: (nfs|iso|smb|iscsi)" | grep "uuid ( RO)" | awk '{print $5}')
for pbd_uuid in $NETWORK_PBDS; do
echo "Force unplugging PBD: $pbd_uuid"
xe pbd-unplug uuid="$pbd_uuid" --force 2>/dev/null
done
# 3. Finally, trigger the immediate hardware shutdown
/sbin/shutdown -h now
Instead of trigging a direct shutdown, this script now gets executed via a command forced in the authorized_keys file:
command="sudo /usr/local/bin/nut-emergency-cleanup.sh",no-port-forwarding,no-x11-forwarding,no-agent-forwarding [PUBLIC_KEY]
Thank you for your help!