The following irule will achieve this:
when CLIENT_ACCEPTED {
set my_pool [LB::server pool]
}
when LB_FAILED {
log local0. "[active_members $my_pool]"
if { [active_members $my_pool] < 1 } {
HTTP::respond 200 content {
Apology Page
We are sorry, but the site you are looking for is temporarily out of service
If you feel you have reached this page in error, please try again.
}
}
}
The event CLIENT_ACCEPTED is only needed to get the pool name, and then it checks on LB_FAILED, if really no member is there, then it sends back the maintenance page. Alternatively this will work also if attached to HTTP_REQUEST, but that means the code will run on every request, while LB_FAILED will only run if the systems fails to select a pool member.
see also
https://devcentral.f5.com/wiki/iRules.lb_failed.ashx