From ba0143cd86eae3f60b131f637a347bb8ff918b96 Mon Sep 17 00:00:00 2001 From: Tiffany Low Date: Mon, 21 Mar 2016 11:43:56 -0700 Subject: [PATCH] Restart haproxy if backend 'weights' setting is changed --- lib/synapse/haproxy.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/synapse/haproxy.rb b/lib/synapse/haproxy.rb index 063d86d9..7419369f 100644 --- a/lib/synapse/haproxy.rb +++ b/lib/synapse/haproxy.rb @@ -716,6 +716,11 @@ def generate_backend_stanza(watcher, config) log.info "synapse: restart required because haproxy_server_options changed for #{backend_name}" @restart_required = true end + if (old_backend.fetch('weight', "") != + backend.fetch('weight', "")) + log.info "synapse: restart required because weight changed for #{backend_name}" + @restart_required = true + end end backends[backend_name] = backend.merge('enabled' => true) end @@ -743,9 +748,12 @@ def generate_backend_stanza(watcher, config) b = "#{b} cookie #{backend_name}" unless config.include?('mode tcp') b = "#{b} #{watcher.haproxy['server_options']}" if watcher.haproxy['server_options'] if backend.has_key?('weight') - # Check if server_options already contains weight, is so log a warning - if watcher.haproxy['server_options'].include? 'weight' - log.warn "synapse: weight is defined by server_options and by nerve" + # Check if server_options/haproxy_server_options already contains weight, if so log a warning + if watcher.haproxy.fetch('server_options', '').include? 'weight' + log.warn "synapse: weight is defined in both server_options and nerve. nerve weight takes precedence" + end + if backend['haproxy_server_options'] and backend['haproxy_server_options'].include? 'weight' + log.warn "synapse: weight is defined in both haproxy_server_options and nerve. nerve weight takes precedence" end weight = backend['weight'].to_i b = "#{b} weight #{weight}"