As I get to use HAProxy more and more, I recently ran into a particular circumstance where I needed to failover traffic from the live server, to the standby server. This is simple to do using the ‘backup‘ option in your haproxy configuration, however I wanted to ensure the service wouldn’t fail-back when the primary server was restored. In essence I needed a fail-over & stay-over setup.

The answer, until a specific feature is added to haproxy, is to set the criteria (i.e. number of passed checks) until the primary server is considered online extremely high. In particular it’s the ‘rise‘ option we’re interested.

listen  sql-cluster 0.0.0.0:1433
        balance roundrobin
        server  sql01 192.168.100.109:1433 check backup
        server  sql02 192.168.100.180:1433 check inter 5s fall 3 rise 99999999

Credit to serverfault for this one.