From 57f01366d7d21823ba4cf6570a56459db37c0b30 Mon Sep 17 00:00:00 2001 From: Juergen Graf Date: Tue, 4 Jul 2017 17:49:59 +0200 Subject: [PATCH 1/2] Add option to enable http health check on port 8080 --- jobs/haproxy/spec | 3 +++ jobs/haproxy/templates/haproxy.config.erb | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/jobs/haproxy/spec b/jobs/haproxy/spec index f25845b7..f2aabe9a 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`" + default: false ha_proxy.disable_http: description: "Disable port 80 traffic" default: false diff --git a/jobs/haproxy/templates/haproxy.config.erb b/jobs/haproxy/templates/haproxy.config.erb index 9a7bac79..196488c6 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 %> <% From b47458f47aff3fec094d3cfabade0d202e5ff0c8 Mon Sep 17 00:00:00 2001 From: Juergen Graf Date: Thu, 13 Jul 2017 11:25:33 +0200 Subject: [PATCH 2/2] Add optional health check http site for tcp backends --- jobs/haproxy/spec | 4 +++- jobs/haproxy/templates/haproxy.config.erb | 12 ++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/jobs/haproxy/spec b/jobs/haproxy/spec index f2aabe9a..39424bee 100644 --- a/jobs/haproxy/spec +++ b/jobs/haproxy/spec @@ -54,7 +54,7 @@ properties: 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`" + 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" @@ -192,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 196488c6..f5f4686c 100644 --- a/jobs/haproxy/templates/haproxy.config.erb +++ b/jobs/haproxy/templates/haproxy.config.erb @@ -360,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 -%> @@ -369,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 -%>