Can I healthcheck two endpoints for one service?

I have a scenario where I need to check that two different servers are up to consider service as up

If server A and server B is up - goto server B else goto server C

Is that doable?, if not - can I check server A as below;

If A is up go to server B
if A is down go server backup server C
(in this workaround scenario I will let server A check server B for me)

server B is in both scenarios the endpoint for the user, but ALSO depending on A status
server B is a blackbox so I can’t do anything there.

messy explaination - i hope somone understands it :slight_smile:

Hi Rickard
It is possible, but of course, if would be better to avoid such “hacky” requirements.
I don’t understand what you want to achieve.

Make sure you make a logical separation between servers (as in host running a webserver) and services (e.g. “mail.acme.org”, “www.acme.org”) in your mind, and have a clear understanding before planning on which services should be running on which servers.

From your description, it is not clear which service should run on which server.
Is it the same service running on all three servers?

You may want to use Named ACL’s to define services (as in HTTP “host” header) and backends that are running a service.
You can then combine the acl names to build your own custom complex “routing” rule.

I made the following demo config, just to illustrate what haproxy could do (not tested):

frontend SERVICE-WEB
  bind *:443 name *:443 ssl crt MYCERT
  mode http
  acl ishost_www.acme.org   hdr(host) -i www.acme.org
  acl ishost_mail.acme.org  hdr(host) -i mail.acme.org
  
  acl isavail_Backend_A   nbsrv(Backend_A) gt 0
  acl isavail_Backend_B   nbsrv(Backend_B) gt 0
  acl isavail_Backend_C   nbsrv(Backend_C) gt 0
  
  use_backend Backend_B   if ishost_www.acme.org  isavail_Backend_A    isavail_Backend_B
  use_backend Backend_C   if ishost_www.acme.org  ! isavail_Backend_A  isavail_Backend_B   isavail_Backend_C

  use_backend Backend_A   if ishost_mail.acme.org isavail_Backend_A

Keep in mind, Named ACL’s can also be used in backends.

However, it is always better use backends with multiple backend servers, and use check, backup and weight to determine which server will get the requests. Use cookie for session persistence if you need. This model is much more robust:

frontend SERVICE-WEB
  bind *:443 name *:443 ssl crt MYCERT
  mode http
  default Backend_www.acme.org
  
backend Backend_www.acme.org
  mode http
  cookie LB-www.acme.org insert indirect nocache secure httponly attr SameSite=strict
  option httpchk HEAD / HTTP/1.1\r\nHost:\ www.acme.org
  server server_A:443 1.2.10.11:443 ssl maxconn 500 weight 100 cookie srv1 check-ssl check
  server server_B:443 1.2.10.12:443 ssl maxconn 500 weight   1 cookie srv2 check-ssl check
  server server_C:443 1.2.10.13:443 ssl maxconn 500 weight 100 cookie srv3 check-ssl check backup

Hope this helps?
Toni

1 Like

@Toni - this looks like an excellent idea, ACL’s I backend, never thought they would superceed the initial server list and their status, I will give it a test !

Just confirming this worked fine !