From 63ff0751b905a43fa40488754f84769ffb7d0ab8 Mon Sep 17 00:00:00 2001 From: David Schroeder Date: Sun, 10 Dec 2023 14:52:45 -0600 Subject: [PATCH] update --- defaults.inc | 2 +- esxi-scripts/esxi-shutdown2.sh | 48 +++++++++++++++++----------------- offsite-power-check.sh | 4 +-- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/defaults.inc b/defaults.inc index 608925bf..48e0dd10 100755 --- a/defaults.inc +++ b/defaults.inc @@ -1,5 +1,5 @@ -VERS='2.4.10-12102023' +VERS='2.4.11-12102023' noheader=' update service dailytemp ' hc_cw=60 diff --git a/esxi-scripts/esxi-shutdown2.sh b/esxi-scripts/esxi-shutdown2.sh index ebc26ad8..e136b95e 100644 --- a/esxi-scripts/esxi-shutdown2.sh +++ b/esxi-scripts/esxi-shutdown2.sh @@ -11,32 +11,32 @@ for VM in $VMS ; do 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 & + 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..." -# vim-cmd hostsvc/maintenance_mode_enter -# -# echo "Now we suspend the Host..." -# esxcli system shutdown poweroff -d 10 -r "Shell initiated system shutdown" -# -# esxcli system maintenanceMode set -e false -t 0 +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..." +vim-cmd hostsvc/maintenance_mode_enter + +echo "Now we suspend the Host..." +esxcli system shutdown poweroff -d 10 -r "Shell initiated system shutdown" + +esxcli system maintenanceMode set -e false -t 0 exit \ No newline at end of file diff --git a/offsite-power-check.sh b/offsite-power-check.sh index c5c081ac..eb410566 100755 --- a/offsite-power-check.sh +++ b/offsite-power-check.sh @@ -116,14 +116,14 @@ $(date)" touch ${PW_TMPFOLDER}/power.offsite.ac.low.notice fi - if ([ ${OFFSITE_BATT_CAP%.*} -lt ${SHUTDOWNSERVERS_AT_LOAD} ] || [ $(expr `date +%s` - $(stat -f %m ${PW_TMPFOLDER}/power.offsite.ac.low)) -ge $(echo "scale=2; ${SHUTDOWNSERVERS_AFTER}*60" | bc) ]) && [ ! -f ${PW_TMPFOLDER}/power.offsite.off ]; then + if ([ ${OFFSITE_BATT_CAP%.*} -le ${SHUTDOWNSERVERS_AT_LOAD} ] || [ $(expr `date +%s` - $(stat -f %m ${PW_TMPFOLDER}/power.offsite.ac.low)) -ge $(echo "scale=2; ${SHUTDOWNSERVERS_AFTER}*60" | bc) ]) && [ ! -f ${PW_TMPFOLDER}/power.offsite.off ]; then echo "($(date +'%Y-%m-%d %H:%M:%S')) - ${OFFSITE_VOLTIN}'volts - ${OFFSITE_BATT_CAP}'% Battery - Powering Down Hosts!" >> ${PW_LOGFILE} SENDNOTICE "OFFSITE HOST POWER" "Powering DOWN offsite host(s) due to power outage" 1 touch ${PW_TMPFOLDER}/power.offsite.off for host in ${PW_OFFSITEHOSTS}; do if [ "$TEST" = "" ] || [ "$TEST" = "full" ]; then # ssh root@${host} /vmfs/volumes/652c94ef-ee49895b-365d-00109b3fea40/.SCRIPTS/esxi-shutdown2.sh & - ssh root@${host} "sh -s" < ${PW_FOLDER}/esxi-scripts/esxi-shutdown2.sh & + ssh root@${host} sh < ${PW_FOLDER}/esxi-scripts/esxi-shutdown2.sh & else echo "TESTMODE: Shutting down '${host}'" fi