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

Commit d743b25

Browse files
reivilibrerichvdh
andauthored
Use supervisord to supervise Postgres and Caddy in the Complement image. (#12480)
Co-authored-by: Richard van der Hoff <[email protected]>
1 parent 30c8e7e commit d743b25

9 files changed

+44
-12
lines changed

changelog.d/12480.misc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Use supervisord to supervise Postgres and Caddy in the Complement image to reduce restart time.

docker/Dockerfile-workers

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ RUN rm /etc/nginx/sites-enabled/default
2020
# Copy Synapse worker, nginx and supervisord configuration template files
2121
COPY ./docker/conf-workers/* /conf/
2222

23+
# Copy a script to prefix log lines with the supervisor program name
24+
COPY ./docker/prefix-log /usr/local/bin/
25+
2326
# Expose nginx listener port
2427
EXPOSE 8080/tcp
2528

docker/complement/SynapseWorkers.Dockerfile

+4-1
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,16 @@ WORKDIR /data
3434
# Copy the caddy config
3535
COPY conf-workers/caddy.complement.json /root/caddy.json
3636

37+
COPY conf-workers/postgres.supervisord.conf /etc/supervisor/conf.d/postgres.conf
38+
COPY conf-workers/caddy.supervisord.conf /etc/supervisor/conf.d/caddy.conf
39+
3740
# Copy the entrypoint
3841
COPY conf-workers/start-complement-synapse-workers.sh /
3942

4043
# Expose caddy's listener ports
4144
EXPOSE 8008 8448
4245

43-
ENTRYPOINT /start-complement-synapse-workers.sh
46+
ENTRYPOINT ["/start-complement-synapse-workers.sh"]
4447

4548
# Update the healthcheck to have a shorter check interval
4649
HEALTHCHECK --start-period=5s --interval=1s --timeout=1s \
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[program:caddy]
2+
command=/usr/local/bin/prefix-log /root/caddy run --config /root/caddy.json
3+
autorestart=unexpected
4+
stdout_logfile=/dev/stdout
5+
stdout_logfile_maxbytes=0
6+
stderr_logfile=/dev/stderr
7+
stderr_logfile_maxbytes=0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[program:postgres]
2+
command=/usr/local/bin/prefix-log /usr/bin/pg_ctlcluster 13 main start --foreground
3+
4+
# Lower priority number = starts first
5+
priority=1
6+
7+
autorestart=unexpected
8+
stdout_logfile=/dev/stdout
9+
stdout_logfile_maxbytes=0
10+
stderr_logfile=/dev/stderr
11+
stderr_logfile_maxbytes=0
12+
13+
# Use 'Fast Shutdown' mode which aborts current transactions and closes connections quickly.
14+
# (Default (TERM) is 'Smart Shutdown' which stops accepting new connections but
15+
# lets existing connections close gracefully.)
16+
stopsignal=INT

docker/complement/conf-workers/start-complement-synapse-workers.sh

-6
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@ function log {
1212
# Replace the server name in the caddy config
1313
sed -i "s/{{ server_name }}/${SERVER_NAME}/g" /root/caddy.json
1414

15-
log "starting postgres"
16-
pg_ctlcluster 13 main start
17-
18-
log "starting caddy"
19-
/root/caddy start --config /root/caddy.json
20-
2115
# Set the server name of the homeserver
2216
export SYNAPSE_SERVER_NAME=${SERVER_NAME}
2317

docker/conf/log.config

-4
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ version: 1
22

33
formatters:
44
precise:
5-
{% if worker_name %}
6-
format: '%(asctime)s - worker:{{ worker_name }} - %(name)s - %(lineno)d - %(levelname)s - %(request)s - %(message)s'
7-
{% else %}
85
format: '%(asctime)s - %(name)s - %(lineno)d - %(levelname)s - %(request)s - %(message)s'
9-
{% endif %}
106

117
handlers:
128
{% if LOG_FILE_PATH %}

docker/configure_workers_and_start.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@
171171
# Templates for sections that may be inserted multiple times in config files
172172
SUPERVISORD_PROCESS_CONFIG_BLOCK = """
173173
[program:synapse_{name}]
174-
command=/usr/local/bin/python -m {app} \
174+
command=/usr/local/bin/prefix-log /usr/local/bin/python -m {app} \
175175
--config-path="{config_path}" \
176176
--config-path=/conf/workers/shared.yaml \
177177
--config-path=/conf/workers/{name}.yaml

docker/prefix-log

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
#
3+
# Prefixes all lines on stdout and stderr with the process name (as determined by
4+
# the SUPERVISOR_PROCESS_NAME env var, which is automatically set by Supervisor).
5+
#
6+
# Usage:
7+
# prefix-log command [args...]
8+
#
9+
10+
exec 1> >(awk '{print "'"${SUPERVISOR_PROCESS_NAME}"' | "$0}' >&1)
11+
exec 2> >(awk '{print "'"${SUPERVISOR_PROCESS_NAME}"' | "$0}' >&2)
12+
exec "$@"

0 commit comments

Comments
 (0)