I would like to redirect requests to a “sorry page” during maintenance downtimes. Is it possible to base redirection on whether, or not, a semaphore file is present on my haproxy host?
That is:
If file is present, redirect to sorry page.
Thank you
sean.r
I’m not aware of any way to interact with the file-system from HAProxy.
However there are multiple ways to achieve what you are searching for (from simplest to most complex):
- use backend server checks for an path like
/up
, which if it is served (say by NGinx) from the server’s filesystem you can just remove it to mark the server down for HAProxy; (then use nbsrv
sample to identify if there are any servers left in a backend, and route requests to the “maintainance” website server;)
- use the HAProxy stats page with admin rights enabled (or a tool like
hatop
, or directly by using HAProxy management commands) to manually mark the server down or for maintainance; (also use the nbsrv
sample as above;) (see set server health) (you can even automate this with socat
as described in the linked documentation;)
- if you really need to use that semaphore file on the HAProxy server, you could use the following trick: install
webfs
(an extremly simple webserver), make it listen only on 127.0.0.1
and use that as a backend server check target (use the addr and port server options, which although don’t have the “check” in their name, they refer to that;)
- or alternatively you can use the agent-check directive that allows you not only to designate a server up or down, but also its weight, etc.;
- you can even come up with something like: have a path like
/admin/up/<random-token>
and /admin/down/<random-token>
which you can use to set a process variable to decide the routing by using http-request set-var(proc.down) 1 if { path /admin/.... }
(and similar for up); then route traffic to the “maintainance” webserver based on this variable with ACL’s;
I hope that I gave you enough (and diverse) ideas to solve your issue. If you settle on a particular option and want more info, just let me know.