Commit 61cc3725 authored by Jérome Perrin's avatar Jérome Perrin

stack/erp5: make haproxy reload script wait for old worker processes

This is mostly to fix some flaky tests, because with the previous
approach of just sending a signal for haproxy to reload the config
asynchronously we don't know when haproxy has reloaded.
parent 9e1071da
Pipeline #38011 failed with stage
in 0 seconds
...@@ -94,7 +94,7 @@ md5sum = 9547bacad0635b0f64cac48f15c4e9ae ...@@ -94,7 +94,7 @@ md5sum = 9547bacad0635b0f64cac48f15c4e9ae
[template-balancer] [template-balancer]
filename = instance-balancer.cfg.in filename = instance-balancer.cfg.in
md5sum = 48b8b8b4b87973beaa1fd6299244ebd6 md5sum = 409a7505548576ebf0e4d5cc218e0753
[template-haproxy-cfg] [template-haproxy-cfg]
filename = haproxy.cfg.in filename = haproxy.cfg.in
......
...@@ -219,6 +219,7 @@ ca-cert = ${haproxy-conf-ssl:ca-cert} ...@@ -219,6 +219,7 @@ ca-cert = ${haproxy-conf-ssl:ca-cert}
crl = ${haproxy-conf-ssl:crl} crl = ${haproxy-conf-ssl:crl}
{% endif %} {% endif %}
stats-socket = ${directory:run}/ha.sock stats-socket = ${directory:run}/ha.sock
admin-socket = ${directory:run}/haa.sock
path-routing-list = {{ dumps(slapparameter_dict['path-routing-list']) }} path-routing-list = {{ dumps(slapparameter_dict['path-routing-list']) }}
family-path-routing-dict = {{ dumps(slapparameter_dict['family-path-routing-dict']) }} family-path-routing-dict = {{ dumps(slapparameter_dict['family-path-routing-dict']) }}
pidfile = ${directory:run}/haproxy.pid pidfile = ${directory:run}/haproxy.pid
...@@ -336,18 +337,60 @@ context = ...@@ -336,18 +337,60 @@ context =
extensions = jinja2.ext.do extensions = jinja2.ext.do
[haproxy-reload] [haproxy-reload]
recipe = collective.recipe.template recipe = slapos.recipe.template
output = ${directory:bin}/${:_buildout_section_name_} output = ${directory:bin}/${:_buildout_section_name_}
mode = 700 mode = 700
input = inline =
inline: #!${buildout:executable}
#!/bin/sh """Restarts haproxy and waits for all workers to have been restarted"""
kill -USR2 $(cat "${haproxy-cfg-parameter-dict:pidfile}") import errno
import contextlib
import socket
import sys
import time
ADMIN_SOCKET = '''${haproxy-cfg-parameter-dict:admin-socket}'''
def send_command(command, connect_retries=10):
with contextlib.closing(socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)) as sock:
while True:
connect_retries = connect_retries - 1
try:
sock.connect(ADMIN_SOCKET)
except OSError as e:
if e.errno != errno.ECONNREFUSED:
raise
if not connect_retries:
raise
time.sleep(1)
else:
break
sock.sendall((command + "\nquit\n").encode())
response = b""
while True:
data = sock.recv(4096)
if not data:
break
response += data
return response.decode()
send_command("reload")
for _ in range(360):
time.sleep(1)
proc = send_command("show proc")
if "old workers" not in proc:
sys.exit(0)
print(proc)
sys.exit(1)
[{{ section('haproxy') }}] [{{ section('haproxy') }}]
recipe = slapos.cookbook:wrapper recipe = slapos.cookbook:wrapper
wrapper-path = ${directory:services-on-watch}/haproxy wrapper-path = ${directory:services-on-watch}/haproxy
command-line = "{{ parameter_dict['haproxy'] }}/sbin/haproxy" -f "${haproxy-cfg:output}" command-line =
"{{ parameter_dict['haproxy'] }}/sbin/haproxy"
-S ${haproxy-cfg-parameter-dict:admin-socket},level,operator
-f "${haproxy-cfg:output}"
hash-files = ${haproxy-cfg:output} hash-files = ${haproxy-cfg:output}
[{{ section('haproxy-socat-stats')}}] [{{ section('haproxy-socat-stats')}}]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment