Forum Moderators: open

Message Too Old, No Replies

Automatically restart IIS 6.0 when 'Service Unavailable'

How do you do it?

         

jgar

7:06 am on Dec 2, 2003 (gmt 0)

10+ Year Member



Our Windows 2003 Server is now performing much better than when we first installed it, however IIS does crash from time to time (usually at night), so users (and spiders) just get a 'Service Unavailable' message.

I have read that it may be possible to configure IIS 6.0 to restart automatically according to a choice of criteria: time period, number of hits, memory status, number of .asp scripts being queued ...

The problem is How do you configure IIS 6.0 to do it?
I've searched the web to find out how, but all I find are articles saying it can be done, without explicitly saying what I have to do ...

Can anyone help?

IanTurner

10:01 am on Dec 2, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



I use the command line interface

IISRESET /RESTART /TIMEOUT:nnn /REBOOTONERROR

from windows scheduled tasks.

jgar

10:35 am on Dec 2, 2003 (gmt 0)

10+ Year Member



Thanks for that. I am afraid I need to ask two beginner questions:

1) What does this command do exactly?
ie on what criteria does it restart?
Our problem is that .asp page processing scrips build up, and then all visitors get a "Service Unavailable" error.

2) Is it easy to set up

IanTurner

10:52 am on Dec 2, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



It is reasonably easy to set up, you need to create a .bat file which is called by scheduled tasks, you can then use wget (command line http interface to try accessing the IIS server - if it fails then call the IISRESET command from the .bat file)

jgar

7:11 pm on Dec 2, 2003 (gmt 0)

10+ Year Member



Thank you for your thoughts, IanTurner
I have been looking around trying to get a grip on what your saying.

IISRESET /RESTART /TIMEOUT:nnn /REBOOTONERROR - yes
Batch file - yes
scheduled tasks - yes

<wget (command line http interface to try accessing the IIS server - if it fails then call the IISRESET command from the .bat file)>

I'm not getting to grips with that bit ...

Can you give an example of using wget? Is it used in the batch file?

IanTurner

7:36 pm on Dec 2, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month


I use wget in the .bat file to make a request on the local webserver.

You will need to download a copy of wget, any good SE should find it for you.

The command is 'wget http://www.example.com/page.asp'

If you have a set up a test.asp page you can make it return a set value which can then be tested in the .bat file.

jgar

8:10 pm on Dec 2, 2003 (gmt 0)

10+ Year Member



Ah yes, now I see ..

How do you do the test?

IanTurner

2:03 am on Dec 3, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Here is an example of one of the tests that I use.

:: Check Connection to SQLServerDB
del testsql3.asp
C:\wget\wget.exe [example.com...]
find /C "25" testsql3.asp
IF ERRORLEVEL 1 IISRESET /RESTART /TIMEOUT:120 /REBOOTONERROR

The file testsql3.asp will return a body containing the value 25 (for reasons that elude me now - you can set up the page to return whatever you like in the body) If it fails to return 25 then for some reason the IIS Server or its DB connection is down and resetting IIS often clears the problem, so we try an IIS Reset.

There are lots of variants of testing a webserver available to you using wget. You could run the wget from your own machine and have it sound an alarm on your machine if the site goes down or have another webserver send an email to you.

jgar

3:56 am on Dec 3, 2003 (gmt 0)

10+ Year Member



Thanks!

I assume the code you just gave is the contents of the batch file - right?

How often do you run the test?
eg every 5 minutes, or every hour?

Jgar

IanTurner

8:26 am on Dec 3, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Yes the content is just a batch file.

Run the test as often as is suitable, for your application. I have that one set at every 5 mins.

jgar

8:57 am on Dec 3, 2003 (gmt 0)

10+ Year Member



This has been extremely useful - thank you very much.

jgar

6:43 pm on Dec 4, 2003 (gmt 0)

10+ Year Member



This is great stuff - I tried this technique.

I managed to watch the server screen as the batch file was called just after IIS went down.

It works on our server only up to a point though:

wget tried to download the page .... when it couln't, it tried again... again...and again - by the 7th time (and 20 minutes later), I stopped the batch file and restarted the server manually.

Is this normal? Is there a way to stop wget retyring and just giving an error?

IanTurner

7:51 pm on Dec 4, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Thats an rtfm

-t number
--tries=number

Set number of retries to number. Specify 0 or inf for infinite retrying.

In the Download Options section of the wget manual

jgar

6:35 pm on Dec 5, 2003 (gmt 0)

10+ Year Member



Thanks for that (although it did take me a while to figure our "rtfm") ;-)

It now works a treat, and I would recommend this to anyone who wants to have the confidence to be able to leave their desk sometimes ... without having to worry about the site being down for long periods ...

Our batch file now looks like this:

del testsql1.asp
C:\wget\wget.exe --timeout=30 --tries=1 [website.com...]
find /C "SQLServer Test Code 1" testscript.asp
IF ERRORLEVEL 1 IISRESET /RESTART /TIMEOUT:120 /REBOOTONERROR

IanTurner

7:32 pm on Dec 5, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



No problem, I hope you now understand what you are doing as well as being able just to write the code.

Let me know if you find any other enhancements to this.