Almost Silent Citrix 24 Hour Restart Schedule

3 min read
Almost Silent Citrix 24 Hour Restart Schedule
Really think you need to restart every 24? Ok. Now lets make it almost unseen.

Reboot Every Day

If your team seeks to keep old tradition alive lets at least do our best to not kick people out of applications or desktops.

We can do this with a bit of a creative restart scheduling with existing resources. If needed maybe add a few extra machines as this will depend on your setup and 24-7 capacity use case.

Studio Already Has a Restart Scheduler

Of course Citrix Studio has a built in scheduled restart feature for every delivery group. Just set it and forget it. You’ll have to pick one of these two choices:

  • Restart all computers at once. This will cause all resources provided to be unavailable during the time until at least the first machine registers. This could take anywhere from 5-15 minutes of down time.
  • Staged restarts over time. This will cause users to potentially experience back to back forced kick outs. They’ll see your restart warning message twice. Its a bit confusing, try it yourself sometime and you’ll see how odd it can be.

New Thinking For Old Ideas

So you still want to restart every machine every day but you admit its a bad time for users and you don’t want that. Enough talk lets get down to it.

Below I’ve provided three PowerShell scripts to accomplish the following restart schedule, keep in mind this is for Windows Server OS VDAs:

  • 2:30pm. Place half of the machines in a delivery group into maintenance. These machines will continue to provide existing sessions and not new logins.
  • 10:30pm. Send message of pending restart to users, wait 5 minutes, power off machines, wait a minute, power on machines, wait 5 minutes, turn off maintenance. Check to see if at least one machine is out of maintenance and registered, if yes, now set the other half of machines to maintenance.
  • 6:30am. Send message of pending restart to users, wait 5 minutes, power off machines, wait a minute, power on machines, wait 5 minutes, turn off maintenance.

This will achieve the least disruption with the shortest possible session that gets kicked being around 8 hours and a max session time just shy of 24 hours.

Bonus For Machines That Fail Studios Restart Schedule

As you’ll note from below the command used to restart, reboot, shutdown, or what you’d like to call it is actually this:

New-BrokerHostingPowerAction -Action TurnOff -MachineName $vdaInMaintenance

I’ve used this command rather than shutdown as I’ve seen in some setups where machines would not gracefully shutdown. Our goal here is to make sure every machine is powered off and powered on without exception.

Best Regards
Michael Wood


2:30pm for Task Scheduler on Delivery Controller

#-Your input please
$dg = "MyDeliveryGroup"

#-Get list of machines
$vdas = Get-BrokerDesktop -Filter {DesktopGroupName -eq $dg} | ForEach {$_.MachineName}
$count = $vdas | Measure-Object | Select-Object Count | ForEach-Object {$_.Count}
$half = $count / 2
$halfRound = [math]::Round($Half)
$vdaToMaintenances = $vdas | Select -First $halfRound

#-Put in maintenance
ForEach ($vdaToMaintenance in $vdaToMaintenances){
    Set-BrokerMachineMaintenanceMode -InputObject $vdaToMaintenance $true
}

10:30pm for Task Scheduler on Delivery Controller

#-Your input please
$dg = "MyDeliveryGroup"

#-Get list of machines
$vdaInMaintenances = Get-BrokerDesktop -Filter {(DesktopGroupName -eq $dg) -and (InMaintenanceMode -eq "true")} | ForEach {$_.MachineName}
$vdaNotMaintenances = Get-BrokerDesktop -Filter {(DesktopGroupName -eq $dg) -and (InMaintenanceMode -eq "false")} | ForEach {$_.MachineName}

#-Take machines in maintenance, sends message, power off, power on, take out of maintenance
Foreach ($vdaInMaintenance in $vdaInMaintenances) {
    Get-BrokerSession -MachineName $vdaInMaintenance | Send-BrokerSessionMessage -Title "StoreFront Maintenance" -MessageStyle Critical -Text "In 5 minutes your Desktop will logoff. Your also free to logoff now and get a new Desktop."
}
Start-Sleep -S 300

Foreach ($vdaInMaintenance in $vdaInMaintenances) {
    New-BrokerHostingPowerAction -Action TurnOff -MachineName $vdaInMaintenance
}
Start-Sleep -S 60

Foreach ($vdaInMaintenance in $vdaInMaintenances) {
    New-BrokerHostingPowerAction -Action TurnOn -MachineName $vdaInMaintenance
}
Start-Sleep -S 300

Foreach ($vdaInMaintenance in $vdaInMaintenances) {
    Set-BrokerMachineMaintenanceMode -InputObject $vdaInMaintenance $false
}
Start-Sleep -S 60

#-Put other machines in maintenance if previous one not in maintenance and also registered.
#-If these two things are not true do not put other machines in maintenance, you investigate.
$vdaInMaintenanceOut = (Get-BrokerMachine -MachineName $vdaInMaintenance | Select-Object InMaintenanceMode | ForEach {$_.InMaintenanceMode}) -eq $False
$vdaInMaintenanceReg = (Get-BrokerMachine -MachineName $vdaInMaintenance | Select-Object RegistrationState | ForEach {$_.RegistrationState}) -eq "Registered"
If ($vdaInMaintenanceOut -and $vdaInMaintenanceReg) {
    Foreach ($vdaNotMaintenance in $vdaNotMaintenances) {
    Set-BrokerMachineMaintenanceMode -InputObject $vdaNotMaintenances $true
    }

}

6:30am for Task Scheduler on Delivery Controller

#-Your input please
$dg = "MyDeliveryGroup"

#-Get list of machines
$vdaInMaintenances = Get-BrokerDesktop -Filter {(DesktopGroupName -eq $dg) -and (InMaintenanceMode -eq "true")} | ForEach {$_.MachineName}

#-Take machines in maintenance, sends message, power off, power on, take out of maintenance
Foreach ($vdaInMaintenance in $vdaInMaintenances) {
    Get-BrokerSession -MachineName $vdaInMaintenance | Send-BrokerSessionMessage -Title "StoreFront Maintenance" -MessageStyle Critical -Text "In 5 minutes your Desktop will logoff. Your also free to logoff now and get a new Desktop."
}
Start-Sleep -S 300

Foreach ($vdaInMaintenance in $vdaInMaintenances) {
    New-BrokerHostingPowerAction -Action TurnOff -MachineName $vdaInMaintenance
}
Start-Sleep -S 60

Foreach ($vdaInMaintenance in $vdaInMaintenances) {
    New-BrokerHostingPowerAction -Action TurnOn -MachineName $vdaInMaintenance
}
Start-Sleep -S 300

Foreach ($vdaInMaintenance in $vdaInMaintenances) {
    Set-BrokerMachineMaintenanceMode -InputObject $vdaInMaintenance $false
}
Virtualize Brief


Follow