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

Commit 3c5549e

Browse files
reivilibrerichvdh
andauthored
Refactor the Dockerfile-workers configuration script to use Jinja2 templates in Synapse workers' Supervisord blocks. (#13054)
Co-authored-by: Richard van der Hoff <[email protected]>
1 parent 3ceaf14 commit 3c5549e

File tree

4 files changed

+43
-38
lines changed

4 files changed

+43
-38
lines changed

changelog.d/13054.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Refactor the Dockerfile-workers configuration script to use Jinja2 templates in Synapse workers' Supervisord blocks.

docker/conf-workers/supervisord.conf.j2

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,3 @@ autorestart=true
3131
# Redis can be disabled if the image is being used without workers
3232
autostart={{ enable_redis }}
3333

34-
[program:synapse_main]
35-
command=/usr/local/bin/prefix-log /usr/local/bin/python -m synapse.app.homeserver --config-path="{{ main_config_path }}" --config-path=/conf/workers/shared.yaml
36-
priority=10
37-
# Log startup failures to supervisord's stdout/err
38-
# Regular synapse logs will still go in the configured data directory
39-
stdout_logfile=/dev/stdout
40-
stdout_logfile_maxbytes=0
41-
stderr_logfile=/dev/stderr
42-
stderr_logfile_maxbytes=0
43-
autorestart=unexpected
44-
exitcodes=0
45-
46-
# Additional process blocks
47-
{{ worker_config }}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[program:synapse_main]
2+
command=/usr/local/bin/prefix-log /usr/local/bin/python -m synapse.app.homeserver
3+
--config-path="{{ main_config_path }}"
4+
--config-path=/conf/workers/shared.yaml
5+
priority=10
6+
# Log startup failures to supervisord's stdout/err
7+
# Regular synapse logs will still go in the configured data directory
8+
stdout_logfile=/dev/stdout
9+
stdout_logfile_maxbytes=0
10+
stderr_logfile=/dev/stderr
11+
stderr_logfile_maxbytes=0
12+
autorestart=unexpected
13+
exitcodes=0
14+
15+
16+
{% for worker in workers %}
17+
[program:synapse_{{ worker.name }}]
18+
command=/usr/local/bin/prefix-log /usr/local/bin/python -m {{ worker.app }}
19+
--config-path="{{ main_config_path }}"
20+
--config-path=/conf/workers/shared.yaml
21+
--config-path=/conf/workers/{{ worker.name }}.yaml
22+
autorestart=unexpected
23+
priority=500
24+
exitcodes=0
25+
stdout_logfile=/dev/stdout
26+
stdout_logfile_maxbytes=0
27+
stderr_logfile=/dev/stderr
28+
stderr_logfile_maxbytes=0
29+
30+
{% endfor %}

docker/configure_workers_and_start.py

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -176,21 +176,6 @@
176176
}
177177

178178
# Templates for sections that may be inserted multiple times in config files
179-
SUPERVISORD_PROCESS_CONFIG_BLOCK = """
180-
[program:synapse_{name}]
181-
command=/usr/local/bin/prefix-log /usr/local/bin/python -m {app} \
182-
--config-path="{config_path}" \
183-
--config-path=/conf/workers/shared.yaml \
184-
--config-path=/conf/workers/{name}.yaml
185-
autorestart=unexpected
186-
priority=500
187-
exitcodes=0
188-
stdout_logfile=/dev/stdout
189-
stdout_logfile_maxbytes=0
190-
stderr_logfile=/dev/stderr
191-
stderr_logfile_maxbytes=0
192-
"""
193-
194179
NGINX_LOCATION_CONFIG_BLOCK = """
195180
location ~* {endpoint} {{
196181
proxy_pass {upstream};
@@ -353,13 +338,10 @@ def generate_worker_files(
353338
# This config file will be passed to all workers, included Synapse's main process.
354339
shared_config: Dict[str, Any] = {"listeners": listeners}
355340

356-
# The supervisord config. The contents of which will be inserted into the
357-
# base supervisord jinja2 template.
358-
#
359-
# Supervisord will be in charge of running everything, from redis to nginx to Synapse
360-
# and all of its worker processes. Load the config template, which defines a few
361-
# services that are necessary to run.
362-
supervisord_config = ""
341+
# List of dicts that describe workers.
342+
# We pass this to the Supervisor template later to generate the appropriate
343+
# program blocks.
344+
worker_descriptors: List[Dict[str, Any]] = []
363345

364346
# Upstreams for load-balancing purposes. This dict takes the form of a worker type to the
365347
# ports of each worker. For example:
@@ -437,7 +419,7 @@ def generate_worker_files(
437419
)
438420

439421
# Enable the worker in supervisord
440-
supervisord_config += SUPERVISORD_PROCESS_CONFIG_BLOCK.format_map(worker_config)
422+
worker_descriptors.append(worker_config)
441423

442424
# Add nginx location blocks for this worker's endpoints (if any are defined)
443425
for pattern in worker_config["endpoint_patterns"]:
@@ -535,10 +517,16 @@ def generate_worker_files(
535517
"/conf/supervisord.conf.j2",
536518
"/etc/supervisor/supervisord.conf",
537519
main_config_path=config_path,
538-
worker_config=supervisord_config,
539520
enable_redis=workers_in_use,
540521
)
541522

523+
convert(
524+
"/conf/synapse.supervisord.conf.j2",
525+
"/etc/supervisor/conf.d/synapse.conf",
526+
workers=worker_descriptors,
527+
main_config_path=config_path,
528+
)
529+
542530
# healthcheck config
543531
convert(
544532
"/conf/healthcheck.sh.j2",

0 commit comments

Comments
 (0)