Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Guardian Program to monitor if IIS is up, and recycle app pool if down


This question is not answered. Helpful answers available: 1. Correct answers available: 1.


Permlink Replies: 3 - Last Post: Feb 1, 2018 12:53 AM Last Post By: Angus Robertson
Kevin Morris

Posts: 52
Registered: 1/8/13
Guardian Program to monitor if IIS is up, and recycle app pool if down  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 31, 2018 8:35 AM
I have an interesting challenge put to me by a customer. He has a website that he needs to monitor to ensure it's running. All the monitoring apps available on the Internet just monitor and notify him if down. He needs something that runs on his server and restarts his site if it's down. Here is a description of what my customer manually does now when the site is reported down (either by a site monitoring app, or by a user):

- Use a browser to manually try to connect to the website URL. If there is a 500 server error, then the site is down.
- If the URL responds with data then the site is working.

- (I suggested building in an "I'm Alive" URL function, just so I can get a little text response back, instead of the changing content of a webpage, or using a series of "if not error" tests)

- If the site is down, He manually goes through the following steps:
Stop the site in IIS
Recycle the Application Pool
Start the site
Usually just recycling the Application Pool works,
Usually just restarting the website in IIS works.
But sometimes he has to do both.

To recycle the Application Pool:
IIS Manager -> Application Pools -> Right click on the Application Pool -> click Recycle

To Stop/Start or restart the Website:
IIS Manager ->sites -> Find the Website -> Manage Website -> Restart / Start / Stop

My customer would like me to write a Delphi program that does all the monitoring and restarting automatically. My questions are these:

1) Is there an existing product that does this?
2) If not, assuming I would build a normal Delphi .exe, (so it has a UI which allows end user to configure it)
2a) How do I programmatically monitor the website for uptime? (components I shd use + Windows API commands)
2b) How do I programmatically recycle the Application Pool and/or restart IIS (components I shd use + Windows API commands)

Thanks in advance for any help you can provide. I still use Delphi XE3 and Delphi XE7. Ancient yes, but they still work well for what I need to do. I have the IPWorks component set that came with XE3, if that helps. My dev platform is Windows Server Essentials 2016. The production system is Windows Web Server 2008.

Edited by: Kevin Morris on Jan 31, 2018 8:43 AM
Angus Robertson

Posts: 205
Registered: 3/17/00
Re: Guardian Program to monitor if IIS is up, and recycle app pool if down
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 31, 2018 9:26 AM   in response to: Kevin Morris in response to: Kevin Morris
- If the site is down, He manually goes through the following
steps:
Stop the site in IIS
Recycle the Application Pool
Start the site
Usually just recycling the Application Pool works,
Usually just restarting the website in IIS works.
But sometimes he has to do both.

Is this a shared server or dedicated.

If dedicated, ask him to just try restarting the WWW Publishing Service instead
and see if that works.

That is trivial from any application (or script), accessing specific options
for specific sites in IIS is rather more complex.

You'd want to write a windows service application to do this in background, but
is really just a morning's work. Adding email notification when it happens is
another hour. At least with the ICS stuff I use.

Angus
Kevin Morris

Posts: 52
Registered: 1/8/13
Re: Guardian Program to monitor if IIS is up, and recycle app pool if down  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 31, 2018 10:26 AM   in response to: Angus Robertson in response to: Angus Robertson
Hi Angus

Is this a shared server or dedicated.

The customer owns and has full control over the physical server so he can install and run anything. However, it hosts many different websites, so I'm assuming this means restarting the WWW Publishing Service is not an option?

I guess we are stuck "accessing specific options for specific sites in IIS" as you say

Is there a Powershell script to do this? If not, is there a set of Windows APIs I can use for this?

You'd want to write a windows service application to do this in background,

Just to get started I want to use a regular Windows .exe, just for quick and easy config changes and display of output to the monitor. I can switch it to a background service later.

Also, is there a recommendation for testing the website URL to see if its up? I don't think pinging the server alone is enough.
Angus Robertson

Posts: 205
Registered: 3/17/00
Re: Guardian Program to monitor if IIS is up, and recycle app pool if  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 1, 2018 12:53 AM   in response to: Kevin Morris in response to: Kevin Morris
The customer owns and has full control over the physical server
so he can install and run anything. However, it hosts many
different websites, so I'm assuming this means restarting the WWW
Publishing Service is not an option?

His choice really, if low traffic and not too often, probably no-one would
notice.

I guess we are stuck "accessing specific options for specific
sites in IIS" as you say
Is there a Powershell script to do this? If not, is there a set
of Windows APIs I can use for this?

Yes, all this stuff can be scripted, but I've never needed to look that far,
MSDN will have everything you need.

Also, is there a recommendation for testing the website URL to
see if its up?

I just make an HTTPS request to a scripted page on all my servers every 10
minutes to check SSL is working and I get a 200 response. Have done for 15
years, using 'Test Server' scheduled task in an old program I wrote:

https://www.magsys.co.uk/dunman/

Angus
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02