Forum Discussion
Show maintenance page when everything is down
I was just working on this same problem. I came across a few sections in the DevCentral Codeshare:
Both had great tips. I ended up combining them, though, because I want to return a 503 instead of 200. The code I'm using now runs at the end of my iRules (priority 1000). Between my first HTTP_REQUEST block and that final one, I do bits of processing that may change the pool. So by the time I get to my error handling at the end, I want to make sure I'm only doing this for pages that would be sent to the default pool. I certainly don't want this happening for every image and style sheet request that comes through! I think I need to constrain this even more, though. One of the Codeshare examples filtered on GET requests; that's probably wise.
do initial HTTP request processing
when HTTP_REQUEST priority 100 {
set DEBUG 1
set uri [HTTP::uri]
Derive a default pool name from our virtual server name
WARNING: This assumes our VS and pool use the same name.
set virtual_name [virtual name]
set default_pool [getfield $virtual_name "/" 3]
...
}
when HTTP_REQUEST priority 1000 {
set log_label "(VS $virtual_name) final"
set final_pool [getfield [LB::server pool] "/" 3]
If our selected pool is down, show a maintenance page and trigger a retry in $retry_interval seconds
if { $final_pool eq $default_pool && [active_members $final_pool] < 1 } {
sets the timer to return client to host URL
set retry_interval 30
log local0. "$log_label: --> pool $final_pool down; retrying in $retry_interval seconds"
Use the Host header value for the responses if it's set. If not, use the VIP address.
if {[string length [HTTP::host]]}{
set retry_host [HTTP::host]
} else {
set retry_host [IP::local_addr]
}
set retry_uri [HTTP::uri]
set iframe_src {https://MY_MAINTENANCE_LINK}
set respond_content "Maintenance\n\nRetrying your request in $retry_interval seconds\n"
HTTP::respond 503 content $respond_content {Content-Type} {text/html}
return
}
}
I have a bit of CSS in there, but the gist of the response is that it's sending back a 503 code, then following up with some short HTML to show a "retrying in $retry_interval seconds" message. Just below that, it includes an iframe that loads a maintenance page (see MY_MAINTENANCE_LINK above). I don't know if that's good or bad behavior for a 503 page, but it will let our web development team own the content of the maintenance page and let me handle how it's used.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com