Skip to content
This repository has been archived by the owner on Mar 7, 2020. It is now read-only.

Commit

Permalink
Added haproxy
Browse files Browse the repository at this point in the history
  • Loading branch information
mbailey committed Aug 25, 2009
1 parent 8c8bbb9 commit 3ca5169
Show file tree
Hide file tree
Showing 5 changed files with 266 additions and 112 deletions.
208 changes: 103 additions & 105 deletions lib/deprec/recipes/haproxy.rb
Original file line number Diff line number Diff line change
@@ -1,105 +1,103 @@
# # Copyright 2006-2009 by Mike Bailey. All rights reserved.
# Capistrano::Configuration.instance(:must_exist).load do
# namespace :deprec do
# namespace :haproxy do
#
# SRC_PACKAGES[:haproxy] = {
# :md5sum => "e37046e0cb2f407d92c41d7731d1dd10 haproxy-1.3.20.tar.gz",
# :url => "http://haproxy.1wt.eu/download/1.3/src/haproxy-1.3.20.tar.gz"
# }
#
# desc "Install haproxy"
# task :install do
# install_deps
# deprec2.download_src(SRC_PACKAGES[:haproxy], src_dir)
# deprec2.install_from_src(SRC_PACKAGES[:haproxy], src_dir)
# end
#
# task :install_deps do
# apt.install( {:base => %w(build-essential)}, :stable )
# end
#
# SYSTEM_CONFIG_FILES[:haproxy] = [
#
# # {:template => "example.conf.erb",
# # :path => '/etc/example/example.conf',
# # :mode => 0755,
# # :owner => 'root:root'}
#
# ]
#
# PROJECT_CONFIG_FILES[:haproxy] = [
#
# # {:template => "example.conf.erb",
# # :path => 'conf/example.conf',
# # :mode => 0755,
# # :owner => 'root:root'}
# ]
#
#
# desc "Generate configuration file(s) for XXX from template(s)"
# task :config_gen do
# config_gen_system
# config_gen_project
# end
#
# task :config_gen_system do
# SYSTEM_CONFIG_FILES[:haproxy].each do |file|
# deprec2.render_template(:haproxy, file)
# end
# end
#
# task :config_gen_project do
# PROJECT_CONFIG_FILES[:haproxy].each do |file|
# deprec2.render_template(:haproxy, file)
# end
# end
#
# desc 'Deploy configuration files(s) for XXX'
# task :config, :roles => :web do
# config_system
# config_project
# end
#
# task :config_system, :roles => :web do
# deprec2.push_configs(:haproxy, SYSTEM_CONFIG_FILES[:haproxy])
# end
#
# task :config_project, :roles => :web do
# deprec2.push_configs(:haproxy, PROJECT_CONFIG_FILES[:haproxy])
# end
#
#
# task :start, :roles => :web do
# run "#{sudo} /etc/init.d/haproxy start"
# end
#
# task :stop, :roles => :web do
# run "#{sudo} /etc/init.d/haproxy stop"
# end
#
# task :restart, :roles => :web do
# run "#{sudo} /etc/init.d/haproxy restart"
# end
#
# task :reload, :roles => :web do
# run "#{sudo} /etc/init.d/haproxy reload"
# end
#
# task :activate, :roles => :web do
# run "#{sudo} update-rc.d haproxy defaults"
# end
#
# task :deactivate, :roles => :web do
# run "#{sudo} update-rc.d -f haproxy remove"
# end
#
# task :backup, :roles => :web do
# end
#
# task :restore, :roles => :web do
# end
#
# end
# end
# end
# Copyright 2006-2009 by Mike Bailey. All rights reserved.
Capistrano::Configuration.instance(:must_exist).load do
namespace :deprec do
namespace :haproxy do

SRC_PACKAGES[:haproxy] = {
:md5sum => "e37046e0cb2f407d92c41d7731d1dd10 haproxy-1.3.20.tar.gz",
:url => "http://haproxy.1wt.eu/download/1.3/src/haproxy-1.3.20.tar.gz"
}

desc "Install haproxy"
task :install do
install_deps
deprec2.download_src(SRC_PACKAGES[:haproxy], src_dir)
deprec2.install_from_src(SRC_PACKAGES[:haproxy], src_dir)
end

task :install_deps do
apt.install( {:base => %w(build-essential)}, :stable )
end

SYSTEM_CONFIG_FILES[:haproxy] = [

{:template => "haproxy.cfg.erb",
:path => '/etc/haproxy.cfg',
:mode => 0644,
:owner => 'root:root'},

{:template => "haproxy-init.d",
:path => '/etc/init.d/haproxy',
:mode => 0755,
:owner => 'root:root'}

]

PROJECT_CONFIG_FILES[:haproxy] = [

# {:template => "example.conf.erb",
# :path => 'conf/example.conf',
# :mode => 0755,
# :owner => 'root:root'}
]

desc "Generate configuration files for haproxy from template(s)"
task :config_gen do
config_gen_system
config_gen_project
end

task :config_gen_system do
SYSTEM_CONFIG_FILES[:haproxy].each do |file|
deprec2.render_template(:haproxy, file)
end
end

task :config_gen_project do
PROJECT_CONFIG_FILES[:haproxy].each do |file|
deprec2.render_template(:haproxy, file)
end
end

desc 'Deploy configuration filess for haproxy'
task :config, :roles => :haproxy do
config_system
config_project
end

task :config_system, :roles => :haproxy do
deprec2.push_configs(:haproxy, SYSTEM_CONFIG_FILES[:haproxy])
end

task :config_project, :roles => :haproxy do
deprec2.push_configs(:haproxy, PROJECT_CONFIG_FILES[:haproxy])
end


task :start, :roles => :haproxy do
run "#{sudo} /etc/init.d/haproxy start"
end

task :stop, :roles => :haproxy do
run "#{sudo} /etc/init.d/haproxy stop"
end

task :restart, :roles => :haproxy do
run "#{sudo} /etc/init.d/haproxy restart"
end

task :reload, :roles => :haproxy do
run "#{sudo} /etc/init.d/haproxy reload"
end

task :activate, :roles => :haproxy do
run "#{sudo} update-rc.d haproxy defaults"
end

task :deactivate, :roles => :haproxy do
run "#{sudo} update-rc.d -f haproxy remove"
end

end
end
end
2 changes: 1 addition & 1 deletion lib/deprec/recipes_minus_rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
require "#{File.dirname(__FILE__)}/recipes/collectd"
require "#{File.dirname(__FILE__)}/recipes/syslog"
require "#{File.dirname(__FILE__)}/recipes/heartbeat"
# require "#{File.dirname(__FILE__)}/recipes/haproxy"
require "#{File.dirname(__FILE__)}/recipes/haproxy"

require "#{File.dirname(__FILE__)}/recipes/ubuntu"
require "#{File.dirname(__FILE__)}/recipes/lvm"
Expand Down
119 changes: 119 additions & 0 deletions lib/deprec/templates/haproxy/haproxy-init.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#!/bin/sh
### BEGIN INIT INFO
# Provides: haproxy
# Required-Start: $local_fs $network
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: fast and reliable load balancing reverse proxy
# Description: This file should be used to start and stop haproxy.
### END INIT INFO

# Author: Arnaud Cornet <acornet@debian.org>

PATH=/sbin:/usr/sbin:/bin:/usr/bin
PIDFILE=/var/run/haproxy.pid
HAPROXY=/usr/local/sbin/haproxy
CONFIG=/etc/haproxy.cfg
EXTRAOPTS=
ENABLED=1

test -x $HAPROXY || exit 0
test -f "$CONFIG" || exit 0

if [ -e /etc/default/haproxy ]; then
. /etc/default/haproxy
fi

test "$ENABLED" != "0" || exit 0

[ -f /etc/default/rcS ] && . /etc/default/rcS
. /lib/lsb/init-functions


haproxy_start()
{
start-stop-daemon --start --pidfile "$PIDFILE" \
--exec $HAPROXY -- -f "$CONFIG" -D -p "$PIDFILE" \
$EXTRAOPTS || return 2
return 0
}

haproxy_stop()
{
start-stop-daemon --stop --user root --pidfile "$PIDFILE" \
|| return 2
return 0
}

haproxy_reload()
{
$HAPROXY -f "$CONFIG" -p $PIDFILE -D $EXTRAOPTS -st $(<$PIDFILE) \
|| return 2
return 0
}

case "$1" in
start)
log_daemon_msg "Starting haproxy" "haproxy"
haproxy_start
case "$?" in
0)
log_end_msg 0
;;
1)
log_end_msg 1
echo "pid file '$PIDFILE' found, haproxy not started."
;;
2)
log_end_msg 1
;;
esac
;;
stop)
log_daemon_msg "Stopping haproxy" "haproxy"
haproxy_stop
case "$?" in
0|1)
log_end_msg 0
;;
2)
log_end_msg 1
;;
esac
;;
reload|force-reload)
log_daemon_msg "Reloading haproxy" "haproxy"
haproxy_reload
case "$?" in
0|1)
log_end_msg 0
;;
2)
log_end_msg 1
;;
esac
;;
restart)
log_daemon_msg "Restarting haproxy" "haproxy"
haproxy_stop
haproxy_start
case "$?" in
0)
log_end_msg 0
;;
1)
log_end_msg 1
;;
2)
log_end_msg 1
;;
esac
;;
*)
echo "Usage: /etc/init.d/haproxy {start|stop|reload|restart}"
exit 3
;;
esac

:
42 changes: 42 additions & 0 deletions lib/deprec/templates/haproxy/haproxy.cfg.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# /etc/haproxy.cfg
#
# Reload gracelly with:
#
# haproxy -f /etc/haproxy.conf -sf `cat /var/run/haproxy.pid`
#
global
log /var/log/haproxy.log daemon info
maxconn 4096
pidfile /var/run/haproxy.pid
daemon

defaults
option forwardfor
stats enable
stats auth myuser:mypass
balance roundrobin
option httpclose
mode http
retries 3
option redispatch
maxconn 2000
contimeout 5000
clitimeout 50000
srvtimeout 50000

frontend dell *:80
acl host_xenium hdr_beg(host) -i xenium.example.com
acl host_xenium hdr_beg(host) -i x.example.com

acl host_app1 hdr_beg(host) -i intrepica.com
acl host_app1 hdr_beg(host) -i www.intrepica.com

use_backend localhost if host_xenium
use_backend app1 if host_app1

backend localhost
server LOCALHOST 127.0.0.1:81

backend app1
server APP1 192.168.0.179:80

Loading

0 comments on commit 3ca5169

Please sign in to comment.