Validate haproxy.cfg

Is there any way to validate the HAProxy haproxy.cfg file before restarting the HAProxy service? For example: There might be a small spelling/syntax error in a larger haproxy.cfg file. I searched through several forums, but was unable to find anything in relation to validating the haproxy.cfg files for syntax errors.

As of now, I use a trial and error basis on a developer machine before I upload the changes to a Production Server.

Thanks in Advance..


Solution 1:

The official HaProxy configuration file check was buried in the help sections.

/usr/local/sbin/haproxy --help

There are two ways to check the haproxy.cfg syntax is to use..

One way is the /usr/local/sbin/haproxy -c -V -f /etc/haproxy/haproxy.cfg which validates the file syntax. The -c switch in the command represents the Check, while the others denote "Verbose" & "file".

Another way is to sudo service haproxy configtest

I hope this helps anyone looking to check the syntax of the haproxy.cfg file before restarting the service.

Thanks & Regards

Shawn

Solution 2:

We are using this command sudo haproxy -f /etc/haproxy/haproxy.cfg -c