1#!/bin/sh 2# 3# This script sets up the HAProxy load balancer initially, configured with 4# no working backend servers. Presumably in a real environment you would 5# do this sort of setup with a real configuration management system. For 6# this demo, however, this shell script will suffice. 7# 8set -e 9 10# Install HAProxy 11sudo apt-get update 12sudo apt-get install -y haproxy 13 14# Configure it in a jank way 15cat <<EOF >/tmp/haproxy.cfg 16global 17 daemon 18 maxconn 256 19 20defaults 21 mode http 22 timeout connect 5000ms 23 timeout client 50000ms 24 timeout server 50000ms 25 26listen stats 27 bind *:9999 28 mode http 29 stats enable 30 stats uri / 31 stats refresh 2s 32 33listen http-in 34 bind *:80 35 balance roundrobin 36 option http-server-close 37EOF 38sudo mv /tmp/haproxy.cfg /etc/haproxy/haproxy.cfg 39 40# Enable HAProxy 41cat <<EOF >/tmp/haproxy 42ENABLED=1 43EOF 44sudo mv /tmp/haproxy /etc/default/haproxy 45 46# Start it 47sudo /etc/init.d/haproxy start 48