Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit e2c300e

Browse files
authored
Create healthcheck script for synapse-workers container (#11429)
The intent is to iterate through all the worker ports and only report healthy when all are healthy, starting with the main process.
1 parent c675a18 commit e2c300e

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

changelog.d/11429.docker

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Update `Dockerfile-workers` to healthcheck all workers in container.

docker/Dockerfile-workers

+3
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ VOLUME ["/data"]
2121
# files to run the desired worker configuration. Will start supervisord.
2222
COPY ./docker/configure_workers_and_start.py /configure_workers_and_start.py
2323
ENTRYPOINT ["/configure_workers_and_start.py"]
24+
25+
HEALTHCHECK --start-period=5s --interval=15s --timeout=5s \
26+
CMD /bin/sh /healthcheck.sh

docker/conf-workers/healthcheck.sh.j2

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
# This healthcheck script is designed to return OK when every
3+
# host involved returns OK
4+
{%- for healthcheck_url in healthcheck_urls %}
5+
curl -fSs {{ healthcheck_url }} || exit 1
6+
{%- endfor %}

docker/configure_workers_and_start.py

+13
Original file line numberDiff line numberDiff line change
@@ -474,10 +474,16 @@ def generate_worker_files(environ, config_path: str, data_dir: str):
474474

475475
# Determine the load-balancing upstreams to configure
476476
nginx_upstream_config = ""
477+
478+
# At the same time, prepare a list of internal endpoints to healthcheck
479+
# starting with the main process which exists even if no workers do.
480+
healthcheck_urls = ["http://localhost:8080/health"]
481+
477482
for upstream_worker_type, upstream_worker_ports in nginx_upstreams.items():
478483
body = ""
479484
for port in upstream_worker_ports:
480485
body += " server localhost:%d;\n" % (port,)
486+
healthcheck_urls.append("http://localhost:%d/health" % (port,))
481487

482488
# Add to the list of configured upstreams
483489
nginx_upstream_config += NGINX_UPSTREAM_CONFIG_BLOCK.format(
@@ -510,6 +516,13 @@ def generate_worker_files(environ, config_path: str, data_dir: str):
510516
worker_config=supervisord_config,
511517
)
512518

519+
# healthcheck config
520+
convert(
521+
"/conf/healthcheck.sh.j2",
522+
"/healthcheck.sh",
523+
healthcheck_urls=healthcheck_urls,
524+
)
525+
513526
# Ensure the logging directory exists
514527
log_dir = data_dir + "/logs"
515528
if not os.path.exists(log_dir):

0 commit comments

Comments
 (0)