Skip to content

Commit

Permalink
Balance java app servers with HAProxy.
Browse files Browse the repository at this point in the history
  • Loading branch information
githuesch committed Jun 18, 2014
1 parent 51b828a commit 3e3b92c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 2 additions & 0 deletions haproxy/attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
default[:haproxy][:maxcon_factor_php_app_ssl] = 10
default[:haproxy][:maxcon_factor_nodejs_app] = 10
default[:haproxy][:maxcon_factor_nodejs_app_ssl] = 10
default[:haproxy][:maxcon_factor_java_app] = 10
default[:haproxy][:maxcon_factor_java_app_ssl] = 10
default[:haproxy][:maxcon_factor_static] = 15
default[:haproxy][:maxcon_factor_static_ssl] = 15

Expand Down
28 changes: 27 additions & 1 deletion haproxy/templates/default/haproxy.cfg.erb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ defaults
<% end -%>

# Set up application listeners here.
<% if node[:haproxy][:rails_backends].blank? && node[:haproxy][:php_backends].blank? && node[:haproxy][:nodejs_backends].blank? && node[:haproxy][:static_backends].blank? -%>
<% if node[:haproxy][:rails_backends].blank? && node[:haproxy][:php_backends].blank? && node[:haproxy][:nodejs_backends].blank? && node[:haproxy][:static_backends].blank? && node[:haproxy][:java_backends].blank? -%>
listen application 0.0.0.0:80
# configure a fake backend as long as there are no real ones
# this way HAProxy will not fail on a config check
Expand Down Expand Up @@ -136,6 +136,28 @@ backend static_servers_ssl
<% end -%>
<% end -%>

<% if !node[:haproxy][:java_backends].empty? -%>
backend java_servers
balance <%= node[:haproxy][:balance] %>
option redispatch
option forwardfor
option httpchk <%= node[:haproxy][:health_check_method] %> <%= node[:haproxy][:health_check_url] %>
<% node[:haproxy][:java_backends].each do |backend| -%>
server <%= backend['name'] %> <%= backend['ip'] %>:80 weight <%= backend['backends'] || 10 %> maxconn <%= backend['backends'] * node[:haproxy][:maxcon_factor_java_app] %> check inter <%= node[:haproxy][:check_interval] %>
<% end -%>
<% end -%>

<% if !node[:haproxy][:java_backends].empty? -%>
backend java_servers_ssl
mode tcp
balance <%= node[:haproxy][:balance] %>
option redispatch
option ssl-hello-chk
<% node[:haproxy][:java_backends].each do |backend| -%>
server <%= backend['name'] %> <%= backend['ip'] %>:443 weight <%= backend['backends'] || 10 %> maxconn <%= backend['backends'] * node[:haproxy][:maxcon_factor_java_app_ssl] %> check inter <%= node[:haproxy][:check_interval] %>
<% end -%>
<% end -%>

frontend http-in
bind :80

Expand Down Expand Up @@ -236,6 +258,8 @@ frontend http-in
default_backend nodejs_app_servers
<% elsif !node[:haproxy][:static_backends].empty? -%>
default_backend static_servers
<% elsif !node[:haproxy][:java_backends].empty? -%>
default_backend java_servers
<% end -%>

frontend https-in
Expand Down Expand Up @@ -291,6 +315,8 @@ frontend https-in
default_backend nodejs_app_servers_ssl
<% elsif !node[:haproxy][:static_backends].empty? -%>
default_backend static_servers_ssl
<% elsif !node[:haproxy][:java_backends].empty? -%>
default_backend java_servers_ssl
<% end -%>

<% end -%>

0 comments on commit 3e3b92c

Please sign in to comment.