Skip to content

Commit 801ed1f

Browse files
committed
fix: verify backend is UP in HAProxy before removing old container
1 parent 21249e1 commit 801ed1f

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

deploy/ansible/roles/app/tasks/main.yml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,21 @@
179179
docker kill -s HUP rustyip-haproxy
180180
changed_when: true
181181

182-
- name: Wait for HAProxy to settle
183-
ansible.builtin.pause:
184-
seconds: 5
182+
- name: Wait for new backend to be UP in HAProxy
183+
ansible.builtin.shell: |
184+
for i in $(seq 1 30); do
185+
csv=$(docker exec rustyip-haproxy wget -qO- \
186+
"http://127.0.0.1:9000/stats;csv;norefresh" 2>/dev/null)
187+
status=$(echo "$csv" | awk -F, '$1 == "app" && $2 == "{{ deploy_target }}" {print $18}')
188+
if [ "$status" = "UP" ]; then
189+
echo "backend {{ deploy_target }} is UP in HAProxy"
190+
exit 0
191+
fi
192+
sleep 2
193+
done
194+
echo "timeout waiting for backend {{ deploy_target }} to become UP"
195+
exit 1
196+
changed_when: false
185197

186198
- name: Stop old active container
187199
ansible.builtin.shell: |

deploy/ansible/roles/app/templates/haproxy.cfg.j2

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,21 @@ frontend https_in
6565
backend global_rate_tracking
6666
stick-table type string len 6 size 1 expire 10m store http_req_rate(1s)
6767

68+
frontend stats_internal
69+
bind 127.0.0.1:9000
70+
mode http
71+
stats enable
72+
stats uri /stats
73+
stats refresh 2s
74+
6875
resolvers docker_dns
6976
nameserver dns1 127.0.0.11:53
7077
resolve_retries 3
7178
timeout resolve 1s
7279
timeout retry 1s
7380
hold valid 10s
74-
hold nx 5s
81+
hold nx 30s
82+
hold obsolete 30s
7583

7684
backend app
7785
balance roundrobin

0 commit comments

Comments
 (0)