From ff7da3b53a4f927678bd3f118990d3cf0c6a6fa5 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 | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/synapse/haproxy.rb b/lib/synapse/haproxy.rb index 063d86d9..786095e6 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,10 +748,13 @@ 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' + # 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 by server_options and by nerve" end + if backend['haproxy_server_options'] and backend['haproxy_server_options'].include? 'weight' + log.warn "synapse: weight is defined by haproxy_server_options and by nerve" + end weight = backend['weight'].to_i b = "#{b} weight #{weight}" end