Friday, October 15, 2010

How would you like to reset your webserver from anyplace. and device, anytime using a Citrix Xenapp Published App?

Often times as an administrator you are some place out in the field and you will get a call that your Web Server has crashed for some reason and needs reset. Or you want your helpdesk people to be able to reset the Webserver but not really have access to the actual desktop.

Here is a method I came up with to publish and Icon within Citrix Xenapp to allow an admin or helpdest staff to quickly do an IISReset remotely via Citrix Xenapp application to get your web server back going in most situations.

As a bonus this will give you a log file that gives you an idea when your web server is crashing and people are resetting it so you can research your log files for a fix.
Note that this script assumes that your Citrix Server is on the same network as your webserver.  I haven't tried it using IP addresses instead of a server name, but I suspect it might work as long as you are putting in an account that has admin priveleges on the Webserver in the script)

To get started you will need to do a few things.

Firstly you will have to download PSTools from Microsoft and copy the PSExec.exe file to the root of the Citrix server that you will be publishing the app to. Lets call that server CitrixAdmin henceforth. PSTools is written by Mark Russinovich and can be found at:
Link to information page on PSexec

Direct Download Link to

Download, extract the PSTools zip to a folder on your CitrixAdmin server and then copy the PSExec.exe file in the root of your C: drive. Also copy the PSExec.exe file to the C: drive of your Webserver.

The other thing you will need to do is copy the IISreset command to your C:/ root of your Webserver from the C:\WINDOWS\system32 folder (open a command prompt and type: copy C:\WINDOWS\system32\iisreset.exe c:  or use Windows Explorer to do it)

Next you need to create a simple command batch file on your CitrixAdmin Server that will run your IISReset command on the remote server that we can publish in your Citrix APP farm.

In order for the IISReset and PSExec to run you will need to pick an account with admin priveleges.

Open up Notepad or your favorite text editor and add the following text between the lines:
Echo This is a script file to reset the Web Server
Echo The web server was reset at %time% %date%>>C:\WebReset.txt

Echo Off
c:\psexec.exe \\web -u administratoracct -p accountpassword c:\iisreset.exe /restart
Save the file to the C:\ root folder (or another folder of your choosing) on the Citrixadmin server as "resetweb.cmd"

(In the above script you will need to change file://web/ to file://the%20name%20of/ your webserver. You will also need to change the administratoracct text with the account name that has admin priveleges on your Webserver and accountpassword with the password to that account. Note: yes it is open text password but this file will be on your CitrixAdmin server and not out on the web server)

OK so what this little script does is remotely run IISreset on the Webserver from your CitrixAdmin server.  Then it generates a file on the webserver called Webreset.txt that keeps track of the time and date that the script was run. You can even test the script by clicking on it and running it.  It will reset your IIS Web server so be certain that it is during off hours when you test this.

Now all that needs to be done is create a simple published application for the resetweb.cmd script file you created on the CitrixAdmin Server.

As a Citrix Admin you should know how to publish an application but I will give the steps here anyways. 
On your CitrixAdmin find and Open the Citrix Access Management Console and drill down to the Farm applications folder, right click on it and Select New/ Publish Application from the context menu. Proceed as if you are creating a new app by giving it a name, description etc. and go to next screen.  Keep the defaults on the application publishing screen as an application being published from the server and click next.

To set up the application on the Application Location Properties screen all you need do is type in:  C:\resetweb.cmd   into the Command Line field and C:\ into the working directory.  Finish through publishing the app by adding your users you want to be able to reset the web server and thats it! (note if you put the into a different directory you will have to modify the command line and working directory with that directory and the psexec.exe file must also be in that directory.

Connect to your Citrix apps via your favorite device and you now will have an icon you can click on to reset your Web server from where ever you are at! And you will have a log file in the root of your webserver that will tell you whenever this is done.

Now that you have done this what other applications/scripts can you think of that you can use PSexec to run commands remotely via a Citrix published app to save on administration time? The possibilities seem endless.

No comments: