Our production server is running Apache v2.2.4 on CentOS5.2. Mono v1.2.4 is integrated within Apache.
Recently, we faced a problem in our production server. From Apache's access_log, I found a HTTP 500 internal server error for one of the HTTP request and all subsequent HTTP requests also failed but with HTTP 503 service unavailable error. From thereafter, none of the requests were successful. Also, only later some time, we realized that our application was not working because of this error and then we restarted Apache service.
My questions are,
- in this kind of situation, how do I automatically restart Apache service when HTTP 503 error is encountered? Is there any Apache directive available to set?
- in general, what would cause a HTTP 503 error in Apache?
NOTE: Mono helps in running applications developed in .NET on a Linux-based OS.
EDIT: I agree on finding the root cause of this problem. In fact, we've been analyzing that too. Till we resolve it, am finding whether this could be restarted immediately on its own without having any downtime/service disruption for application users.
you should really fix the problem, but you could run something like this for a temp solution:
503 errors are normally related to errors on an application being served or a configuration error. It should be on apache's error log (if you don't have an error log, enable it on the configuration with the ErrorLog directive and control what level of error logging you want with LogLevel).
You can use monit to check a page and see if the HTTP code from a determined page is ok, and what to do if not (like, restarting apache).
I don't think you can, or should. You're much better leaving the server as-is and trying to find the root of the problem. IMHO, restarting on error is a bad policy in general.
If you still insist, try looking at something like SWATCH to monitor your apache logs and act on a 503 error.
You could have something like the following in your
httpd.conf
:That would call a script whenever an error is encountered, and set this up to restart the server.
I've encountered a 503 error when something I'm reverse proxying behind Apache is down. Restarting the service that is reverse proxied fixes it, but this error is expected if I've shut down that service.
Perhaps some extension is attempting to contact another service that isn't running, or is timing out.
This is what I understand you want:
You want something to monitor the log and INSTANTLY restart apache, if a specific error occurs. You do not want to probe every minute, just watch log.
You can achieve that, but it might give you a performance issue, although this won't cost you much server power.
However! This is generally not a good idea, as some person could find out what you were looking for in the log file and then just keep on making 404 errors with that string at the end of the URL. But:
Edit the config file and pipe the errorlog to a script, such as:
Then create that script and it could be something like this:
This will do what you ask for, but it is ugly and not recommended.