How to make reloads safe in case of invalid config

  • I use default systemd-reloads
    ExecReload=/usr/sbin/haproxy -f $CONFIG -c -q
    ExecReload=/bin/kill -USR2 $MAINPID

  • Haproxy’s management manual says:

First, the service script (/etc/init.d/haproxy or equivalent) will verify that
the configuration file parses correctly using “haproxy -c”. After that it will
try to start haproxy with this configuration file, using “-st” or “-sf”.

However if I try to reload invalid config - all old process die immediately.

Of cause it is easy to solve problem by using “haproxy -c -f /etc/haproxy/haproxy.cfg && service haproxy reload”. But it is not correct way with double validation.

Is there any better solution for this case?

The systemd unit haproxy ships with will handle this.

Use the correct unit file haproxy ships with and the proper systemd commands to reload haproxy. If it does not work, elaborate what you are doing exactly, with which unit file and what happens exactly.