Skip to content

Instantly share code, notes, and snippets.

@schisamo
Created October 27, 2010 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schisamo/649100 to your computer and use it in GitHub Desktop.
Save schisamo/649100 to your computer and use it in GitHub Desktop.
#
# Cookbook Name:: haproxy
# Recipe:: default
#
# Copyright 2009, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package "haproxy" do
action :install
end
template "/etc/default/haproxy" do
source "haproxy-default.erb"
owner "root"
group "root"
mode 0644
end
service "haproxy" do
supports :restart => true, :status => true, :reload => true
action [:enable, :start]
end
pool_members = search(:node, "role:#{node[:haproxy][:pool_role]}") || []
template "/etc/haproxy/haproxy.cfg" do
source "haproxy.cfg.erb"
owner "root"
group "root"
mode 0644
variables :pool_members => pool_members
notifies :restart, resources(:service => "haproxy")
end
global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
#log loghost local0 info
maxconn 4096
#debug
#quiet
user haproxy
group haproxy
defaults
log global
mode http
option httplog
option dontlognull
retries 3
redispatch
maxconn 2000
contimeout 5000
clitimeout 50000
srvtimeout 50000
# Set up application listeners here.
listen application 0.0.0.0:80
balance roundrobin
<% @pool_members.each do |member| %>
<% server_ip = member.has_key?("ec2") ? member.ec2.public_ipv4 : member.ipaddress %>
server <%= member.hostname %> <%= server_ip %>:80 weight 1 maxconn 1 check
<% end %>
listen admin 0.0.0.0:22002
mode http
stats uri /
maintainer "YOUR_COMPANY_NAME"
maintainer_email "YOUR_EMAIL"
license "All rights reserved"
description "Installs/Configures knife_fu"
long_description IO.read(File.join(File.dirname(__FILE__), 'README.rdoc'))
version "0.0.1"
depends 'apache2'
#
# Cookbook Name:: knife_fu
# Recipe:: default
#
# Copyright 2010, Opscode, Inc..
#
# All rights reserved - Do Not Redistribute
#
include_recipe "apache2"
template "/var/www/index.html" do
source "index.html.erb"
owner "root"
group "root"
mode "0644"
end
<html>
<head>
<title>Welcome to <%= node[:hostname]%></title>
</head>
<body>
Knife rocks...you have reached:
<ul>
<li><b>FQDN</b>: <%= node[:fqdn] %></li>
<li><b>Public FQDN</b>: <%= node[:ec2][:public_hostname]%></li>
<li><b>IP Address</b>: <%= node[:ipaddress] %></li>
<li><b>Public IP</b>: <%= node[:ec2][:public_ipv4] %></li>
<li><b>Platform</b>: <%= node[:platform] %></li>
<li><b>Plaform Version</b>: <%= node[:platform_version] %></li>
<li><b>Run List</b>: <%= node.run_list %></li>
</ul>
</body>
</html>
name "lb"
description "load balancer"
override_attributes(
:haproxy => {:pool_role => "web"}
)
run_list(
"recipe[haproxy]"
)
name "web"
description "simple web app"
run_list(
"recipe[knife_fu]"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment