Have multiple configuration files for HAProxy

This post is an extract from an answer to a question from a mailing list or on stack overflow, I was so hurry to not loose it, that I copied-pasted it here, in case I lost the link.

It seems to be Michael Bibl from the Debian team:

http://permalink.gmane.org/gmane.comp.web.haproxy/17603

 

To recreate the same structure and functionality as the Apache2-style as we also wanted the easier management.

Below shows the directory structure and files we modified to make this happen.

Modified /etc/init.d/haproxy:

EXTRAOPTS=`for FILE in `find /etc/haproxy/sites-enabled -type l | sort -n`; do CONFIGS="$CONFIGS -f $FILE"; done; echo $CONFIGS`

Directory structure:

/etc/haproxy
├── errors
│ ├── 400.http
│ ├── 403.http
│ ├── 408.http
│ ├── 500.http
│ ├── 502.http
│ ├── 503.http
│ └── 504.http
├── haproxy.cfg
├── haproxy.cfg.bak
├── haproxy.cfg.bak-2014-03-21
├── sites-available
│ ├── site01.example.com
│ ├── site02.example.com
│ └── site03.exmaple.com
└── sites-enabled
├── site01.example.com -> ../sites-available/site01.example.com
├── site02.example.com -> ../sites-available/site02.example.com
└── site03.example.com -> ../sites-available/site03.example.com

Created haensite:

#!/bin/bash

if [[ $EUID -ne 0 ]]; then
echo "You must be a root user" 2>&1
exit 1
fi

if [ $# -lt 1 ]; then
echo "Invalid number of arguments"
exit 1
fi

echo "Enabling $1..."

cd /etc/haproxy/sites-enabled
ln -s ../sites-available/$1 ./

echo "To activate the new configuration, you need to run:"
echo " /etc/init.d/haproxy restart"

Created hadissite:

#!/bin/bash

if [[ $EUID -ne 0 ]]; then
echo "You must be a root user" 2>&1
exit 1
fi

if [ $# -lt 1 ]; then
echo "Invalid number of arguments"
exit 1
fi

echo "Disabling $1..."

rm -f /etc/haproxy/sites-enabled/$1

echo "To activate the new configuration, you need to run:"
echo " /etc/init.d/haproxy restart"

Leave a Reply

Your email address will not be published. Required fields are marked *