diff --git a/defaults.inc b/defaults.inc index f32e43eb..b9ce159a 100755 --- a/defaults.inc +++ b/defaults.inc @@ -1,6 +1,6 @@ #!/usr/bin/env bash -VERS='2.3.12-10232023' +VERS='2.3.15-10252023' noheader=' update service dailytemp ' diff --git a/esxi-scripts/iscsi-sys-vm-shutdown-verify.ps1 b/esxi-scripts/iscsi-sys-vm-shutdown-verify.ps1 new file mode 100755 index 00000000..8b1401bb --- /dev/null +++ b/esxi-scripts/iscsi-sys-vm-shutdown-verify.ps1 @@ -0,0 +1,19 @@ +#!/usr/bin/env pwsh + +. /opt/idssys/powerwall/settings.ps1 + +Connect-VIServer -Server $args[0] -Protocol https -User $ESXiUsername -Password $ESXiPassword | Out-Null + +Get-Datastore | Where {$_.Name -like '*iSCSI-SYS*'} | Get-VM | if ($_.PowerState -eq "PoweredOn") { + Try{ + $vm = Get-VM -Name $vmName -ErrorAction Stop + switch($vm.PowerState){ + 'poweredon' { + sleep 5 + } + } + } + Catch{ + Write-Host "VM '$($vmName)' not found!" + } +} diff --git a/esxi-scripts/iscsi-sys-vm-shutdown.ps1 b/esxi-scripts/iscsi-sys-vm-shutdown.ps1 new file mode 100755 index 00000000..0f250809 --- /dev/null +++ b/esxi-scripts/iscsi-sys-vm-shutdown.ps1 @@ -0,0 +1,7 @@ +#!/usr/bin/env pwsh + +. /opt/idssys/powerwall/settings.ps1 + +Connect-VIServer -Server $args[0] -Protocol https -User $ESXiUsername -Password $ESXiPassword | Out-Null + +Get-Datastore | Where {$_.Name -like '*iSCSI-SYS*'} | Get-VM | Where {$_.PowerState -like '*On*' -and $_.Name -notlike '*CLS*'} | Shutdown-VMGuest -Confirm:$false diff --git a/esxi-scripts/iscsi-vm-shutdown-verify.ps1 b/esxi-scripts/iscsi-vm-shutdown-verify.ps1 index e52bd613..8a3fe9f8 100755 --- a/esxi-scripts/iscsi-vm-shutdown-verify.ps1 +++ b/esxi-scripts/iscsi-vm-shutdown-verify.ps1 @@ -4,7 +4,7 @@ Connect-VIServer -Server $args[0] -Protocol https -User $ESXiUsername -Password $ESXiPassword | Out-Null -Get-Datastore | Where {$_.Name -like '*iSCSI-PRI*' -or $_.Name -like '*iSCSI2*'} | Get-VM | if ($_.PowerState -eq "PoweredOn") { +Get-Datastore | Where {$_.Name -like '*iSCSI-PRI*'} | Get-VM | if ($_.PowerState -eq "PoweredOn") { Try{ $vm = Get-VM -Name $vmName -ErrorAction Stop switch($vm.PowerState){ diff --git a/esxi-scripts/sys-suspend.ps1 b/esxi-scripts/sys-suspend.ps1 index 9c6e012a..408209bf 100755 --- a/esxi-scripts/sys-suspend.ps1 +++ b/esxi-scripts/sys-suspend.ps1 @@ -4,4 +4,4 @@ Connect-VIServer -Server $args[0] -Protocol https -User $ESXiUsername -Password $ESXiPassword | Out-Null -Get-VM | Where {$_.PowerState -like '*On*' -and ($_.Name -like '*MySQL*' -or $_.Name -like '*PiHole*' -or $_.Name -like '*vCenter*')} | Suspend-VM -Confirm:$false +Get-VM | Where {$_.PowerState -like '*On*' -and ($_.Name -like '*MySQL-Node*' -or $_.Name -like '*LAN-DNS*')} | Suspend-VM -Confirm:$false diff --git a/powerwall.sh b/powerwall.sh index 7c3dff20..d0fc4684 100755 --- a/powerwall.sh +++ b/powerwall.sh @@ -825,24 +825,27 @@ SHUTDOWN_SERVERS(){ [ "${TEST}" != "true" ] && ${PW_FOLDER}/esxi-scripts/iscsi-vm-shutdown.ps1 ${ESXIHOST} >/dev/null 2>&1 echo "Done" done + for ESXIHOST in "${PW_MAINSITE_HOSTS[@]}"; do + echo -en "Enabling Maintenance Mode on: ${ESXIHOST} ... " + [ "${TEST}" != "true" ] && ssh root@${ESXIHOST} 'esxcli system maintenanceMode set -e true -t 0' & + echo "Done" + done + sleep 1m for ESXIHOST in "${PW_MAINSITE_HOSTS[@]}"; do echo -en "Verifying iSCSI VM's stopped on: ${ESXIHOST} ... " [ "${TEST}" != "true" ] && ${PW_FOLDER}/esxi-scripts/iscsi-vm-shutdown-verify.ps1 ${ESXIHOST} >/dev/null 2>&1 echo "Done" done - # sleep 1m for ESXIHOST in "${PW_MAINHOSTS[@]}"; do echo -en "Stopping Remaining VM's on: ${ESXIHOST} ... " if [ "${TEST}" != "true" ]; then - ssh root@${ESXIHOST} 'esxcli system maintenanceMode set -e true -t 0' & ${PW_FOLDER}/esxi-scripts/vm-shutdown.ps1 ${ESXIHOST} >/dev/null 2>&1 ${PW_FOLDER}/esxi-scripts/iscsi-server-shutdown.ps1 ${ESXIHOST} >/dev/null 2>&1 fi echo "Done" done - sleep 1m for ESXIHOST in "${PW_MAINHOSTS[@]}"; do - echo -en "Shutting down host: ${ESXIHOST} ..." + echo -en "Shutting down host & disabling Maintenance Mode: ${ESXIHOST} ..." if [ "${TEST}" != "true" ]; then ssh root@${ESXIHOST} 'esxcli system shutdown poweroff -d 10 -r "Automated ESXi host shutdown"' ssh root@${ESXIHOST} 'esxcli system maintenanceMode set -e false -t 0' @@ -865,9 +868,20 @@ SHUTDOWN_SERVERS(){ [ ! -f $FOLDER/shutdown.main ] && [ "${2}" == "TEMP" ] && SHUTDOWN_SERVERS MAIN if [ ! -f $FOLDER/shutdown.sys ]; then touch $FOLDER/shutdown.sys - + for ESXIHOST in "${PW_SYSHOSTS[@]}"; do - echo -en "Suspending DB, PiHole & vCenter VM's on: ${ESXIHOST} ... " + echo -en "Stopping iSCSI VM's on: ${ESXIHOST} ... " + [ "${TEST}" != "true" ] && ${PW_FOLDER}/esxi-scripts/iscsi-sys-vm-shutdown.ps1 ${ESXIHOST} >/dev/null 2>&1 + echo "Done" + done + for ESXIHOST in "${PW_SYSHOSTS[@]}"; do + echo -en "Enabling Maintenance Mode on: ${ESXIHOST} ... " + [ "${TEST}" != "true" ] && ssh root@${ESXIHOST} 'esxcli system maintenanceMode set -e true -t 0' & + echo "Done" + done + sleep 1m + for ESXIHOST in "${PW_SYSHOSTS[@]}"; do + echo -en "Suspending MySQL & LAN-DNS VM's on: ${ESXIHOST} ... " [ "${TEST}" != "true" ] && ${PW_FOLDER}/esxi-scripts/sys-suspend.ps1 ${ESXIHOST} >/dev/null 2>&1 echo "Done" done @@ -882,7 +896,6 @@ SHUTDOWN_SERVERS(){ for ESXIHOST in "${PW_SYSHOSTS[@]}"; do echo -en "Shutting Down Host: ${ESXIHOST} ... " if [ "${TEST}" != "true" ]; then - ssh root@${ESXIHOST} 'esxcli system maintenanceMode set -e true -t 0' ssh root@${ESXIHOST} 'esxcli system shutdown poweroff -d 10 -r "Automated ESXi host shutdown"' & ssh root@${ESXIHOST} 'esxcli system maintenanceMode set -e false -t 0' fi