Splitting monolithic HAProxy configuration into more manageable form

As soon as you have more than a few frontend, backend and listen directives in your HAProxy config thing get crowded in that single monolithic file. There are few possible solutions to this “problem”, like this python solution, or maybe using multiple config files and specifying them with -f when starting haproxy (http://comments.gmane.org/gmane.comp.web.haproxy/5888).

While there is nothing wrong with above mentioned solutions I think there is a better aproach where script would check if new configuration is valid before restarting HAProxy. Script below assumes you have colordiff, and etckeeper installed and configured. If you don’t you should think about using etckeeper, it can save you from trouble when you need to revert some changes in /etc directory.

First create /etc/haproxy/conf.d/ and split your haproxy.cfg in multiple files prefixed with numbers in order in which you would like them to be in final config. IE. in 00-global.cfg put your global options, and in 99-global.cfg put everything you want at the end of final HAProxy config file. If you need to disable one site simple rename it into 11-site1.cfg.disable, and run this script: https://gist.github.com/jlazic/e65f5bda141ffaed5640.


Edit: I have been using this script for a month now and it works great. If only there would be a way to dump running HAProxy configuration, and diff that config with one on the disk.

Josip Lazić

Josip Lazić wrote 21 posts

Post navigation


Leave a Reply

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

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>