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

Create healthcheck script for synapse-workers container. #11429

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/11429.docker
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update `Dockerfile-workers` to healthcheck all workers in container.
3 changes: 3 additions & 0 deletions docker/Dockerfile-workers
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ VOLUME ["/data"]
# files to run the desired worker configuration. Will start supervisord.
COPY ./docker/configure_workers_and_start.py /configure_workers_and_start.py
ENTRYPOINT ["/configure_workers_and_start.py"]

HEALTHCHECK --start-period=5s --interval=15s --timeout=5s \
CMD /bin/sh /healthcheck.sh
6 changes: 6 additions & 0 deletions docker/conf-workers/healthcheck.sh.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
# This healthcheck script is designed to return OK when every
# host involved returns OK
{%- for healthcheck_url in healthcheck_urls %}
curl -fSs {{ healthcheck_url }} || exit 1
{%- endfor %}
13 changes: 13 additions & 0 deletions docker/configure_workers_and_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,10 +474,16 @@ def generate_worker_files(environ, config_path: str, data_dir: str):

# Determine the load-balancing upstreams to configure
nginx_upstream_config = ""

# At the same time, prepare a list of internal endpoints to healthcheck
# starting with the main process which exists even if no workers do.
healthcheck_urls = ["http://localhost:8080/health"]

for upstream_worker_type, upstream_worker_ports in nginx_upstreams.items():
body = ""
for port in upstream_worker_ports:
body += " server localhost:%d;\n" % (port,)
healthcheck_urls.append("http://localhost:%d/health" % (port,))

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

# healthcheck config
convert(
"/conf/healthcheck.sh.j2",
"/healthcheck.sh",
healthcheck_urls=healthcheck_urls,
)

# Ensure the logging directory exists
log_dir = data_dir + "/logs"
if not os.path.exists(log_dir):
Expand Down