From a26357efb9490286c170112f6f89c1e697de91f0 Mon Sep 17 00:00:00 2001
From: Jeffrey Zhang <zhang.lei.fly@gmail.com>
Date: Fri, 19 Jan 2018 13:12:57 +0800
Subject: [PATCH] Add a active-standby mode memcached in haproxy

Memcached do not support cluster. Then make it work in active-standby
mode. This will be helpful to implement high available when using memcached
as tooz backend.

Change-Id: I13722111d8b8d5b066e9a85d4c8d1679704c8caa
---
 ansible/roles/haproxy/templates/haproxy.cfg.j2 | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/ansible/roles/haproxy/templates/haproxy.cfg.j2 b/ansible/roles/haproxy/templates/haproxy.cfg.j2
index 335b4b9f05..0147bb8e0a 100644
--- a/ansible/roles/haproxy/templates/haproxy.cfg.j2
+++ b/ansible/roles/haproxy/templates/haproxy.cfg.j2
@@ -892,6 +892,19 @@ listen mariadb
 {% endfor %}
 {% endif %}
 
+{% if enable_memcached | bool %}
+listen memcached
+  mode tcp
+  timeout client 3600s
+  timeout server 3600s
+  option tcplog
+  option tcpka
+  bind {{ kolla_internal_vip_address }}:{{ memcached_port }}
+{% for host in groups['memcached'] %}
+  server {{ hostvars[host]['ansible_hostname'] }} {{ hostvars[host]['ansible_' + hostvars[host]['api_interface']]['ipv4']['address'] }}:{{ memcached_port }} check inter 2000 rise 2 fall 5 {% if not loop.first %}backup{% endif %}
+{% endfor %}
+{% endif %}
+
 {% if enable_opendaylight | bool %}
 listen opendaylight_api
   bind {{ kolla_internal_vip_address }}:{{ opendaylight_haproxy_restconf_port }}