Documentation issues regarding servers state

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.

  1. 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.

  1. 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
  1. 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

HAPEE documentation is not handled of course by the OSS project, although some parts of the HAPEE docs can of course apply to OSS haproxy.

Tagging some haproxy folks perhaps they can help @capflam @valentine_r

I don’t think there is anything specific to HAPEE in this part of the documentation. But let’s look at it in details.

  1. Indeed the sudo does not seem useful there.
  2. You should not forgot to use systemctl edit --full which allows to completely override the file, which is stated in the documentation
  3. Having a clean state when starting or restarting is a good idea indeed, that could be a good idea to rm at startup! However I’m not so convinced with loading the stats on start or restart, most people would want to do a restart to be in a clean state, or they would do a reload instead. But I presume that depend on your usage.

Note that if you want to report problems in the HAPEE documentation, there is a feedback button on the page !

Thanks,

Hi, thanks for your time to answer.

systemctl edit --full is a good and reliable way to completely overwrite a service unit, but I find it too broad, and the full unit covers much more than what is documented in the article.
I’d prefer the specific and limited aproach, but that is subjective.

Regarding the clean start, that also is subjective and dependent on the use case of each user.
In my case, keeping the exact state upon reboot (particularly an automated or unexpected/unplanned reboot) is very important.