I did this recently, using the following irule named "failwhale-irule":
when HTTP_REQUEST {
if { [class match [virtual name] equals "failwhale-maintenance"] } {
log -noname local0. "MAINT [HTTP::host] [HTTP::uri] VS [virtual name] is in maintenance"
pool maintenance_pool
snat automap
}
if { [class match [LB::server pool] equals "failwhale-maintenance"] } {
log -noname local0. "MAINT [HTTP::host] [HTTP::uri] POOL [LB::server pool] is in maintenance"
pool maintenance_pool
snat automap
}
if { [active_members [LB::server pool]] == 0} {
log -noname local0. "FAIL [HTTP::host] [HTTP::uri] [LB::server pool] has no active members"
pool failwhale_pool
snat automap
}
}
can also use when LB_FAILED with LB::reselect
maintenance_pool and failwhale_pool point to http servers where the default site is an Apache server accepting any Host: header. It runs a WSGI script that customizes a maintenance or failure page with the requested site name and URL.
In this case I'm using
snat automap because the pool members happen to be external, making it a one-armed setup.
if { [active_members [LB::server pool]] == 0} is what you're really asking for, but I thought you might also be interested in the capability of class matching to virtuals that are known to be in maintenance. This lets us configure a site for maintenance without making it look like it's down accidentally.