Last resort backend

Is it possible to define a backend that can be used by all other backend as its last resort.

Ie normal backends will have 2 servers defined, if both those servers are down or then uses the last resort backend.

I know there is the backup flag that can be set per server in the backend config, but that does mean defining it in every backend.

Cheers
Simon

You could use the following “trick”:

  • in your frontend I assume you have some ACL’s that are used to route the requests to various backends as such use_backend service_1 if route_1;
  • now there is a sample nbsrv ( http://cbonte.github.io/haproxy-dconv/1.8/configuration.html#7.3.2-nbsrv ) that returns the number of live servers;
  • you could create a special ACL for the case when no servers are available as acl service_1_down nbsrv(service_1) eq 0;
  • then you could insert a new routing rule in the frontent that uses the newly introduced ACL; (however you need to define one backend which contains the fallback server;)
  • (BTW, I always include a default_fallback rule in my frontends, and I always have such a fallback backend even if I have so live servers declared so I can handle such situations more easily;)

Thus tu summarize:

frontend main
    acl route_1 ...
    acl service_1_down nbsrv(service_1) eq 0
    use_backend fallback if route_1 service_1_down
    use_backend service_1 if route_1
    default_backend fallback

backend service_1
   ...

backend fallback
   ...
1 Like