Hi, this is not a help request per se, but I don’t know where to send this.
This is about saving the servers state when reloading/restarting HAproxy.
In the community documentation I don’t find any page that explains what to do with it, only a reference manual of directives.
However in the HAPEE documentation there is an article about that : show servers state | HAProxy Runtime API
Unless I misunderstand (sorry if this is the case) this page might have a few mistakes or issues.
- sudo in systemd unit
The systemd override snippet that is present in the doc uses “sudo” for “socat”.
I think this is useless in most cases (systemd runs as root) and an issue when sudo is not installed on the server.
- override doesn’t override
When writting “ExecReload” like this, the directives already present in the systemd unit are complemented and not overidden.The issue is that HAProxy is reloaded a first time without a state file available, then the state file s generated (with the wrong content) then HAProxy is reloaded again with the wrong states.
To remove what has been defined before (in the stock systemd unit), you must write like this :
ExecReload=
ExecReload=command1
ExecReload=command2
- Save states on stop and restart (and reboot)
When properly restarting HAProxy (which is a stop then start) or rebooting the server, the states are not saved and reused. We can add the “save” on “ExecStop”.
Also, removing the state file after start is probably a good idea to avoid confusion.
Here is the full systemd override for the community edition of HAProxy :
[Service]
# Remove state file after start (to avoid confusion)
ExecStartPost=-/bin/sh -c 'rm -f /var/lib/haproxy/state'
# Store state file before stopping
ExecStop=-/bin/sh -c 'echo "show servers state" | socat stdio unix-connect:/run/haproxy/admin.sock > /var/lib/haproxy/state'
# Store state file before reloading
ExecReload=
ExecReload=/usr/sbin/haproxy -Ws -f $CONFIG -c -q $EXTRAOPTS
ExecReload=/bin/sh -c 'echo "show servers state" | socat stdio unix-connect:/run/haproxy/admin.sock > /var/lib/haproxy/state'
ExecReload=/bin/kill -USR2 $MAINPID