Browse Source

Use supervisord to supervise Postgres and Caddy in the Complement image. (#12480)

Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
tags/v1.59.0rc1
reivilibre 2 years ago
committed by GitHub
parent
commit
d743b25c8f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 44 additions and 12 deletions
  1. +1
    -0
      changelog.d/12480.misc
  2. +3
    -0
      docker/Dockerfile-workers
  3. +4
    -1
      docker/complement/SynapseWorkers.Dockerfile
  4. +7
    -0
      docker/complement/conf-workers/caddy.supervisord.conf
  5. +16
    -0
      docker/complement/conf-workers/postgres.supervisord.conf
  6. +0
    -6
      docker/complement/conf-workers/start-complement-synapse-workers.sh
  7. +0
    -4
      docker/conf/log.config
  8. +1
    -1
      docker/configure_workers_and_start.py
  9. +12
    -0
      docker/prefix-log

+ 1
- 0
changelog.d/12480.misc View File

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

+ 3
- 0
docker/Dockerfile-workers View File

@@ -20,6 +20,9 @@ RUN rm /etc/nginx/sites-enabled/default
# Copy Synapse worker, nginx and supervisord configuration template files
COPY ./docker/conf-workers/* /conf/

# Copy a script to prefix log lines with the supervisor program name
COPY ./docker/prefix-log /usr/local/bin/

# Expose nginx listener port
EXPOSE 8080/tcp



+ 4
- 1
docker/complement/SynapseWorkers.Dockerfile View File

@@ -34,13 +34,16 @@ WORKDIR /data
# Copy the caddy config
COPY conf-workers/caddy.complement.json /root/caddy.json

COPY conf-workers/postgres.supervisord.conf /etc/supervisor/conf.d/postgres.conf
COPY conf-workers/caddy.supervisord.conf /etc/supervisor/conf.d/caddy.conf

# Copy the entrypoint
COPY conf-workers/start-complement-synapse-workers.sh /

# Expose caddy's listener ports
EXPOSE 8008 8448

ENTRYPOINT /start-complement-synapse-workers.sh
ENTRYPOINT ["/start-complement-synapse-workers.sh"]

# Update the healthcheck to have a shorter check interval
HEALTHCHECK --start-period=5s --interval=1s --timeout=1s \


+ 7
- 0
docker/complement/conf-workers/caddy.supervisord.conf View File

@@ -0,0 +1,7 @@
[program:caddy]
command=/usr/local/bin/prefix-log /root/caddy run --config /root/caddy.json
autorestart=unexpected
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0

+ 16
- 0
docker/complement/conf-workers/postgres.supervisord.conf View File

@@ -0,0 +1,16 @@
[program:postgres]
command=/usr/local/bin/prefix-log /usr/bin/pg_ctlcluster 13 main start --foreground

# Lower priority number = starts first
priority=1

autorestart=unexpected
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0

# Use 'Fast Shutdown' mode which aborts current transactions and closes connections quickly.
# (Default (TERM) is 'Smart Shutdown' which stops accepting new connections but
# lets existing connections close gracefully.)
stopsignal=INT

+ 0
- 6
docker/complement/conf-workers/start-complement-synapse-workers.sh View File

@@ -12,12 +12,6 @@ function log {
# Replace the server name in the caddy config
sed -i "s/{{ server_name }}/${SERVER_NAME}/g" /root/caddy.json

log "starting postgres"
pg_ctlcluster 13 main start

log "starting caddy"
/root/caddy start --config /root/caddy.json

# Set the server name of the homeserver
export SYNAPSE_SERVER_NAME=${SERVER_NAME}



+ 0
- 4
docker/conf/log.config View File

@@ -2,11 +2,7 @@ version: 1

formatters:
precise:
{% if worker_name %}
format: '%(asctime)s - worker:{{ worker_name }} - %(name)s - %(lineno)d - %(levelname)s - %(request)s - %(message)s'
{% else %}
format: '%(asctime)s - %(name)s - %(lineno)d - %(levelname)s - %(request)s - %(message)s'
{% endif %}

handlers:
{% if LOG_FILE_PATH %}


+ 1
- 1
docker/configure_workers_and_start.py View File

@@ -171,7 +171,7 @@ WORKERS_CONFIG: Dict[str, Dict[str, Any]] = {
# Templates for sections that may be inserted multiple times in config files
SUPERVISORD_PROCESS_CONFIG_BLOCK = """
[program:synapse_{name}]
command=/usr/local/bin/python -m {app} \
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


+ 12
- 0
docker/prefix-log View File

@@ -0,0 +1,12 @@
#!/bin/bash
#
# Prefixes all lines on stdout and stderr with the process name (as determined by
# the SUPERVISOR_PROCESS_NAME env var, which is automatically set by Supervisor).
#
# Usage:
# prefix-log command [args...]
#

exec 1> >(awk '{print "'"${SUPERVISOR_PROCESS_NAME}"' | "$0}' >&1)
exec 2> >(awk '{print "'"${SUPERVISOR_PROCESS_NAME}"' | "$0}' >&2)
exec "$@"

Loading…
Cancel
Save