diff --git a/jobs/haproxy/spec b/jobs/haproxy/spec index f25845b7..39424bee 100644 --- a/jobs/haproxy/spec +++ b/jobs/haproxy/spec @@ -53,6 +53,9 @@ properties: default: ~ ha_proxy.backend_ca_file: description: "Optional SSL CA certificate chain (PEM file) concatenated together for backend SSL servers, only used when one of the `backend_ssl` options is set to `verify`" + ha_proxy.enable_health_check_http: + description: "Optionally enable http health-check on `haproxy_ip:8080/health`. It shows `200 OK` if >0 backend servers are up." + default: false ha_proxy.disable_http: description: "Disable port 80 traffic" default: false @@ -189,6 +192,8 @@ properties: # Setting `verify` requires `ha_proxy.backend_ca_file` key to be set. backend_verifyhost: example.com # optional - hostname to verify in the x509 certificate subject for SSL-enabled backend servers # only used if backend_ssl: `verify` is set + health_check_http: 4444 # optional port number - if provided a heath check http site is created at `haproxy_ip:4444/health`. + # It shows `200 OK` if >0 backend servers are up. ha_proxy.tcp_link_port: description: "Port haproxy should listen on when using the tcp_backend link" ha_proxy.resolvers: diff --git a/jobs/haproxy/templates/haproxy.config.erb b/jobs/haproxy/templates/haproxy.config.erb index 9a7bac79..f5f4686c 100644 --- a/jobs/haproxy/templates/haproxy.config.erb +++ b/jobs/haproxy/templates/haproxy.config.erb @@ -72,6 +72,15 @@ listen stats_<%= proc %> <% end %> <% end %> +<% if p("ha_proxy.enable_health_check_http") %> +listen health_check_http_url + bind :8080 + mode http + monitor-uri /health + acl http-routers_down nbsrv(http-routers) eq 0 + monitor fail if http-routers_down +<% end %> + <%# HTTP Frontend %> <% @@ -351,7 +360,7 @@ if tcp_proxy["backend_port"] backend_port = tcp_proxy["backend_port"] end %> -<% tcp_proxy["backend_servers"].each_with_index do |ip, index| %> + <% tcp_proxy["backend_servers"].each_with_index do |ip, index| %> server node<%= index %> <%= ip %>:<%= backend_port %> <% if_p("ha_proxy.resolvers") do -%> resolvers default <% end -%> check inter 1000 <% if tcp_proxy["backend_ssl"] then -%> <% if tcp_proxy["backend_ssl"].downcase == "verify" then -%> @@ -360,6 +369,14 @@ end %> <% elsif tcp_proxy["backend_ssl"].downcase == "noverify" then -%> ssl verify none <% end -%> <% end -%> - <% end -%> + <% end -%> + <% if tcp_proxy["health_check_http"] then %> +listen health_check_http_tcp-<%= tcp_proxy["name"] %> + bind :<%= tcp_proxy["health_check_http"] %> + mode http + monitor-uri /health + acl tcp-<%= tcp_proxy["name"] %>-routers_down nbsrv(tcp-<%= tcp_proxy["name"] %>) eq 0 + monitor fail if tcp-<%= tcp_proxy["name"] %>-routers_down + <% end -%> <% end -%>