{"id":421,"date":"2015-02-01T16:25:38","date_gmt":"2015-02-01T15:25:38","guid":{"rendered":"http:\/\/lazic.info\/josip\/?p=421"},"modified":"2016-05-05T15:38:14","modified_gmt":"2016-05-05T14:38:14","slug":"splitting-haproxy-config","status":"publish","type":"post","link":"https:\/\/lazic.info\/josip\/post\/splitting-haproxy-config\/","title":{"rendered":"Splitting monolithic HAProxy configuration into more manageable form"},"content":{"rendered":"<p>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 &#8220;problem&#8221;, like this <a href=\"https:\/\/github.com\/finnlabs\/haproxy\" title=\"\" target=\"\">python solution<\/a>, or maybe using multiple config files and specifying them with -f when starting haproxy (<a href=\"http:\/\/comments.gmane.org\/gmane.comp.web.haproxy\/5888\" title=\"\" target=\"\">http:\/\/comments.gmane.org\/gmane.comp.web.haproxy\/5888<\/a>).<\/p>\n<p>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  <a href=\"http:\/\/etckeeper.branchable.com\/\" title=\"\" target=\"\">etckeeper<\/a> installed and configured. If you don&#8217;t you should think about using etckeeper, it can save you from trouble when you need to revert some changes in \/etc directory.<br \/>\n<!--more--><\/p>\n<p>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 <em>00-global.cfg<\/em> put your global options, and in <em>99-global.cfg<\/em> 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: <a href=\"https:\/\/gist.github.com\/jlazic\/e65f5bda141ffaed5640\" title=\"\" target=\"\">https:\/\/gist.github.com\/jlazic\/e65f5bda141ffaed5640<\/a>.<\/p>\n<div class=\"oembed-gist\"><script src=\"https:\/\/gist.github.com\/jlazic\/e65f5bda141ffaed5640.js\"><\/script><noscript>View the code on <a href=\"https:\/\/gist.github.com\/jlazic\/e65f5bda141ffaed5640\">Gist<\/a>.<\/noscript><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/lazic.info\/josip\/wp-content\/uploads\/2015\/02\/haconfig-run.png\" alt=\"haconfig-run\" width=\"918\" height=\"336\" class=\"aligncenter size-full wp-image-448\" srcset=\"https:\/\/lazic.info\/josip\/wp-content\/uploads\/2015\/02\/haconfig-run.png 918w, https:\/\/lazic.info\/josip\/wp-content\/uploads\/2015\/02\/haconfig-run-300x110.png 300w, https:\/\/lazic.info\/josip\/wp-content\/uploads\/2015\/02\/haconfig-run-800x293.png 800w\" sizes=\"auto, (max-width: 918px) 100vw, 918px\" \/><\/p>\n<p>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.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &#8220;problem&#8221;, 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 [&hellip;]<\/p>\n<div class=\"clearfix text-center more-button\"><a href=\"https:\/\/lazic.info\/josip\/post\/splitting-haproxy-config\/\" class=\"btn btn-success\">Continue reading<\/a><\/div>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[12],"class_list":["post-421","post","type-post","status-publish","format-standard","hentry","category-linux","tag-haproxy"],"_links":{"self":[{"href":"https:\/\/lazic.info\/josip\/wp-json\/wp\/v2\/posts\/421","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lazic.info\/josip\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lazic.info\/josip\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lazic.info\/josip\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lazic.info\/josip\/wp-json\/wp\/v2\/comments?post=421"}],"version-history":[{"count":0,"href":"https:\/\/lazic.info\/josip\/wp-json\/wp\/v2\/posts\/421\/revisions"}],"wp:attachment":[{"href":"https:\/\/lazic.info\/josip\/wp-json\/wp\/v2\/media?parent=421"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lazic.info\/josip\/wp-json\/wp\/v2\/categories?post=421"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lazic.info\/josip\/wp-json\/wp\/v2\/tags?post=421"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}