Skip to content

Commit 15e7709

Browse files
committed
Made balance configurable.
1 parent 83cff65 commit 15e7709

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

haproxy/attributes/default.rb

+2
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,5 @@ def random_haproxy_pw
4646

4747
default[:haproxy][:stats_password] = random_haproxy_pw
4848
default[:haproxy][:enable_stats] = false
49+
50+
default[:haproxy][:balance] = 'roundrobin'

haproxy/templates/default/haproxy.cfg.erb

+9-9
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ defaults
4040
listen application 0.0.0.0:80
4141
# configure a fake backend as long as there are no real ones
4242
# this way HAProxy will not fail on a config check
43-
balance source
43+
balance <%= node[:haproxy][:balance] %>
4444
server localhost 127.0.0.1:8080 weight 1 maxconn 5 check
4545
<% else -%>
4646

4747
<% if !node[:haproxy][:rails_backends].empty? -%>
4848
backend rails_app_servers
49-
balance source
49+
balance <%= node[:haproxy][:balance] %>
5050
option redispatch
5151
option forwardfor
5252
option httpchk <%= node[:haproxy][:health_check_method] %> <%= node[:haproxy][:health_check_url] %>
@@ -58,7 +58,7 @@ backend rails_app_servers
5858
<% if !node[:haproxy][:rails_backends].empty? -%>
5959
backend rails_app_servers_ssl
6060
mode tcp
61-
balance source
61+
balance <%= node[:haproxy][:balance] %>
6262
option redispatch
6363
option ssl-hello-chk
6464
<% node[:haproxy][:rails_backends].each do |backend| -%>
@@ -68,7 +68,7 @@ backend rails_app_servers_ssl
6868

6969
<% if !node[:haproxy][:php_backends].empty? -%>
7070
backend php_app_servers
71-
balance source
71+
balance <%= node[:haproxy][:balance] %>
7272
option redispatch
7373
option forwardfor
7474
option httpchk <%= node[:haproxy][:health_check_method] %> <%= node[:haproxy][:health_check_url] %>
@@ -80,7 +80,7 @@ backend php_app_servers
8080
<% if !node[:haproxy][:php_backends].empty? -%>
8181
backend php_app_servers_ssl
8282
mode tcp
83-
balance source
83+
balance <%= node[:haproxy][:balance] %>
8484
option redispatch
8585
option ssl-hello-chk
8686
<% node[:haproxy][:php_backends].each do |backend| -%>
@@ -90,7 +90,7 @@ backend php_app_servers_ssl
9090

9191
<% if !node[:haproxy][:nodejs_backends].empty? -%>
9292
backend nodejs_app_servers
93-
balance source
93+
balance <%= node[:haproxy][:balance] %>
9494
option redispatch
9595
option forwardfor
9696
option httpchk <%= node[:haproxy][:health_check_method] %> <%= node[:haproxy][:health_check_url] %>
@@ -102,7 +102,7 @@ backend nodejs_app_servers
102102
<% if !node[:haproxy][:nodejs_backends].empty? -%>
103103
backend nodejs_app_servers_ssl
104104
mode tcp
105-
balance source
105+
balance <%= node[:haproxy][:balance] %>
106106
option redispatch
107107
option ssl-hello-chk
108108
<% node[:haproxy][:nodejs_backends].each do |backend| -%>
@@ -112,7 +112,7 @@ backend nodejs_app_servers_ssl
112112

113113
<% if !node[:haproxy][:static_backends].empty? -%>
114114
backend static_servers
115-
balance source
115+
balance <%= node[:haproxy][:balance] %>
116116
option redispatch
117117
option forwardfor
118118
option httpchk GET <%= node[:haproxy][:health_check_url] %> # Nginx doesn't understand OPTIONS
@@ -124,7 +124,7 @@ backend static_servers
124124
<% if !node[:haproxy][:static_backends].empty? -%>
125125
backend static_servers_ssl
126126
mode tcp
127-
balance source
127+
balance <%= node[:haproxy][:balance] %>
128128
option redispatch
129129
option ssl-hello-chk
130130
<% node[:haproxy][:static_backends].each do |backend| -%>

0 commit comments

Comments
 (0)