Skip to content

Commit ba0143c

Browse files
author
Tiffany Low
committed
Restart haproxy if backend 'weights' setting is changed
1 parent c3bcd29 commit ba0143c

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

lib/synapse/haproxy.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,11 @@ def generate_backend_stanza(watcher, config)
716716
log.info "synapse: restart required because haproxy_server_options changed for #{backend_name}"
717717
@restart_required = true
718718
end
719+
if (old_backend.fetch('weight', "") !=
720+
backend.fetch('weight', ""))
721+
log.info "synapse: restart required because weight changed for #{backend_name}"
722+
@restart_required = true
723+
end
719724
end
720725
backends[backend_name] = backend.merge('enabled' => true)
721726
end
@@ -743,9 +748,12 @@ def generate_backend_stanza(watcher, config)
743748
b = "#{b} cookie #{backend_name}" unless config.include?('mode tcp')
744749
b = "#{b} #{watcher.haproxy['server_options']}" if watcher.haproxy['server_options']
745750
if backend.has_key?('weight')
746-
# Check if server_options already contains weight, is so log a warning
747-
if watcher.haproxy['server_options'].include? 'weight'
748-
log.warn "synapse: weight is defined by server_options and by nerve"
751+
# Check if server_options/haproxy_server_options already contains weight, if so log a warning
752+
if watcher.haproxy.fetch('server_options', '').include? 'weight'
753+
log.warn "synapse: weight is defined in both server_options and nerve. nerve weight takes precedence"
754+
end
755+
if backend['haproxy_server_options'] and backend['haproxy_server_options'].include? 'weight'
756+
log.warn "synapse: weight is defined in both haproxy_server_options and nerve. nerve weight takes precedence"
749757
end
750758
weight = backend['weight'].to_i
751759
b = "#{b} weight #{weight}"

0 commit comments

Comments
 (0)