This commit is contained in:
2023-12-10 16:14:25 -06:00
parent 24800b3d5f
commit ab41f6ed98
3 changed files with 71 additions and 74 deletions

View File

@@ -1,42 +1,42 @@
#/bin/sh
#Shutdown servers with pass-through devices
#vim-cmd vmsvc/power.shutdown 3
VMS=`vim-cmd vmsvc/getallvms | grep -v Vmid | awk '{print $1}'`
for VM in $VMS ; do
PWR=`vim-cmd vmsvc/power.getstate $VM | grep -v "Retrieved runtime info"`
if [ "$PWR" == "Powered on" ] ; then
name=`vim-cmd vmsvc/get.config $VM | grep -i "name =" | awk '{print $3}' | head -1 | cut -d "\"" -f2`
echo "Powered on: $name"
echo "Suspending: $name"
vim-cmd vmsvc/power.suspend $VM > /dev/null &
fi
done
while true ; do
RUNNING=0
for VM in $VMS ; do
PWR=`vim-cmd vmsvc/power.getstate $VM | grep -v "Retrieved runtime info"`
if [ "$PWR" == "Powered on" ] ; then
echo "Waiting..."
RUNNING=1
fi
done
if [ $RUNNING -eq 0 ] ; then
echo "Gone..."
break
fi
sleep 1
done
echo "Now we put the Host into maintenance mode..."
echo "Putting the Host into maintenance mode ..."
vim-cmd hostsvc/maintenance_mode_enter
echo "Now we suspend the Host..."
esxcli system shutdown poweroff -d 10 -r "Shell initiated system shutdown"
VMS=`vim-cmd vmsvc/getallvms | grep -v Vmid | awk '{print $1}'`
for VM in $VMS; do
if [ $VM -eq $VM ]; then
PWR=`vim-cmd vmsvc/power.getstate $VM | grep -v "Retrieved runtime info"`
if [ "$PWR" == "Powered on" ] ; then
name=`vim-cmd vmsvc/get.config $VM | grep -i "name =" | awk '{print $3}' | head -1 | cut -d "\"" -f2`
echo "Shutting down: $name"
vim-cmd vmsvc/power.shutdown $VM > /dev/null &
fi
fi
done
echo "Waiting for all VM's to be powered off ..."
while true ; do
RUNNING=0
for VM in $VMS; do
if [ $VM -eq $VM ]; then
PWR=`vim-cmd vmsvc/power.getstate $VM | grep -v "Retrieved runtime info"`
if [ "$PWR" == "Powered on" ] ; then
RUNNING=1
fi
fi
done
if [ $RUNNING -eq 0 ] ; then
echo "DONE"
break
fi
sleep 1
done
echo "Shutting down the Host in 10secs ..."
esxcli system shutdown poweroff -d 10 -r "Power-Monitor script initiated system shutdown"
echo "Disable maintenance mode before powering off ..."
esxcli system maintenanceMode set -e false -t 0
exit
exit 0