On Fri, Sep 28, 2012 at 07:25:01AM +0200, Fred Leeflang wrote:
> Hi,
> 
> A last question for now; The haproxy loadbalancers listen to dual IP 
> addresses, ideally one of these IP addresses is active on a host, this 
> is done through heartbeat. When one virtual IP address disappears, 
> heartbeat will make the IP address active on the second host and haproxy 
> will there listen to both. This approach I've tested and it works.
> 
> However, when haproxy stops for some reason on either node heartbeat 
> should detect this and shut down. This is more of a heartbeat question 
> than a haproxy question I guess but I'm hoping you folks on here know 
> how to do this as well. The simplest way would be to simply to have a 
> shell script check if haproxy is running, if not shutdown heartbeat on 
> the node; Just don't know if this is the most elegant way.

I can't respond specifically for heartbeat since I don't use it, but with
keepalived I generally check haproxy's presence using "killall -0 haproxy"
which is very cheap and returns 0/err depending on the process presence.
You can safely run this several times a second without detecting any load
on the system.

I also like to check haproxy for the availability of the servers. This is
a bit more complex, you have to create a dedicated frontend, define a
monitor URI and a fail reason based on the number of servers for example :

    frontend check
        bind 127.0.0.1:9999
        mode http
        monitor-uri /
        monitor fail if { nbsrv(nginx) lt 1 } || { nbsrv(php) lt 1 }

This service will return 200 when it's OK or 5xx on failure. So you can
check it with a simple shell script, for example :

    #!/bin/bash
    exec 3</dev/tcp/127.0.0.1/9999
    echo "GET /" >&3
    read -u 3 -t 1
    exec 3<&-
    set -- $REPLY
    test "${2:0:3}" == "200"

Some very cheap HTTP clients such as the wget from busybox might be
appropriate as well instead of the script above.

Regards,
Willy


Reply via email to