Fail Whale

Gabriel Filion gabster at lelutin.ca
Sat Nov 16 22:26:12 CET 2013


On 15/11/13 04:29 PM, James Pearson wrote:
> Excerpts from maillists0's message of 2013-11-15 12:52:31 -0800:
>> In some load balancers (haproxy, for example) you can create a backend that
>> only gets hit if all the other backends are down. A common enough setup is
>> to have a local apache serve a polite "oops" page on an alternate port on
>> the loopback. Is there some clever way to do this with Varnish? I've read
>> to docs and googled but can't find anything like this. If this is possible,
>> a doc to the right link would be awesome.
> 
> If all you want to do is serve a static page, you can do that in vcl_error.  We
> read in an external HTML file (that's also used for other things) using
> std.fileread[0].  Here's the entire thing[1]; perhaps it will be useful.

hmm this is nice. we've been using static html in the vcl up to now, but
we also deploy the html as a file for the local lighttpd instance so
that we can point arbitrary domains to it for maintenance. with your
suggestion, we can maintain only one copy of the html, and then use
puppet (for example) to trigger a reload when the contents change.

> [0]: http://comments.gmane.org/gmane.comp.web.varnish.misc/8099
> [1]: http://dpaste.com/hold/1465288/

since the paste in [1] above is set to expire in 30 days, it means that
ppl who stumble upon this thread in more than one month will not see the
example.

the paste is relatively small, so for posterity and future users' sake,
here's a copy of it:

/**
 * Called when we hit an error, either explicitly or implicitly due to
backend
 * or internal errors.
 *
 * The vcl_error subroutine may terminate by calling return with one of the
 * following keywords:
 *
 * deliver
 *    Deliver the error object to the client.
 * restart
 *    Restart the transaction. Increases the restart counter. If the
number of
 *    restarts is higher than max_restarts varnish emits a guru meditation
 *    error.
 */
sub vcl_error {
   # Allow the use of the error directive to do redirects in VCL.
   if (obj.status == 301 || obj.status == 302) {
      set obj.http.Location = obj.response;
      return (deliver);
   }

   set obj.http.Content-Type = "text/html; charset=utf-8";
   set obj.http.Retry-After = "5";
   # This file appears to only be read on a Varnish restart, or reload
if the
   # VCL changes.
   set obj.http.errorHTML = std.fileread("/path/to/down.html");

   # Custom error message?
   if (req.http.X-Error-Message) {
      set obj.http.errorHTML = regsub(
         obj.http.errorHTML,
         "We're down for scheduled maintenance\.",
         req.http.X-Error-Message);
   }

   synthetic obj.http.errorHTML;
   unset obj.http.errorHTML;

   return (deliver);
}

-- 
Gabriel Filion

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 291 bytes
Desc: OpenPGP digital signature
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20131116/134771a0/attachment.pgp>


More information about the varnish-misc mailing list