Skip to content

Commit

Permalink
Restart haproxy if backend 'weights' setting is changed
Browse files Browse the repository at this point in the history
  • Loading branch information
Tiffany Low committed May 27, 2016
1 parent 6d9b95a commit 42c4d48
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ This section is its own hash, which should contain the following keys:
* `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.
* `shared_frontend`: optional: haproxy configuration directives for a shared http frontend (see below)
* `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.
* `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.
* `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.

<a name="haproxy"/>
### Configuring HAProxy ###
Expand Down
14 changes: 11 additions & 3 deletions lib/synapse/haproxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,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
Expand Down Expand Up @@ -749,9 +754,12 @@ def generate_backend_stanza(watcher, config)
end
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}"
Expand Down

0 comments on commit 42c4d48

Please sign in to comment.