views:

614

answers:

3

We have a system with a web app and a bunch of Windows Services doing some background work.

Whenever we need to make a more substantial change to the system, we end up having to issue an IIS Reset, and then manually restart all relevant Windows services.

Is there any way at all to be notified of such IISReset events in C# code, so that our Windows Services could restart themselves, whenever they detect such an IISReset command being executed?

Thanks! Marc

+1  A: 

Couldn't you just write a batch file to call IIS Reset and then restart the Windows Services?

I think the way to start a Windows Service is:

NET START "SERVICE NAME"
Nebakanezer
Yes I could - of course I could - but how can I make sure our sysadmins will *ALWAYS* use this batch file then?? Sure, for myself that's not a problem...... but we're in a managed, hosted environment where I can't take *ANYTHING* for granted.... that's why I was hoping to put the smarts to detect IISReset into my Windows service code so that I am NOT dependant on a sysadmin reading a readme file...
marc_s
+1  A: 

Agree with Nebakanezer, you may need to stop the service first though.

  • Option 1

NET STOP "SERVICE NAME"
NET START "SERVICE NAME"

  • Option 2

What about deploying a dummy asp.net app to the IIS server, then you can detect the application starting which should only happen on an IISReset and trigger the stop and restart of the services? I'm not sure if IIS has a tightened security model that will allow you to do thinks like stop services or trigger a batch file to do same but it's worth a try.

  • Option 3

If thats not an option for whatever reason, you could pull something together that monitors the IIS logs, I believe they log IIS resets.

TygerKrash
Yes, that might work - if we can make sure our sys admins will ALWAYS use our batch file..... since that's not always a viable alternative, I was hoping to maybe find a way our Windows services could be smart about this and detect the IISReset themselves....
marc_s
ok. I've thought of another option that might do the trick?
TygerKrash
+1  A: 

You could also plug into Windows Instrumentation with you own custom Windows Query Language expression. I've never used it for IIS directly, but I expect that there would be objects you can listen to, which lets you be aware of such changes. You can check this out : http://www.csharphelp.com/archives2/archive334.html as a starting point for research.

Irwin