mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-02-17 14:44:07 -05:00
Refactor the Dockerfile-workers configuration script to use Jinja2 templates in Synapse workers' Supervisord blocks. (#13054)
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
This commit is contained in:
parent
3ceaf1462d
commit
3c5549e74a
1
changelog.d/13054.misc
Normal file
1
changelog.d/13054.misc
Normal file
@ -0,0 +1 @@
|
|||||||
|
Refactor the Dockerfile-workers configuration script to use Jinja2 templates in Synapse workers' Supervisord blocks.
|
@ -31,17 +31,3 @@ autorestart=true
|
|||||||
# Redis can be disabled if the image is being used without workers
|
# Redis can be disabled if the image is being used without workers
|
||||||
autostart={{ enable_redis }}
|
autostart={{ enable_redis }}
|
||||||
|
|
||||||
[program:synapse_main]
|
|
||||||
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
|
|
||||||
priority=10
|
|
||||||
# Log startup failures to supervisord's stdout/err
|
|
||||||
# Regular synapse logs will still go in the configured data directory
|
|
||||||
stdout_logfile=/dev/stdout
|
|
||||||
stdout_logfile_maxbytes=0
|
|
||||||
stderr_logfile=/dev/stderr
|
|
||||||
stderr_logfile_maxbytes=0
|
|
||||||
autorestart=unexpected
|
|
||||||
exitcodes=0
|
|
||||||
|
|
||||||
# Additional process blocks
|
|
||||||
{{ worker_config }}
|
|
||||||
|
30
docker/conf-workers/synapse.supervisord.conf.j2
Normal file
30
docker/conf-workers/synapse.supervisord.conf.j2
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
[program:synapse_main]
|
||||||
|
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
|
||||||
|
priority=10
|
||||||
|
# Log startup failures to supervisord's stdout/err
|
||||||
|
# Regular synapse logs will still go in the configured data directory
|
||||||
|
stdout_logfile=/dev/stdout
|
||||||
|
stdout_logfile_maxbytes=0
|
||||||
|
stderr_logfile=/dev/stderr
|
||||||
|
stderr_logfile_maxbytes=0
|
||||||
|
autorestart=unexpected
|
||||||
|
exitcodes=0
|
||||||
|
|
||||||
|
|
||||||
|
{% for worker in workers %}
|
||||||
|
[program:synapse_{{ worker.name }}]
|
||||||
|
command=/usr/local/bin/prefix-log /usr/local/bin/python -m {{ worker.app }}
|
||||||
|
--config-path="{{ main_config_path }}"
|
||||||
|
--config-path=/conf/workers/shared.yaml
|
||||||
|
--config-path=/conf/workers/{{ worker.name }}.yaml
|
||||||
|
autorestart=unexpected
|
||||||
|
priority=500
|
||||||
|
exitcodes=0
|
||||||
|
stdout_logfile=/dev/stdout
|
||||||
|
stdout_logfile_maxbytes=0
|
||||||
|
stderr_logfile=/dev/stderr
|
||||||
|
stderr_logfile_maxbytes=0
|
||||||
|
|
||||||
|
{% endfor %}
|
@ -176,21 +176,6 @@ WORKERS_CONFIG: Dict[str, Dict[str, Any]] = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Templates for sections that may be inserted multiple times in config files
|
# Templates for sections that may be inserted multiple times in config files
|
||||||
SUPERVISORD_PROCESS_CONFIG_BLOCK = """
|
|
||||||
[program:synapse_{name}]
|
|
||||||
command=/usr/local/bin/prefix-log /usr/local/bin/python -m {app} \
|
|
||||||
--config-path="{config_path}" \
|
|
||||||
--config-path=/conf/workers/shared.yaml \
|
|
||||||
--config-path=/conf/workers/{name}.yaml
|
|
||||||
autorestart=unexpected
|
|
||||||
priority=500
|
|
||||||
exitcodes=0
|
|
||||||
stdout_logfile=/dev/stdout
|
|
||||||
stdout_logfile_maxbytes=0
|
|
||||||
stderr_logfile=/dev/stderr
|
|
||||||
stderr_logfile_maxbytes=0
|
|
||||||
"""
|
|
||||||
|
|
||||||
NGINX_LOCATION_CONFIG_BLOCK = """
|
NGINX_LOCATION_CONFIG_BLOCK = """
|
||||||
location ~* {endpoint} {{
|
location ~* {endpoint} {{
|
||||||
proxy_pass {upstream};
|
proxy_pass {upstream};
|
||||||
@ -353,13 +338,10 @@ def generate_worker_files(
|
|||||||
# This config file will be passed to all workers, included Synapse's main process.
|
# This config file will be passed to all workers, included Synapse's main process.
|
||||||
shared_config: Dict[str, Any] = {"listeners": listeners}
|
shared_config: Dict[str, Any] = {"listeners": listeners}
|
||||||
|
|
||||||
# The supervisord config. The contents of which will be inserted into the
|
# List of dicts that describe workers.
|
||||||
# base supervisord jinja2 template.
|
# We pass this to the Supervisor template later to generate the appropriate
|
||||||
#
|
# program blocks.
|
||||||
# Supervisord will be in charge of running everything, from redis to nginx to Synapse
|
worker_descriptors: List[Dict[str, Any]] = []
|
||||||
# and all of its worker processes. Load the config template, which defines a few
|
|
||||||
# services that are necessary to run.
|
|
||||||
supervisord_config = ""
|
|
||||||
|
|
||||||
# Upstreams for load-balancing purposes. This dict takes the form of a worker type to the
|
# Upstreams for load-balancing purposes. This dict takes the form of a worker type to the
|
||||||
# ports of each worker. For example:
|
# ports of each worker. For example:
|
||||||
@ -437,7 +419,7 @@ def generate_worker_files(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Enable the worker in supervisord
|
# Enable the worker in supervisord
|
||||||
supervisord_config += SUPERVISORD_PROCESS_CONFIG_BLOCK.format_map(worker_config)
|
worker_descriptors.append(worker_config)
|
||||||
|
|
||||||
# Add nginx location blocks for this worker's endpoints (if any are defined)
|
# Add nginx location blocks for this worker's endpoints (if any are defined)
|
||||||
for pattern in worker_config["endpoint_patterns"]:
|
for pattern in worker_config["endpoint_patterns"]:
|
||||||
@ -535,10 +517,16 @@ def generate_worker_files(
|
|||||||
"/conf/supervisord.conf.j2",
|
"/conf/supervisord.conf.j2",
|
||||||
"/etc/supervisor/supervisord.conf",
|
"/etc/supervisor/supervisord.conf",
|
||||||
main_config_path=config_path,
|
main_config_path=config_path,
|
||||||
worker_config=supervisord_config,
|
|
||||||
enable_redis=workers_in_use,
|
enable_redis=workers_in_use,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
convert(
|
||||||
|
"/conf/synapse.supervisord.conf.j2",
|
||||||
|
"/etc/supervisor/conf.d/synapse.conf",
|
||||||
|
workers=worker_descriptors,
|
||||||
|
main_config_path=config_path,
|
||||||
|
)
|
||||||
|
|
||||||
# healthcheck config
|
# healthcheck config
|
||||||
convert(
|
convert(
|
||||||
"/conf/healthcheck.sh.j2",
|
"/conf/healthcheck.sh.j2",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user