Skip to content

Commit

Permalink
Merge pull request #429 from engineyard/FB1604
Browse files Browse the repository at this point in the history
Replace 127.0.0.1 with private hostname on solo instances
  • Loading branch information
Dimitris authored Nov 26, 2019
2 parents 7469fbe + 50413de commit e616700
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
8 changes: 7 additions & 1 deletion cookbooks/haproxy/recipes/configure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
end

use_http2 = node['haproxy'] && node['haproxy']['http2']


solo = node.engineyard.environment.instances.select{ |i| 'solo' == i.role }.map{ |i| i.private_hostname}.first


managed_template "/etc/haproxy.cfg" do
owner 'root'
group 'root'
Expand All @@ -67,7 +72,8 @@
:httpchk_host => haproxy_httpchk_host,
:httpchk_path => haproxy_httpchk_path,
:http2 => use_http2,
:certificates => Dir['/etc/nginx/ssl/*.pem'].reject {|filename| filename =~ /dhparam/}}
:certificates => Dir['/etc/nginx/ssl/*.pem'].reject {|filename| filename =~ /dhparam/},
:solo => solo}
})

# We need to reload to activate any changes to the config
Expand Down
13 changes: 6 additions & 7 deletions cookbooks/haproxy/templates/default/haproxy.cfg.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ global
maxconn 65535

# Logging to syslog facility local0
# log 127.0.0.1 local0
# log <%= @solo %> local0

# Distribute the health checks with a bit of randomness
spread-checks 5
Expand Down Expand Up @@ -141,7 +141,7 @@ listen cluster
<% end %>
<% else %>
# It must be a solo.
server solo 127.0.0.1:8081 check inter 5000 fastinter 1000 fall 1 weight 50
server solo <%= @solo %>:8081 check inter 5000 fastinter 1000 fall 1 weight 50
<% end %>
<% end %>
Expand All @@ -163,14 +163,14 @@ listen cluster
<% end -%>

backend nodes-http

<% if @backends.any? %>
<% @backends.each_with_index do |instance, i| %>
server app-<%= i %> <%= instance['private_hostname'] %>:8089 check inter 5000 fastinter 1000 fall 1 weight <%= (instance['role'] == 'app_master') ? @app_master_weight : 50 %> # <%= instance['id'] %>
<% end %>
<% else %>
# It must be a solo.
server solo 127.0.0.1:8089 check inter 5000 fastinter 1000 fall 1 weight 50
server solo <%= @solo %>:8089 check inter 5000 fastinter 1000 fall 1 weight 50
<% end %>

backend nodes-http2
Expand All @@ -182,9 +182,8 @@ listen cluster
<% end %>
<% else %>
# It must be a solo.
server solo 127.0.0.1:8081 check inter 5000 fastinter 1000 fall 1 weight 50 send-proxy
server solo <%= @solo %>:8081 check inter 5000 fastinter 1000 fall 1 weight 50 send-proxy
<% end %>
<% else %>
<% if @certificates.count > 0 %>
Expand All @@ -205,7 +204,7 @@ listen clusterssl
<% end %>
<% else %>
# It must be a solo.
server solo 127.0.0.1:8081 check inter 5000 fastinter 1000 fall 1 weight 50
server solo <%= @solo %>:8081 check inter 5000 fastinter 1000 fall 1 weight 50
<% end %>
<% else %>
Expand Down

0 comments on commit e616700

Please sign in to comment.