Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into expose-admin-list…
Browse files Browse the repository at this point in the history
…ener-options

Conflicts:
	README.md
  • Loading branch information
sonnysideup committed May 30, 2014
2 parents c11dcaa + 76f2343 commit f94e5c7
Show file tree
Hide file tree
Showing 11 changed files with 193 additions and 4 deletions.
11 changes: 10 additions & 1 deletion .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,22 @@ platforms:
box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_ubuntu-12.04_provisionerless.box
run_list:
- recipe[apt]

provisioner:
attributes:
haproxy:
test:
netcat_package: netcat
- name: ubuntu-10.04
driver_config:
box: opscode-ubuntu-10.04
box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_ubuntu-10.04_provisionerless.box
run_list:
- recipe[apt]
provisioner:
attributes:
haproxy:
test:
netcat_package: netcat

suites:
- name: default
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ Attributes
- `node['haproxy']['admin']['address_bind']` - sets the address to bind the administrative interface on, 127.0.0.1 by default
- `node['haproxy']['admin']['port']` - sets the port for the administrative interface, 22002 by default
- `node['haproxy']['admin']['options']` - sets extras config parameters on the administrative interface, 'stats uri /' by default
- `node['haproxy']['enable_stats_socket']` - controls haproxy socket creation, false by default
- `node['haproxy']['stats_socket_path']` - location of haproxy socket, "/var/run/haproxy.sock" by default
- `node['haproxy']['stats_socket_user']` - user for haproxy socket, default is node['haproxy']['user']
- `node['haproxy']['stats_socket_group']` - group for haproxy socket, default is node['haproxy']['group']
- `node['haproxy']['pid_file']` - the PID file of the haproxy process, used in the tuning recipe.
- `node['haproxy']['defaults_options']` - an array of options to use for the config file's `defaults` stanza, default is ["httplog", "dontlognull", "redispatch"]
- `node['haproxy']['defaults_timeouts']['connect']` - connect timeout in defaults stanza
Expand All @@ -71,6 +75,7 @@ Attributes
- `node['haproxy']['source']['target_cpu']` - the target cpu used to `make` haproxy
- `node['haproxy']['source']['target_arch']` - the target arch used to `make` haproxy
- `node['haproxy']['source']['use_pcre']` - whether to build with libpcre support
- `node['haproxy']['package']['version'] - the version of haproxy to install, default latest

Recipes
-------
Expand Down
3 changes: 3 additions & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
default['haproxy']['group'] = "haproxy"

default['haproxy']['enable_default_http'] = true
default['haproxy']['mode'] = "http"
default['haproxy']['incoming_address'] = "0.0.0.0"
default['haproxy']['incoming_port'] = 80
default['haproxy']['members'] = [{
Expand Down Expand Up @@ -80,6 +81,8 @@
default['haproxy']['source']['use_openssl'] = false
default['haproxy']['source']['use_zlib'] = false

default['haproxy']['package']['version'] = nil

default['haproxy']['listeners'] = {
'listen' => {},
'frontend' => {},
Expand Down
5 changes: 5 additions & 0 deletions metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,8 @@
:display_name => "HAProxy source use PCRE",
:description => "Whether to build with libpcre support.",
:required => "optional"

attribute "haproxy/package/version",
:display_name => "HAProxy package version",
:description => "The version of haproxy to install.",
:required => "optional"
4 changes: 3 additions & 1 deletion recipes/install_package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
# limitations under the License.
#

package "haproxy"
package "haproxy" do
version node['haproxy']['package']['version'] if node['haproxy']['package']['version']
end

directory node['haproxy']['conf_dir']

Expand Down
28 changes: 28 additions & 0 deletions spec/recipes/lb_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'spec_helper'

haproxyConfigFile = '/etc/haproxy/haproxy.cfg'

describe 'haproxy::install_package' do
let(:chef_run) { ChefSpec::Runner.new().converge(described_recipe) }

it 'Installs the haproxy package' do
expect(chef_run).to install_package 'haproxy'
end

givenVersion = '1.2.3.4'

# re-converge
let(:chef_run) do
ChefSpec::Runner.new do |node|
node.set['haproxy']['package']['version'] = givenVersion
end.converge(described_recipe)
end

it 'Installs the haproxy package at a given version' do
expect(chef_run).to install_package('haproxy').with_version(givenVersion)
end

end



25 changes: 25 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Added by ChefSpec
require 'chefspec'

# Uncomment to use ChefSpec's Berkshelf extension
require 'chefspec/berkshelf'

RSpec.configure do |config|
# Specify the path for Chef Solo to find cookbooks
# config.cookbook_path = '/var/cookbooks'

# Specify the path for Chef Solo to find roles
# config.role_path = '/var/roles'

# Specify the Chef log_level (default: :warn)
# config.log_level = :debug

# Specify the path to a local JSON file with Ohai data
# config.path = 'ohai.json'

# Specify the operating platform to mock Ohai data from
# config.platform = 'ubuntu'

# Specify the operating version to mock Ohai data from
# config.version = '12.04'
end
File renamed without changes.
2 changes: 1 addition & 1 deletion templates/default/haproxy.cfg.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ global

defaults
log global
mode http
mode <%= node['haproxy']['mode'] %>
retries 3
<% @defaults_timeouts.sort.map do | value, time | -%>
timeout <%= value %> <%= time %>
Expand Down
112 changes: 112 additions & 0 deletions templates/rhel/haproxy-init.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#!/bin/sh
#
# haproxy
#
# chkconfig: - 85 15
# description: HAProxy is a free, very fast and reliable solution \
# offering high availability, load balancing, and \
# proxying for TCP and HTTP-based applications
# processname: haproxy
# config: <%= @conf_dir %>/haproxy.cfg
# pidfile: /var/run/haproxy.pid

# Written by Chef on <%= @hostname %>

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

config="<%= @conf_dir %>/haproxy.cfg"
exec="<%= @prefix %>/sbin/haproxy"
prog=$(basename $exec)

[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog

lockfile=/var/lock/subsys/haproxy

check() {
$exec -c -V -f $config
}

start() {
$exec -c -q -f $config
if [ $? -ne 0 ]; then
echo "Errors in configuration file, check with $prog check."
return 1
fi

echo -n $"Starting $prog: "
# start it up here, usually something like "daemon $exec"
daemon $exec -D -f $config -p /var/run/$prog.pid
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}

stop() {
echo -n $"Stopping $prog: "
# stop it here, often "killproc $prog"
killproc $prog
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}

restart() {
$exec -c -q -f $config
if [ $? -ne 0 ]; then
echo "Errors in configuration file, check with $prog check."
return 1
fi
stop
start
}

reload() {
$exec -c -q -f $config
if [ $? -ne 0 ]; then
echo "Errors in configuration file, check with $prog check."
return 1
fi
echo -n $"Reloading $prog: "
$exec -D -f $config -p /var/run/$prog.pid -sf $(cat /var/run/$prog.pid)
retval=$?
echo
return $retval
}

force_reload() {
restart
}

fdr_status() {
status $prog
}

case "$1" in
start|stop|restart|reload)
$1
;;
force-reload)
force_reload
;;
check)
check
;;
status)
fdr_status
;;
condrestart|try-restart)
[ ! -f $lockfile ] || restart
;;
*)
echo $"Usage: $0 {start|stop|status|restart|try-restart|reload|force-reload}"
exit 2
esac
2 changes: 1 addition & 1 deletion test/integration/lwrp/bats/nc.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ setup() {


teardown(){
pkill -9 nc
pkill -9 nc || true
}


Expand Down

0 comments on commit f94e5c7

Please sign in to comment.