Solved

How do I automate maintenance in my IIS web app with Powershell?

Posted on 2015-01-08
5
198 Views
Last Modified: 2015-01-26
Hi there,

I just wondering how to figure out with a solution that allows an application to signal to our load balancer that it is no longer part of a load balance pool...

I imagine to place a sort of empty "flag" file named "ExposeToLoadBalancer.flag" into the web application folder that will cause a particular URL within the application (that the loadbalancer monitors) to return a "200 OK" status code - and the load balancer will send  http requests to the application.

Instead, if the file does not exist, then the application will respond with "503 Under Maintenance", and this will cause the loadbalancer to no longer send new requests to the application.

This is the idea to automate the process.....but I'm not sure if it may be correct!

I'd like some help in order to create a script that can add the "ExposeToLoadBalancer.flag" to each application directory and one that will remove it.

Once a web application has been hidden from the loadbalancer, it can be stopped.
I assume to wait 30 seconds between "hiding" and stopping - just to allow any "in-flight" requests to complete.

Unluckly I'm not very confident with PS using IIS....could someone give me a hint?

Thanks in advance!
0
Comment
Question by:Alessandro Scafaria
  • 3
  • 2
5 Comments
 
LVL 27

Accepted Solution

by:
Dan McFadden earned 500 total points
ID: 40537679
Initial question:  What load balancer are you using?

I have done this in the following manner:

1. place a file (healthy.html) in the root of the website
2. configure LB to hit the file (http://host.domain.com/healthy.html)
3. if a 200 is returned, site is live.  if anything other than a 200 is returned, drain connections to server and remove from group
4. wait until the LB GUI states that connections have gone to 0.  This is not always time dependent.

All I would do is to rename the file from "healthy.html" to "unhealthy.html"

The rename command is easy PS:

rename-item -path D:\websites\www.test.com\healthy.html -newname unhealthy.html

Open in new window


- and back -

rename-item -path D:\websites\www.test.com\unhealthy.html -newname healthy.html

Open in new window


As for automating it, I would need a little more info to answer that.
1. Do you have predefined maintenance windows?
2. Do you take servers out of service at predefined times?
3. Do you realty need to take the website offline (shut it down)?
4. Would this be for a code update maintenance or OS type work... patching?

Dan
0
 
LVL 5

Author Comment

by:Alessandro Scafaria
ID: 40537863
Hi Dan,

thank you so much for your reply!

I'm using ARR as load balancer for my Web Farm built with IIS 7.5.

I'll try to answer properly to your bottom questions in only one shot:

Unfortunately, releases of web applications are frequently. During release, I usually hide and stop the existing version of an application, then install the new version and then start and expose the new version. All the while maintaining the old version (in case I need to roll-back).

I try to achieve this through folder structures that have a version number in their path and through website names that also contain a version number.

In your opinion, how should I "force" to remember what are the actual active sites in the script? This is important when, for example, a release of a website that was not successful, and that the latest version of one of the applications is not actually the "live" version.

Usually my maintenance window requires also a reboot. Is it possible to automate it too?

Many thanks for your help!!
0
 
LVL 27

Expert Comment

by:Dan McFadden
ID: 40538026
Here are a few articles on IIS and ARR:

Health Check:  http://blogs.iis.net/richma/archive/2010/12/14/application-request-routing-health-check-features.aspx

List of links:  http://www.iis.net/learn/web-hosting/scenario-build-a-web-farm-with-iis-servers

I understand your process, but I'm not sure I get the "how should I force" statement.  Let me restate your statement to see if I understand it:

1. script sets 1 or more ARR load balanced websites to "unhealthy"
2. script should know or have a list of active websites
3. script should reboot server

So if that is correct, you can have, in a text file, the paths to each website on the web server.  The script can loop thru this text file and do a predefined set of actions.

That much is straight forward, without knowing your structure and naming format, I can't say much more.

How does IIS get (re-)configured so that it knows what files to serve up upon request?

Dan
0
 
LVL 5

Author Comment

by:Alessandro Scafaria
ID: 40538109
Thank you Dan,

I appreciate! Here is an ideal example of my folder structure:

 C:\APPS

-----getinto2Italy
---------getinto2Italy
--------------101.16.7.0296
--------------------getinto2Italy.Service

-----getinto2France
---------getinto2France
--------------101.90.46.0296
--------------------getinto2France.Service.Host	

-----getinto2Ireland
---------getinto2Ireland
--------------101.90.46.0249
--------------------getinto2Ireland.Web.Admin

Open in new window


You made my point with your statements!

I'm not use how to help you when you're saying: "How does IIS get (re-)configured so that it knows what files to serve up upon request?"....

Thanks in advance!
0
 
LVL 27

Expert Comment

by:Dan McFadden
ID: 40543921
My question was, when you deploy a new version structure, what happens to the older versions?

-Do they stay in the "getinto2..." directory?
- Which of the directories in your example is the web root for the website?
- When someone goes to one of your websites, how do they know or how does IIS know, what URL to return?
- Are you using URL rewriting in ARR?

Have you experimented with web Deploy from MS?

Dan
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you one of those front-line IT Service Desk staff fielding calls, replying to emails, all-the-while working to resolve end-user technological nightmares? I am! That's why I have put together this brief overview of tools and techniques I use in o…
In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question