forked from rubber/rubber
/
haproxy-mongrel.conf
23 lines (21 loc) · 999 Bytes
/
haproxy-mongrel.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<%
@path = "/etc/haproxy/haproxy.cfg"
@additive = ["# start haproxy mongrel", "# end haproxy mongrel"]
%>
listen mongrel_proxy 0.0.0.0:<%= rubber_env.haproxy_listen_port %>
<%
# Since we do "fair" load balancing to the mongrels, we don't want to share mongrels
# between haproxy instances otherwise we still end up with requests getting queued behind
# slow ones.
app_hosts = rubber_instances.for_role('app').collect { |i| i.name }
haproxy_hosts = rubber_instances.for_role('haproxy').collect { |i| i.name }
ports = (rubber_env.mongrel_base_port.to_i ... rubber_env.mongrel_base_port.to_i + rubber_env.mongrel_count.to_i).to_a
host_count = haproxy_hosts.size
host_mod = haproxy_hosts.sort.index(rubber_env.host) rescue 0
ports = ports.find_all {|x| x % host_count == host_mod}
%>
<% app_hosts.each do |server| %>
<% ports.each do |port| %>
server <%= server %>_<%= port %> <%= server %>:<%= port %> maxconn 1 check
<% end %>
<% end %>