The Shonk Project
Home arrow Scripts arrow A Better Way to Take a XenApp Server Offline
Thursday, 29 July 2010
Main Menu
Home
News
Blogs
Scripts
Contact Us


Syndicate
A Better Way to Take a XenApp Server Offline PDF Print
Written by Joe Shonk   
Monday, 08 September 2008

Recently, Andy Zhu published a PowerShell script that utilizes the undocumented CPSCOM to take a server “offline”.  I took a look at it and thought, “Wow, this is great.  I can use something like this for my maintenance scripts.”  So, I took Andy’s idea and created a vbscript version of the script.  Having this as a vbscript reduces the complexity and overhead of automating a PowerShell script.

So why not use the standard CHANGE LOGON /DISABLE command?  Well, in the old days, this is what we used.  That was until Presentation Server 3.0.  Citrix tried to enhance the functionality of the CHANGE LOGON command but broke it instead.  Well, technically it works as designed but it was (and still is) poorly designed.  If the IMA Service did not start properly after a restart, it was time to take the “walk of shame” to the Data Center as RDP connections would also be disabled.  Second, there are several cases in which you would want the servers come back online after a restart.  Using a startup script to force the IMA Service to start and change the logon status works intermittently at best.

What about the Customer Load Evaluator Method? Using a Custom Load Evaluator to take a server offline solves the problem with RDP Console from being locked out but suffers the same problems with trying to automatically bring a server online after a reboot.

Tell me about the Andy Zhu method and why is it better.  Andy’s method uses the Health Monitoring and Recovery feature of PS 4.5 (Sorry PS 4.0 users) to take a server off of the Load Balancing table.  By just taking the server off the table we gain the following benefits:

  • New connections are no longer routed to the server
  • RDC Connections are still available
  • A reboot will place the server back on to the LB table
  • Use HMR.  Automatically have a server skip its scheduled reboot if too many servers are offline.

*Note the HMR node under the Farm Properties HMR node under the Farm Properties of how many servers can be taken off the LB table.  Using this script (and Andy Zhu’s PowerShell script) to take a server offline will count against this number.  If you try to run the following script and the farm has reached it’s limit (number of servers that can be off the LB table) then the script will report an error.  You can increase this number accordingly but be sure to leave a buffer for the HMR to do its job too.

The advantage of this vbscript over PowerShell is you don't have to worry about the security complexities of running PowerShell scripts automatically and you don't need the overhead of the .NET framework.

Usage:

cscript.exe disablelb.vbs [ComputerName]

Other Notes:

  • If the [ComputerName] is not specified then the Computer Name of the machine that is executing the script will be used
  • Does not have to be run on the server that you wish to remove from the load table
  • Can use enablelb.exe [ComputerName] to place the server back on to the LB table
  • A reboot or restart of the IMA Service will also place the server back on to the LB table
  • Use the QUERY FARM /LOAD will display current servers in the lb table as well as their respective load.  Servers that have been removed from the lb table will not show up in the list.
  • The IMA Service needs to be running.  If it is not, the script will report an error (Error #2).

EnableLB.vbs:

'***************************************************************************
'*
'*  disablelb.vbs script written by Joe Shonk ( This e-mail address is being protected from spam bots, you need JavaScript enabled to view it )
'*  Version 1.0
'*
'*  Based off of Andy Zhu's PowerShell Script
'*  http://community.citrix.com/pages/viewpage.action?pageId=37388904
'*
'*  Syntax: cscript.exe disablelb.vbs [Computer Name]
'*
'*  This script is provided as-is, no warrenty is provided or implied.
'*  The author is NOT responsible for any damages or data loss that may occur
'*  through the use of this script.  Always test, test, test before
'*  rolling anything into a production environment.
'*
'*  This script is free to use for both personal and business use, however,
'*  it may not be sold or included as part of a package that is for sale.
'*
'*  A Service Provider may include this script as part of their service
'*  offering/best practices provided they only charge for their time
'*  to implement and support.
'*
'*  For distribution and updates go to: http://www.theshonkproject.com
'*
'***************************************************************************

On error resume next

Const DISABLELB = 0
Const ENABLELB = 1

Set objArgs = WScript.Arguments

If objArgs.Count > 0 then
    strComputer = objArgs(0)
Else
    Set objShell = CreateObject("WScript.Shell")
    strComputer = objShell.ExpandEnvironmentStrings("%COMPUTERNAME%")
End If

Set objSWbemServices = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

If Err.Number then
  wscript.echo "Error: " & Err.Number
  wscript.quit (Err.Number)
End If

If CheckService("IMAService") = FALSE then
    wscript.echo "The Citrix IMA Service is not started... Exiting Script..."
    wscript.quit (2)
End If

Set objLM = CreateObject("CPSCOMInterop.CPSLoadManager.1")
Set objReturnValue = objLM
objReturnValue = objLM.SetServerLMState(strComputer, DISABLELB)

If Err.Number then
  wscript.echo "Error: " & Err.Number
  wscript.quit (Err.Number)
End If

wscript.quit(0)

Function CheckService(strService)
    CheckService = FALSE
    Set colServices = objSWbemServices.ExecQuery("SELECT * FROM Win32_Service where Name = '" & strService & "'")
   
    For Each objService In colServices
        CheckService = objService.Started
        wscript.echo " - Checking Service: " & objService.Name
        If CheckService then
            wscript.echo " - Service " & objService.Name & " Started"
        Else
            wscript.echo " - Service " & objService.Name & " Not Started"
        End if
    Next
End Function

 

Comments
Add New RSS
Nicholas Dille  - Is CPSCOM supported by Citrix?     |2008-09-09 06:43:09
Hello,

it is great to see new methods emerging to handle Presentation
Server / XenApp. Unfortunately, there is a clear message about
the state of CPSCOM. Vishal Ganeriwala has commented on my CDN page
about CPSCOM http://community.citrix.com/display/xa/First+Di... that it is not supported by Citrix and that MFCOM is to be used
instead.

I have expressed my concerns http://blogs.sepago.de/nicholas/2008/07/21/the-... about officially publishing a CPSCOM-based script while not supporting the
underlying API.

Nevertheless, removing the server from the load
balancing tables greatly helps on automated reboot schedules because no
ONSTART tasks are necessary to get the
server online.

Regards,
Nicholas Dille - http://blogs.sepago.de/nicholas.
Jeremy Saunders     |2008-10-05 06:14:57
But not even MFCOM is truely supported Nicholas. Other than posting to CDN, you
cannot get support or help for your scripts.

Hey Joe,

This is great. I
like the idea of using the HMR, but haven't had enough time to get comfortable
with it yet. As you pointed out I believe the two biggest advantages are by
far...
1) A reboot will place the server back on to the LB table
2) Use HMR.
Automatically have a server skip its scheduled reboot if too many servers are
offline.

I use an "Out of service" load evaluator instead, which I've
scripted here: http://www.jhouseconsulting.com/index.php/blog/200
8/09/08/place-a-xenapp-server-in-and-out-of-servic e-the-easy-way/

My method
makes it easy to take a whole lot of servers off line by using a PSEXEC script,
and put them back on line again with enough intelligence so that it knows what
load elaluator it was previously set to. If using your script, you first need to
...
Nicholas Dille  - MFCOM is supported by Citrix     |2008-10-06 00:47:58
Jeremy,

in my opinion, MFCOM is fully supported by Citrix. The API is
documented including all interfaces, enumerations and types. Citrix provide
examples how to achieve typical tasks. I don't think Citrix can be expected to
offer support for writing a script based on MFCOM other than reporting bugs in
the API.

I have had several dealing with Citrix Support concerning MFCOM-based
scripts which stopped working after a new major release of Presentation Server /
XenApp. I have been pointed to a new or updated interface to correct the script.
If you are stuck with a script which should be working according to the
documentation, just take it on with them ;-)

In addition, some System Engineers
are quite skilled in this area and are able to help you or forward your question
to a colleague.

Hope that helps,
Nicholas.
Tom  - Does this work for PS 4.0??   |2009-01-12 08:39:22
I posted the same question about the PowerShell option.

Thank you, Tom
Joe Shonk  - Re: Does this work for PS 4.0??     |2009-01-12 10:34:26
The short answer is no. The HMR feature was added to 4.5 of which this depends
on. This goes for the VB script and Powershell.

Joe
Write comment
Name:
Email:
 
Website:
Title:
UBBCode:
[b] [i] [u] [url] [quote] [code] [img] 
 
 
:angry::0:confused::cheer:B):evil::silly::dry::lol::kiss::D:pinch:
:(:shock::X:side::):P:unsure::woohoo::huh::whistle:;):s
:!::?::idea::arrow:
 
Please input the anti-spam code that you can read in the image.

3.22 Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."

 
Next >