How to make HAProxy wait for successful health check before bringing server out of maintenance mode

haproxyhealthcheckload balancing

I am using HAProxy socket communication to put my backend into maintenance mode before bringing the web server down for maintenance via this command:

echo "disable server cluster-01/app-01-4" | sudo socat stdio /tmp/haproxy.sock

The problem is that when I mark the backend available again via the socket enable command, HAProxy does not wait for any successful health checks before sending requests to the backend. So we end up losing some of the requests before HAProxy realizes the server is still down, and takes it back off line.

Is there a way to tell HAProxy to wait until the backend is healthy prior to enabling it? Or do I have to make my startup scripts smart enough to monitor the server itself prior to telling HaProxy to enable the backend again? This would obviously be less than ideal.

I'm currently doing this:
echo "enable server cluster-01/app-01-4" | sudo socat stdio /tmp/haproxy.sock

Is there something akin to this that I can use instead?
echo "enable server cluster-01/app-01-4 WAIT_FOR_SUCCESSFUL_HEALTH_CHECK" | sudo socat stdio /tmp/haproxy.sock

Edit: I am using HAProxy version 1.5x

Best Answer

Using set server proxy-name/server-name health down prior to putting the server back in service with enable server ... appears to do what you need.

The server would eventually be taken out of service by subsequent health checks, but that doesn't help if the server was healthy when you took it out, but not healthy when you bring it back in, since HAProxy appears to assume that the server will be in the same health state when enabled that it was in when it was disabled.