HAProxy – clear stick-table from the command line

fault-tolerancehaproxyhigh-availability

I'm using HAProxy to do automatic failover for an LDAP server, but I don't want automatic fail-back.

The scenario is that I have 2 nodes, s1 and s2. I want all traffic going to s1 unless it fails, when it fails, I want all traffic going to s2.
When s1 becomes healthy again, I don't want to automatically route traffic back to it because some entries will have been created on s2 when it was live. I want to ensure that all data has been synchronised before I make s1 active again.

I'm configuring HAProxy like so:

backend bk_app
    stick-table type ip size 1 nopurge
    stick on dst
    option httpchk
    server s1 10.37.226.118:80 check
    server s2 10.37.226.113:80 check backup

This appears to work, connections continue to go to s2 even after s1 is healthy again.

My question is – how do I clear the stick-table from the command line, in other words how do I redirect traffic back to s1?

I have seen some advice which says that if I force s2 to fail, HAProxy will redirect traffic back to s1. This seems to work, but when s2 becomes healthy again, HAProxy directs traffic back to s2 again, in other words the stick-table is still in effect.

I have seen some advice which says that I just need to restart HAProxy, which works perfectly, but this does seem like the nuclear option! Is there some sort of command line option to clear the stick-table?

Best Answer

You can use socket commands to clear the table i.e. echo "clear table Abuse key 192.168.64.12" | socat unix-connect:/var/run/haproxy.stat stdio

The documentation is here: http://haproxy.tech-notes.net/9-2-unix-socket-commands/