Don’t Forget About The Bots!
Tuesday, May 15th, 2007It is occasionally necessary for us to take down one of our customer web sites in order to perform maintenance tasks. Most of the time this doesn’t last more than a few minutes, but if things go wrong, it could take much more than that. These days we use Capistrano for deployment, which has built in functionality to help easily disable a web site (disable_web). That provides reasonable feedback to users coming to the site, so they know what is happening. What it doesn’t cover are the machines accessing the site. Chances are those programs can’t tell that the site is down from the maintenance page.
Turns out that this problem was easy to fix, all that was needed was to get the web server to return the correct HTTP status code. As it was, it was returning code 200: “OK”, when the more appropriate code would be a 503: “Service Temporarily Unavailable.”
All our customer sites run with an Apache server sitting in front of the Rails sites. This allowed us to make the maintenance page a script rather than just a static HTML page.
- To start, we implemented the custom maintenance pages described by Mike Clark.
- Next we replaced the HTML version of the maintenance page with a PHP page.
- And last was to add in a couple of custom headers into the PHP page so that it returned the correct information.
<?php
header("HTTP/1.1 503 Service Temporarily Unavailable");
header("Retry-After: 300");
?>
We included a Retry-After header of 5 minutes, assuming that the site will probably be back up soon.
And that’s it, a couple of changes and now our sites speak proper HTTP even when disabled, great!