Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm running IIS on Windows Server 2003, i faced problems with 500 internal server error. I want to detect if any user gets the following error and restart server if it happens.

I just can't find the good way to detect if server returns this error. I tried to detect it by downloading some light page from server in period of time and checking for error, but i don't think this is optimal variant.

Please share some ideas around my task. Thanks in advance.

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

Restarting IIS because of a 500 response is about the same as cracking an egg with a hefty swing of a sledgehammer. You are not going to solve this problem with a restart, you are going to have to solve your problem by figuring out what is causing the 500 and correcting it. Automatically restarting the server on a 500 is not a resolution to the problem. At best it's a very weak workaround.

If you have a page that is generating a 500 and it's bad enough to require a server restart then you are in a bad way and you should be focusing on determining the cause of the error. Look in the IIS logs for error information. You may need to enable further log fields to get the information required. Turn on detailed error reporting in your application if it's not already enabled.

That said, if you want to detect when a 500 happens you will need to do something like the following:

  • Monitor the IIS log
  • Monitor the Windows Application event log.
  • Write a custom script (client-side) and add it to the custom error page for the 500 errors so that it will notify you

A good, compact description of the IIS logs can be found in this post. A related snippet:

The most valuable log files for IIS6 (and their locations) are:

  • HTTP.SYS Error Log - %windir%\System32\LogFiles\HTTPERR (Default location; configurable)
  • IIS Website Log - %windir%\System32\LogFiles\W3SVC# (Default location; configurable) **
  • Event Log (both System and Application)

If you are facing a situation of too many connections then I would still recommend troubleshooting the application, especially for memory leaks. Isolate the problematic application to its own application pool in order to attempt to avoid having to restart the entire server.

share|improve this answer
    
Server throws 500 error when there are too many user connections. I know that restarting is not a good solution, or may be it is not a solution at all. Can you point which log files i have to check? Where exactly 500 error will be logged? Of course I thought about scripting in error page but when php-cgi.exe crashes it wont help. –  F0G Aug 2 '12 at 12:19
    
See my edit regarding IIS6 log files. How many connections are you facing such that your machine becomes overwhelmed? The vast majority of times that I have faced this it is because of a misbehaving application. –  squillman Aug 2 '12 at 12:25
    
About 300 connections. Script is really heavy, but it works fine on other web servers. I faced this problem coz client doesn't want to use any other web server. Troubleshooting the code will be too hard. We have already removed a lot of unneeded functions, modules, gadgets, but still getting trouble with this... Another problem with code improving is that part of it is encrypted as we use payed CMS. –  F0G Aug 2 '12 at 12:35
    
I have caused 500 error manually, by ending process of php-cgi.exe. IMHO logging of the error took much time, about 2 minutes. –  F0G Aug 2 '12 at 12:38
1  
Ok, good luck to you! Note that IIS buffers log data and only writes it to the log files during certain intervals. This could be the cause of the 2 minute delay you mentioned. –  squillman Aug 2 '12 at 12:53
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.