Tomcat – Rolling Deploys with Tomcats Behind HAProxy

haproxyload balancingtomcat

I have three Tomcat instances running behind an HAProxy. When I roll out changes to my web applications, I'd like to do a rolling deploy (i.e. bounce one Tomcat at a time) so users don't see any downtime.

How do I do this? I see that a running instance of haproxy can be hot-reconfigured (which is good for adding or removing new pool servers), but how does HAProxy react when one of its target servers is temporarily down?

If there's a better solution than HAProxy, I'd be willing to look at that too.

Thanks!

Best Answer

I sent an e-mail to Willy Tarreau and got back the following options:

  1. You can use hot reconfiguration or socat commands to the stats server to set the weight of your target server to 0. This will prevent new sessions from being balanced to that server, but won't affect existing connections.

  2. You can set the http-check disable-on-404 option in combination with "option httpcheck /myurl" and then have your target servers respond to /myurl such that they send a 200 status if everything is fine, a 404 if the server should stop receiving new requests, and a 500 if the server should receive nothing (i.e. when you're ready to bounce the server). haproxy will re-check on the server at the interval specified in your server line.