StarWind Virtual SAN: Feature Configuration Guide for Gentle Shutdown with APC PowerChute
- December 17, 2018
- 32 min read
- Download as PDF
Annotation
Relevant Products
StarWind Virtual SAN (VSAN)
Purpose
The purpose of this integration is to provide a reliable solution for managing unexpected power outages and planned hardware maintenance. By using PowerChute, users can ensure a gentle shutdown of VMs and hosts, effectively placing StarWind devices into maintenance mode to safeguard data and minimize synchronization times post-power outage.
Audience
The guide is aimed at system administrators, IT professionals, and data center managers who use StarWind Virtual SAN® and protect their servers with APC Smart-UPS.
Expected Result
After successful integration, PowerChute should enable the efficient and safe shutdown of VMs and hosts in case of power outages, with StarWind devices smoothly transitioning into maintenance mode. This setup aims to prevent potential issues with setup and reduce the time needed for StarWind devices synchronization after power is restored.
Introduction to PowerChute
PowerChute is a cross-platform application for managing APC Smart-UPS allowing users to manage UPS and prevent the unexpected power outage or plan the hardware maintenance when needed.
The combination of the PowerChute Network software and StarWind Maintenance Script allows users to gently turn off VMs and hosts, put the StarWind devices into maintenance mode and prevent the impact of an unexpected blackout. Users can save their data and avoid long synchronization.
NOTE: It’s recommended to install PowerChute on a dedicated machine (or server) that has its own UPS.
Disclaimer: StarWind Support does not write scripts on demand. Custom script troubleshooting is not supported. For PowerChute configuration please reach out to APC support.
Selecting the Environment
Please select the required option:
Installing PowerChute for Hyper-V
Installing PowerChute Network
1. Launch the downloaded setup file on the server to install PowerChute Network. The Setup wizard will appear. Read and accept the License Agreement.
2. PowerChute Network requires a Java Runtime Environment (JRE). Choose the Use the private JRE bundled with PowerChute option.
3. Select the Enable SNMP Support checkbox to manage the PowerChute from a different console.
4. Select Do not enable VMware Support.
5. Select Browse to modify the installation path if necessary. Otherwise, save the path offered by default.
6. Click Install to continue.
7. Click Finish to close the wizard.
Configuring PowerChute Network
1. On the Welcome page, read the information and click Next.
2. In Network Configuration, select the appropriate network configuration.
3. Specify the required connection scenario.
4. On the Security step, specify the Network Management Card credentials of APC Smart UPS.
9. Verify the information and click Apply to finish the configuration.
Applying StarWind Maintenance Script
StarWind has designed the script which allows users to gently turn off VMs and hosts, put the StarWind devices into Maintenance mode to prevent the data loss and long synchronization process.
1. Navigate to Configure Events and click on UPS on Battery command file.
2. Enable the command file checkbox for the UPC on Battery event (local or network path can be selected).
3. Select the following script file:
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 |
# Execute lines below before running this script, to generate SecureString passwords ################################################################################# #mkdir c:\shutdown #Read-Host -Prompt "Enter password for service user" -AsSecureString | ConvertFrom-SecureString | out-file c:\shutdown\cred.txt #(type in the password of the user you want to use for running the script) #cat c:\shutdown\cred.txt $password = get-content C:\shutdown\cred.txt | convertto-securestring $user = "Domain\ServiceUser" #Specify domain/user credentials $cred = New-Object System.Management.Automation.PSCredential ($user,$password) $StarWind = 'SW-HCA-VM-01' #specify your StarWind VM (or host) ip-address #Getting StarWind devices in to "Maintenance Mode" Import-Module StarWindX try { $server = New-SWServer -host $StarWind -port 3261 -user root -password starwind $server.Connect() write-host "Devices:" -foreground yellow foreach($device in $server.Devices){ if( !$device ){ Write-Host "No device found" -foreground red return } else { $device.Name $disk = $device.Name if ($device.Name -like "HAimage*"){ $device.SwitchMaintenanceMode($true, $true) write-host "$disk entered maintenance mode" } else { write-host "$disk is not an HA device, maintenance mode is not supported" } } } } catch { Write-Host $_ -foreground red } finally { $server.Disconnect() } #Here I'll start a new PowerShell remote session with the selected host Enter-PSSession -ComputerName $StarWind -Credential $cred $action = New-ScheduledTaskAction -Execute 'Powershell.exe' -Argument '-ExecutionPolicy Bypass c:\SW_Maintenance_Off.ps1 -RunType $true -Path c:\SW_Maintenance_Off.ps1' $trigger = New-ScheduledTaskTrigger -AtStartup -RandomDelay 00:00:30 $settings = New-ScheduledTaskSettingsSet -Compatibility Win8 $principal = New-ScheduledTaskPrincipal -UserId SYSTEM -LogonType ServiceAccount -RunLevel Highest $definition = New-ScheduledTask -Action $action -Principal $principal -Trigger $trigger -Settings $settings -Description "Maintenance Mode" Register-ScheduledTask -TaskName "Maintenance Mode off" -InputObject $definition |
NOTE: VMs or Nodes might be needed to install some Windows updates, so it is highly recommended to set them up in the PowerChute console before running this script itself.
Allow PowerShell remote session on both hosts to use this script. Setup power-off configuration in PowerChute console for all the VMs, then run the following script from PowerChute console (apply the Maintenance mode on StarWind devices).
Installing PowerChute for VMware
Installing PowerChute Network
1. Launch the downloaded setup file on the server to install PowerChute Network. The Setup wizard will appear. Read and accept the License Agreement.
2. PowerChute Network requires a Java Runtime Environment (JRE). Choose the Use the private JRE bundled with PowerChute option.
3. Select the Enable SNMP Support checkbox to manage the PowerChute from a different console.
4. If VMware is used in the environment, select Enable VMware Support.
5. Select Browse to modify the installation path if necessary. Otherwise, save the path offered by default.
6. Click Install to continue.
7. Click Finish to close the wizard.
Configuring PowerChute Network
1. On the Welcome page, read the information and click Next.
2. In Network Configuration, select the appropriate network configuration: IPv4 or IPv6.
3. Specify the required connection scenario.
4. In VMware Configuration, specify the connection method to the environment: Standalone VMware Host for single host or Host managed by vCenter Server for vCenter.
5. Specify the IP address and credentials of the vCenter.
NOTE: Select the vCenter Server running on a VM option if vCenter is running on the VM inside the ESXi host.
6. Select the hosts powered by the UPS(s).
7. Specify the Virtualization Settings.
8. On the Security step, Specify the Network Management Card credentials of APC Smart UPS.
9. Verify the information and click Apply to finish the configuration.
Applying StarWind Maintenance Script
StarWind has designed the script which allows users to gently turn off VMs and hosts, put the StarWind devices into Maintenance mode to prevent the data loss and long synchronization process.
1. Navigate to Configure Events and click on UPS on Battery command file.
2. Enable the command file checkbox for the UPC on Battery event (local or network path can be selected).
Select the following script file:
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 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 |
################################################################################ # # Variables: $vcenter - The IP/DNS of your vCenter Server # $username/password - credentials for your vCenter Server # $username4host/password4host - credentials for yours VM host # $cluster - Name of specific cluster to target within vCenter # $datacenter - Name of specific datacenter to target within vCenter # $StarWind - IP address of one of StarWind VMs # ################################################################################# # Execute lines below before running this script, to generate securestring passwords ################################################################################# #mkdir c:\shutdown #Read-Host -Prompt "Enter password for vCenter" -AsSecureString | ConvertFrom-SecureString | out-file c:\shutdown\cred.txt #(type in the password of the user you want to use for running the script) #cat c:\shutdown\cred.txt # #Read-Host -Prompt "Enter password for ESXI hosts" -AsSecureString | ConvertFrom-SecureString | out-file c:\shutdown\cred4host.txt #(type in the password of the user you want to use for running the script) #cat c:\shutdown\cred4host.txt ################################################################################ # Some variables $vcenter = "192.168.1.235" $username = "administrator@vsphere.local" $username4host = "root" $cluster = "SW-SUP-CLUSTER" $datacenter = "SWDATACENTER" $vCenterVMName = "SW-SUP-VCENTER" #Name of vCenter VM $StarWindVM1 = "SW-SUP-FS-00" #Name of first StarWind VM $StarWindVM2 = "SW-SUP-FS-01" #Name of second StarWind VM $StarWind = "192.168.1.233" #IP address of one of StarWind VMs $ESXIhost1 = "192.168.1.231" #Name of first ESXI Host $ESXIhost2 = "192.168.1.232" #Name of second ESXI Host $password = get-content C:\shutdown\cred.txt | convertto-securestring $password4host = get-content C:\shutdown\cred4host.txt | convertto-securestring $credentials = new-object System.Management.Automation.PSCredential $username, $password $credentials4host = new-object System.Management.Automation.PSCredential $username4host, $password4host $time = ( get-date ).ToString('HH-mm-ss') $date = ( get-date ).ToString('dd-MM-yyyy') $logfile = New-Item -type file "C:\shutdown\ShutdownLog-$date-$time.txt" -Force Write-Host "" Write-Host "Shutdown command has been sent to the vCenter Server." -Foregroundcolor yellow Write-Host "This script will shutdown all of the VMs and hosts located in $datacenter." -Foregroundcolor yellow Write-Host "" Sleep 5 Add-Content $logfile "$(get-date -f dd/MM/yyyy) $(get-date -f HH:mm:ss) PowerOff Script Engaged" Add-Content $logfile "" # Connect to vCenter $counter = 0 if ($counter -eq 0){ Set-PowerCLIConfiguration -InvalidCertificateAction ignore -Confirm:$false | Out-Null } Write-Host "Connecting to vCenter - $vcenter.... " -nonewline Set-PowerCLIConfiguration -InvalidCertificateAction ignore -confirm:$false Add-Content $logfile "$(get-date -f dd/MM/yyyy) $(get-date -f HH:mm:ss) Connecting to vCenter - $vcenter" $success = Connect-VIServer $vcenter -Credential $credentials -WarningAction:SilentlyContinue if ($success) { Write-Host "Connected!" -Foregroundcolor Green } else { Write-Host "Something is wrong, Aborting script" -Foregroundcolor Red Add-Content $logfile "$(get-date -f dd/MM/yyyy) $(get-date -f HH:mm:ss) Something is wrong, Aborting script" exit } Write-Host "" Add-Content $logfile "" # Turn Off vApps Write-Host "Stopping VApps...." -Foregroundcolor Green Write-Host "" Add-Content $logfile "$(get-date -f dd/MM/yyyy) $(get-date -f HH:mm:ss) Stopping VApps..." Add-Content $logfile "" $vapps = Get-VApp | Where { $_.Status -eq "Started" } if ($vapps -ne $null) { ForEach ($vapp in $vapps) { Write-Host "Processing $vapp.... " -ForegroundColor Green Write-Host "" Add-Content $logfile "$(get-date -f dd/MM/yyyy) $(get-date -f HH:mm:ss) Stopping $vapp." Add-Content $logfile "" Stop-VApp -VApp $vapp -Confirm:$false | out-null Write-Host "$vapp stopped." -Foregroundcolor Green Write-Host "" } } Write-Host "VApps stopped." -Foregroundcolor Green Add-Content $logfile "$(get-date -f dd/MM/yyyy) $(get-date -f HH:mm:ss) VApps stopped." Add-Content $logfile "" # Change DRS Automation level to partially automated... Write-Host "Changing cluster DRS Automation Level to Partially Automated" -Foregroundcolor green Get-Cluster $cluster | Set-Cluster -DrsAutomation PartiallyAutomated -confirm:$false # Change the HA Level Write-Host "" Write-Host "Disabling HA on the cluster..." -Foregroundcolor green Write-Host "" Add-Content $logfile "Disabling HA on the cluster..." Add-Content $logfile "" Get-Cluster $cluster | Set-Cluster -HAEnabled:$false -confirm:$false # Get VMs again (we will do this again instead of parsing the file in case a VM was powered in the nanosecond that it took to get here.... Write-Host "" Write-Host "Retrieving a list of powered on guests...." -Foregroundcolor Green Write-Host "" Add-Content $logfile "$(get-date -f dd/MM/yyyy) $(get-date -f HH:mm:ss) Retrieving a list of powered on guests...." Add-Content $logfile "" $poweredonguests = Get-VM -Location $cluster | where-object {$_.PowerState -eq "PoweredOn" } Add-Content $logfile "$(get-date -f dd/MM/yyyy) $(get-date -f HH:mm:ss) Checking to see if vCenter is virtualized" # Retrieve host info for vCenter if ($vcenterVMName -ne "NA") { Add-Content $logfile "$(get-date -f dd/MM/yyyy) $(get-date -f HH:mm:ss) vCenter is indeed virtualized, getting ESXi host hosting vCenter Server" $vCenterHost = (Get-VM $vCenterVMName).Host.Name Add-Content $logfile "$(get-date -f dd/MM/yyyy) $(get-date -f HH:mm:ss) $vCenterVMName currently running on $vCenterHost - will process this last" } else { Add-Content $logfile "$(get-date -f dd/MM/yyyy) $(get-date -f HH:mm:ss) vCenter is not virtualized" } Add-Content $logfile "$(get-date -f dd/MM/yyyy) $(get-date -f HH:mm:ss) Proceeding with VM PowerOff" Add-Content $logfile "" # And now, let's start powering off some guests.... ForEach ( $guest in $poweredonguests ) { if ($guest.Name -notmatch $vCenterVMName -and $guest.Name -notmatch $StarWindVM1 -and $guest.Name -notmatch $StarWindVM2) { Write-Host "Processing $guest.... " -ForegroundColor Green Write-Host "Checking for VMware tools install" -Foregroundcolor Green $guestinfo = get-view -Id $guest.ID if ($guestinfo.config.Tools.ToolsVersion -eq 0) { Write-Host "No VMware tools detected in $guest , hard power this one" -ForegroundColor Yellow Write-Host "" Add-Content $logfile "$(get-date -f dd/MM/yyyy) $(get-date -f HH:mm:ss) $guest - no VMware tools, hard power off" Stop-VM $guest -confirm:$false | out-null } else { write-host "VMware tools detected. I will attempt to gracefully shutdown $guest" Write-Host "" Add-Content $logfile "$(get-date -f dd/MM/yyyy) $(get-date -f HH:mm:ss) $guest - VMware tools installed, gracefull shutdown" $vmshutdown = $guest | shutdown-VMGuest -Confirm:$false | out-null } } } # Let's wait a minute or so for shutdowns to complete Write-Host "" Write-Host "Giving VMs 2 minutes before resulting in hard power off" Write-Host "" Add-Content $logfile "" Add-Content $logfile "$(get-date -f dd/MM/yyyy) $(get-date -f HH:mm:ss) Waiting a couple minutes then hard powering off all remaining VMs" Sleep 120 # Now, let's go back through again to see if anything is still powered on and shut it down if it is Write-Host "Beginning Phase 2 - anything left on.... night night...." -ForegroundColor red Write-Host "" # Get our list of guests still powered on... $poweredonguests = Get-VM -Location $cluster | where-object {$_.PowerState -eq "PoweredOn" } if ($poweredonguests -ne $null) { ForEach ( $guest in $poweredonguests ) { if ($guest.Name -notmatch $vCenterVMName -and $guest.Name -notmatch $StarWindVM1 -and $guest.Name -notmatch $StarWindVM2) { Write-Host "Processing $guest ...." -ForegroundColor Green #no checking for toosl, we just need to blast it down... write-host "Shutting down $guest - I don't care, it just needs to be off..." -ForegroundColor Yellow Write-Host "" Add-Content $logfile "$(get-date -f dd/MM/yyyy) $(get-date -f HH:mm:ss) $guest - Hard Power Off" Stop-VM $guest -confirm:$false | out-null } } } # Wait 30 seconds Write-Host "Waiting 30 seconds and then proceeding with host power off" Write-Host "" Sleep 30 Write-Host "Putting StarWind devices in to Maintenance Mode " Write-Host "" #Getting StarWind devices in to "Maintenance Mode" Import-Module StarWindX try { $server = New-SWServer -host $StarWind -port 3261 -user root -password starwind $server.Connect() write-host "Devices:" -foreground yellow foreach($device in $server.Devices){ if( !$device ){ Write-Host "No device found" -foreground red return } else { $device.Name $disk = $device.Name if ($device.Name -like "HAimage*"){ $device.SwitchMaintenanceMode($true, $true) write-host "$disk entered maintenance mode" } else { write-host "$disk is not an HA device, maintenance mode is not supported" } } } } catch { Write-Host $_ -foreground red } finally { $server.Disconnect() } Enter-PSSession -ComputerName $StarWindVM1 -Credential Administrator $action = New-ScheduledTaskAction -Execute 'Powershell.exe' -Argument '-ExecutionPolicy Bypass c:\SW_Maintenance_Off.ps1 -RunType $true -Path c:\SW_Maintenance_Off.ps1.ps1' $trigger = New-ScheduledTaskTrigger -AtStartup -RandomDelay 00:00:30 $settings = New-ScheduledTaskSettingsSet -Compatibility Win8 $principal = New-ScheduledTaskPrincipal -UserId SYSTEM -LogonType ServiceAccount -RunLevel Highest $definition = New-ScheduledTask -Action $action -Principal $principal -Trigger $trigger -Settings $settings -Description "Maintenance Mode" Register-ScheduledTask -TaskName "Maintenance Mode off" -InputObject $definition Add-Content $logfile "" Add-Content $logfile "$(get-date -f dd/MM/yyyy) $(get-date -f HH:mm:ss) Processing power off of all hosts now" Sleep 30 # and now its time to slam down the hosts - I've chosen to go by datacenter here but you could put the cluster # There are some standalone hosts in the datacenter that I would also like to shutdown, those vms are set to # start and stop with the host, so i can just shut those hosts down and they will take care of the vm shutdown shutdown-VMGuest $vCenterVMName -Confirm:$false Write-Host "Waiting for vCenter shutdown" -ForegroundColor Green Add-Content $logfile "$(get-date -f dd/MM/yyyy) $(get-date -f HH:mm:ss) Shutting down $vCenterVMName" Sleep 300 Connect-VIServer $ESXIhost1 -Credential $credentials4host -WarningAction:SilentlyContinue Write-Host "Shutting down $ESXIhost1" -ForegroundColor Green Add-Content $logfile "$(get-date -f dd/MM/yyyy) $(get-date -f HH:mm:ss) Shutting down $ESXIhost1" Stop-VMHost $ESXIhost1 -Confirm:$false -Force Sleep 120 Connect-VIServer $ESXIhost2 -Credential $credentials4host -WarningAction:SilentlyContinue Write-Host "Shutting down $ESXIhost2" -ForegroundColor Green Add-Content $logfile "$(get-date -f dd/MM/yyyy) $(get-date -f HH:mm:ss) Shutting down $ESXIhost2" Stop-VMHost $ESXIhost2 -Confirm:$false -Force Add-Content $logfile "" Add-Content $logfile "$(get-date -f dd/MM/yyyy) $(get-date -f HH:mm:ss) All done!" # That's a wrap |
NOTE: Install Power-CLI to use this script: Log in to StarWind VM and install vSphere PowerCLI on each StarWind virtual machine by adding the PowerShell module (Internet connectivity is required). To do so, run the following command in PowerShell:
1 |
Install-Module -Name VMware.PowerCLI -AllowClobber |
Exit StarWind Maintenance Mode
To turn off the StarWind Maintenance Mode, put the following script directly to C:\ and name it as SW_Maintenance_Off.ps1.
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 |
Write-Host "Waiting untill service is starting" $ServiceName = 'StarWindService' $StarWind = 'SW-HCA-VM-01' #specify your StarWind VM (or host) ip-address $arrService = Get-Service -Name $ServiceName if ($arrService.Status -ne "Running"){ Start-Service $ServiceName Write-Host "Starting " $ServiceName " service" " ---------------------- " " Service is now started" } if ($arrService.Status -eq "running"){ Write-Host "$ServiceName service is already started" #Getting StarWind devices in to "Maintenance Mode" Import-Module StarWindX try { $server = New-SWServer -host $StarWind -port 3261 -user root -password starwind $server.Connect() write-host "Devices:" -foreground yellow foreach($device in $server.Devices){ if( !$device ){ Write-Host "No device found" -foreground red return } else { $device.Name $disk = $device.Name if ($device.Name -like "HAimage*"){ $device.SwitchMaintenanceMode($false, $true) write-host "$disk exited maintenance mode" } else { write-host "$disk is not an HA device, maintenance mode is not supported" } } } } catch { Write-Host $_ -foreground red } finally { $server.Disconnect() } Unregister-ScheduledTask -TaskName "Maintenance Mode off" -Confirm:$false } |
Conclusion
The integration of PowerChute offers a robust solution for managing power supply issues in virtualized environments. This setup is essential for the scenarios where power interruptions are a concern. By following the instructions for installing and configuring PowerChute, users can enhance the resilience and reliability of their IT infrastructure against unexpected power disruptions.