Solved

Windows EXE/Service To Restart Faulting IIS App Pool

Posted on 2008-10-15
6
735 Views
Last Modified: 2013-12-17
Hi

I am looking for guidance on creating a C# windows application to detect a web application is causing continuous faults, and to recycle/restart the appropriate application pool accordingly.

Ideally, I would like to be able to detect whether or not an application pool is running or not, then enable rapid-fail protection so that as soon as the app pool shuts down, this application can restart it.

If this isn't possible, I can write something to detect the errors coming in, and then recycle the appropriate app pool.

I have no idea how to get access to the application pools programmatically, or how to identify them as associated with a particular website

Your help is really appreciated

0
Comment
Question by:williambailie
  • 3
  • 3
6 Comments
 
LVL 37

Expert Comment

by:meverest
ID: 22838976
Hi,

Would it not be a better idea to fix the fault application/s?

when you enable rapid fail protection to shut down the WP, IIS should automatically restart it.

from: http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/5a6d38da-37d8-4d56-b6bd-1a2cbca59a57.mspx

"The WWW service detects the loss of communication and initiates the appropriate actions, typically sending an error or warning to the event log and then restarting the worker process"
0
 

Author Comment

by:williambailie
ID: 22839104
It restarts the worker process, but the web site remains stopped in IIS. Sorry, I don't think I was very clear in my question

The error is very hard to replicate, and therefore track down, and it seems to happen in only one instance of the web application, which is configured identically to a few other instances for other clients.

Also, we have our own error logging system for the application, which we can access to see if the application is faulting consistently.

So the two solutions to this issue are:

1. The ability to restart IIS worker processes programatically
2. The ability to start a website in IIS that is stopped, again programmatically.

The first instance is us having detected the faulting application, and restarting the worker process. Note, we don't want to restart IIS entirely, as there are other perfectly functioning web applications running.

In the second instance, it would be helpful to able to tell if the related IIS worker process is running,  but not essential

Any ideas? If these aren't possible, it's ok. We are considering rebuilding this application from scratch to see if that fixes it
0
 
LVL 37

Accepted Solution

by:
meverest earned 500 total points
ID: 22839267
is the web site stopped?  or the app pool?

You might use scheduler to run this every 1 minute or so:

cscript.exe C:\Inetpub\AdminScripts\adsutil.vbs START_SERVER W3SVC/AppPools/DefaultAppPool

to start the app pool (replace 'DefaultAppPool' with the relevant apppool name) or to start a web site:

cscript.exe C:\Inetpub\AdminScripts\adsutil.vbs START_SERVER W3SVC/1

as before, replace '1' with the web site ID.

if the server is already running, there should be no effect.  if it is stopped, this will get it running again.

it is a nasty botch, but *anything* except for fixing the underlying problem is no more than a sorry patch-up.

Cheers.
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:williambailie
ID: 22839720
Exactly, I agree it is a patch job, but this site cannot be down for very long, and it's getting annoying having to fix it at 1am on Sunday mornings. We're going to try one more thing this weekend to see if it remedies the problem, but if not, we'll have to go for this

I assume there is a STOP_SERVER command also?
0
 
LVL 37

Expert Comment

by:meverest
ID: 22839752
Hi,

umm, yes: there is a stop_server option.... but.... WHY!??! ;-)

Cheers.
0
 

Author Comment

by:williambailie
ID: 22839783
Haha, to force a 'restart' if needed, so calling a stop, then start.

Thanks for your help meverest. It is much appreciated
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

What is an ISAPI filter?   •      It's an assembly (.dll file) that can add or change the way IIS works.   •      They can be enabled globally for your web server or on a site-by-site basis.   When the IIS server receives a request, enabling the ISAPI fi…
Running classic asp applications under Windows Server 2008 R2 (x64) and IIS 7 is not as easy as one may think. It took me a while to figure it out while getting error 8002801d a few times. After you install the OS you will need to install the fol…
This video discusses moving either the default database or any database to a new volume.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now