Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Commit 10a3922

Browse files
hierynomusFeng Honglin
authored andcommitted
Allow a service to be configured as failover for another service in the same backend (#120)
* Added support for hot-failover mode * Updated README
1 parent 5d76e70 commit 10a3922

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ Similar to using legacy links, here list some differences that you need to notic
156156
Once the stack is up, you can scale the web service using `docker-compose scale web=3`. dockercloud/haproxy will automatically reload its configuration.
157157

158158
#### Running with Docker Compose v2 and Swarm (using envvar)
159-
When using links like previous section, the Docker Swarm scheduler can be too restrictive.
160-
Even with overlay network, swarm (As of 1.1.0) will attempt to schedule haproxy on the same node as the linked service due to legacy links behavior.
159+
When using links like previous section, the Docker Swarm scheduler can be too restrictive.
160+
Even with overlay network, swarm (As of 1.1.0) will attempt to schedule haproxy on the same node as the linked service due to legacy links behavior.
161161
This can cause unwanted scheduling patterns or errors such as "Unable to find a node fulfilling all dependencies..."
162162

163163
Since Compose V2 allows discovery through the service names, Dockercloud haproxy only needs the links to indentify which service should be load balanced.
@@ -242,6 +242,7 @@ Settings here can overwrite the settings in HAProxy, which are only applied to t
242242
|EXCLUDE_PORTS|if set(any value) and `HTTP_BASIC_AUTH` global setting is set, no basic auth will be applied to this service.|
243243
|EXTRA_ROUTE_SETTINGS|a string which is append to the each backend route after the health check,possible value: "send-proxy"|
244244
|EXTRA_SETTINGS|comma-separated string of extra settings, and each part will be appended to either related backend section or listen session in the configuration file. To escape comma, use `\,`. Possible value: `balance source`|
245+
|FAILOVER|boolean setting that configures this service to be run as HAProxy `backup` for other configured service(s) in this backend|
245246
|FORCE_SSL|if set(any value) together with ssl termination enabled. HAProxy will redirect HTTP request to HTTPS request.
246247
|GZIP_COMPRESSION_TYPE|enable gzip compression. The value of this envvar is a list of MIME types that will be compressed. Some possible values: `text/html text/plain text/css application/javascript`. See:[HAProxy:compression](http://cbonte.github.io/haproxy-dconv/configuration-1.5.html#4-compression)|
247248
|HEALTH_CHECK|set health check on each backend route, possible value: "check inter 2000 rise 2 fall 3". See:[HAProxy:check](https://cbonte.github.io/haproxy-dconv/configuration-1.5.html#5.2-check)|

haproxy/helper/backend_helper.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@ def get_backend_section(details, routes, vhosts, service_alias, routes_added):
1616
route_health_check = get_route_health_check(details, service_alias, HEALTH_CHECK)
1717
extra_route_settings = get_extra_route_settings(details, service_alias, EXTRA_ROUTE_SETTINGS)
1818
route_setting = " ".join([route_health_check, extra_route_settings]).strip()
19-
backend_routes = get_backend_routes(route_setting, is_sticky, routes, routes_added, service_alias)
19+
backend_routes = get_backend_routes(route_setting, is_sticky, routes, routes_added, service_alias, details)
2020
backend.extend(backend_routes)
2121

2222
return backend
2323

2424

25-
def get_backend_routes(route_setting, is_sticky, routes, routes_added, service_alias):
25+
def get_backend_routes(route_setting, is_sticky, routes, routes_added, service_alias, details):
2626
backend_routes = []
2727
for _service_alias, routes in routes.iteritems():
2828
if not service_alias or _service_alias == service_alias:
29+
service_details = details[_service_alias]
2930
addresses_added = []
3031
for route in routes:
3132
# avoid adding those tcp routes adding http backends
@@ -41,6 +42,9 @@ def get_backend_routes(route_setting, is_sticky, routes, routes_added, service_a
4142
if route_setting:
4243
backend_route.append(route_setting)
4344

45+
if 'failover' in service_details and service_details['failover']:
46+
backend_route.append("backup")
47+
4448
backend_routes.append(" ".join(backend_route))
4549

4650
return sorted(backend_routes)

haproxy/parser/base_parser.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,7 @@ def parse_extra_settings(value):
188188
@staticmethod
189189
def parse_extra_route_settings(value):
190190
return value
191+
192+
@staticmethod
193+
def parse_failover(value):
194+
return value

0 commit comments

Comments
 (0)