Skip to content

Commit 42c4d48

Browse files
author
Tiffany Low
committed
Restart haproxy if backend 'weights' setting is changed
1 parent 6d9b95a commit 42c4d48

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ This section is its own hash, which should contain the following keys:
273273
* `backend_order`: optional: how backends should be ordered in the `backend` stanza. (default is shuffling). Setting to `asc` means sorting backends in ascending alphabetical order before generating stanza. `desc` means descending alphabetical order. `no_shuffle` means no shuffling or sorting.
274274
* `shared_frontend`: optional: haproxy configuration directives for a shared http frontend (see below)
275275
* `cookie_value_method`: optional: default value is `name`, it defines the way your backends receive a cookie value in http mode. If equal to `hash`, synapse hashes backend names on cookie value assignation of your discovered backends, useful when you want to use haproxy cookie feature but you do not want that your end users receive a Set-Cookie with your server name and ip readable in clear.
276-
* `ignore_weights`: optional: stops haproxy backend 'weight' options being generated, even if the Nerve registrations contain this information. This will cause all backend servers to be treated equally by haproxy. This defaults to true so weights will *NOT* be used by default.
276+
* `ignore_weights`: optional: stops haproxy backend 'weight' options being generated, even if the Nerve registrations contain this information. This will cause all backend servers to be treated equally by haproxy. This defaults to true so weights will *NOT* be used by default.
277277

278278
<a name="haproxy"/>
279279
### Configuring HAProxy ###

lib/synapse/haproxy.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,11 @@ def generate_backend_stanza(watcher, config)
714714
log.info "synapse: restart required because haproxy_server_options changed for #{backend_name}"
715715
@restart_required = true
716716
end
717+
if (old_backend.fetch('weight', "") !=
718+
backend.fetch('weight', ""))
719+
log.info "synapse: restart required because weight changed for #{backend_name}"
720+
@restart_required = true
721+
end
717722
end
718723
backends[backend_name] = backend.merge('enabled' => true)
719724
end
@@ -749,9 +754,12 @@ def generate_backend_stanza(watcher, config)
749754
end
750755
b = "#{b} #{watcher.haproxy['server_options']}" if watcher.haproxy['server_options']
751756
if backend.has_key?('weight')
752-
# Check if server_options already contains weight, is so log a warning
753-
if watcher.haproxy['server_options'].include? 'weight'
754-
log.warn "synapse: weight is defined by server_options and by nerve"
757+
# Check if server_options/haproxy_server_options already contains weight, if so log a warning
758+
if watcher.haproxy.fetch('server_options', '').include? 'weight'
759+
log.warn "synapse: weight is defined in both server_options and nerve. nerve weight takes precedence"
760+
end
761+
if backend['haproxy_server_options'] and backend['haproxy_server_options'].include? 'weight'
762+
log.warn "synapse: weight is defined in both haproxy_server_options and nerve. nerve weight takes precedence"
755763
end
756764
weight = backend['weight'].to_i
757765
b = "#{b} weight #{weight}"

0 commit comments

Comments
 (0)