mirror of
https://github.com/spantaleev/matrix-docker-ansible-deploy.git
synced 2026-10-21 05:44:16 +00:00
Containers are created with `--rm`, so Docker removes them asynchronously after they stop. The pre-start `docker rm` returns immediately while that removal is still in progress (its error is suppressed), and the following `docker create --name` can fail with "The container name ... is already in use". This is easy to hit since systemd_service_manager switched its default restart mode to `all-at-once`: many containers stop and start at the same time and Docker falls behind on removals. The playbook then fails at "Restart systemd services needing restart at once", even though the services recover on their own (`Restart=always`) a little later. The external roles (MASH, devture) were hardened against this in 2026-03 (see mother-of-all-self-hosting/ansible-role-valkey@0ba79c0), but the roles in `roles/custom` never were. This ports the same bounded cleanup loop to them: stop, force-remove, and wait until Docker releases the name, failing explicitly after a timeout. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
127 lines
8.0 KiB
YAML
127 lines
8.0 KiB
YAML
# SPDX-FileCopyrightText: 2023 - 2024 Nikita Chernyi
|
|
# SPDX-FileCopyrightText: 2023 - 2025 Slavi Pantaleev
|
|
# SPDX-FileCopyrightText: 2023 Samuel Meenzen
|
|
# SPDX-FileCopyrightText: 2025 Suguru Hirahara
|
|
#
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
---
|
|
|
|
# synapse_auto_compressor tool
|
|
# Project source code URL: https://github.com/matrix-org/rust-synapse-compress-state
|
|
|
|
matrix_synapse_auto_compressor_enabled: true
|
|
|
|
# renovate: datasource=docker depName=registry.gitlab.com/mb-saces/rust-synapse-tools
|
|
matrix_synapse_auto_compressor_version: v0.0.3
|
|
|
|
# note: UID/GID better to match the UID/GID of the Postgres container, but it doesn't really matter, as volumes are not used here
|
|
matrix_synapse_auto_compressor_uid: ''
|
|
matrix_synapse_auto_compressor_gid: ''
|
|
|
|
# note: the Postgres image version doesn't matter, as it is used for a SQL script that doesn't use any specific features
|
|
matrix_synapse_auto_compressor_postgres_image: "postgres"
|
|
|
|
matrix_synapse_auto_compressor_base_path: "{{ matrix_base_data_path }}/synapse-auto-compressor"
|
|
matrix_synapse_auto_compressor_container_src_files_path: "{{ matrix_synapse_auto_compressor_base_path }}/container-src"
|
|
|
|
matrix_synapse_auto_compressor_container_image_self_build: false
|
|
matrix_synapse_auto_compressor_container_image_self_build_repo: "https://github.com/matrix-org/rust-synapse-compress-state.git"
|
|
matrix_synapse_auto_compressor_container_image_self_build_version: "{{ 'main' if matrix_synapse_auto_compressor_version == 'latest' else matrix_synapse_auto_compressor_version }}"
|
|
|
|
matrix_synapse_auto_compressor_container_image: "{{ matrix_synapse_auto_compressor_container_image_registry_prefix }}mb-saces/rust-synapse-tools:{{ matrix_synapse_auto_compressor_version }}"
|
|
matrix_synapse_auto_compressor_container_image_registry_prefix: "{{ 'localhost/' if matrix_synapse_auto_compressor_container_image_self_build else matrix_synapse_auto_compressor_container_image_registry_prefix_upstream }}"
|
|
matrix_synapse_auto_compressor_container_image_registry_prefix_upstream: "{{ matrix_synapse_auto_compressor_container_image_registry_prefix_upstream_default }}"
|
|
matrix_synapse_auto_compressor_container_image_registry_prefix_upstream_default: "registry.gitlab.com/"
|
|
|
|
# The base container network. It will be auto-created by this role if it doesn't exist already.
|
|
matrix_synapse_auto_compressor_container_network: matrix-synapse-auto-compressor
|
|
|
|
# A list of additional container networks that the container would be connected to.
|
|
# The role does not create these networks, so make sure they already exist.
|
|
# Use this to expose this container to another reverse proxy, which runs in a different container network.
|
|
matrix_synapse_auto_compressor_container_additional_networks: []
|
|
|
|
# A list of extra arguments to pass to the container
|
|
matrix_synapse_auto_compressor_container_extra_arguments: []
|
|
|
|
# Controls how long the pre-start cleanup should wait for stale container-name release
|
|
# before failing startup explicitly.
|
|
matrix_synapse_auto_compressor_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}"
|
|
|
|
# Controls the delay between pre-start cleanup retries.
|
|
matrix_synapse_auto_compressor_container_cleanup_retry_delay_seconds: "{{ devture_systemd_docker_base_container_cleanup_retry_delay_seconds }}"
|
|
|
|
# Shell command used in the systemd pre-start phase to deterministically remove a stale
|
|
# container and wait until Docker releases its name.
|
|
matrix_synapse_auto_compressor_container_cleanup_command: |
|
|
i=0;
|
|
while [ "$i" -lt {{ matrix_synapse_auto_compressor_container_cleanup_timeout_seconds }} ]; do
|
|
{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-synapse-auto-compressor >/dev/null 2>&1 || true;
|
|
{{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-synapse-auto-compressor >/dev/null 2>&1 || true;
|
|
if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-synapse-auto-compressor >/dev/null 2>&1; then
|
|
i=$((i + 1));
|
|
sleep {{ matrix_synapse_auto_compressor_container_cleanup_retry_delay_seconds }};
|
|
continue;
|
|
fi;
|
|
if {{ devture_systemd_docker_base_host_command_docker }} info >/dev/null 2>&1; then
|
|
exit 0;
|
|
fi;
|
|
echo "Failed to query Docker daemon while cleaning up matrix-synapse-auto-compressor" >&2;
|
|
exit 1;
|
|
done;
|
|
echo "Failed to remove stale container matrix-synapse-auto-compressor after {{ matrix_synapse_auto_compressor_container_cleanup_timeout_seconds }} attempts" >&2;
|
|
exit 1
|
|
|
|
# List of systemd services that matrix-synapse-auto-compressor.service depends on
|
|
matrix_synapse_auto_compressor_systemd_required_services_list: "{{ matrix_synapse_auto_compressor_systemd_required_services_list_default + matrix_synapse_auto_compressor_systemd_required_services_list_auto + matrix_synapse_auto_compressor_systemd_required_services_list_custom }}"
|
|
matrix_synapse_auto_compressor_systemd_required_services_list_default: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}"
|
|
matrix_synapse_auto_compressor_systemd_required_services_list_auto: []
|
|
matrix_synapse_auto_compressor_systemd_required_services_list_custom: []
|
|
|
|
# List of systemd services that matrix-synapse-auto-compressor.service wants
|
|
matrix_synapse_auto_compressor_systemd_wanted_services_list: []
|
|
|
|
matrix_synapse_auto_compressor_database_username: 'synapse'
|
|
matrix_synapse_auto_compressor_database_password: ''
|
|
matrix_synapse_auto_compressor_database_hostname: ''
|
|
matrix_synapse_auto_compressor_database_port: 5432
|
|
matrix_synapse_auto_compressor_database_name: 'synapse'
|
|
|
|
# connection string to synapse database (postgres only)
|
|
matrix_synapse_auto_compressor_synapse_database: 'postgres://{{ matrix_synapse_auto_compressor_database_username | urlencode() }}:{{ matrix_synapse_auto_compressor_database_password | urlencode() }}@{{ matrix_synapse_auto_compressor_database_hostname }}:{{ matrix_synapse_auto_compressor_database_port }}/{{ matrix_synapse_auto_compressor_database_name }}'
|
|
|
|
# Controls the `OnCalendar` configuration for the compressor job.
|
|
# Also see: `matrix_synapse_auto_compressor_schedule_randomized_delay_sec`
|
|
matrix_synapse_auto_compressor_schedule: "*-*-* 00:00:00"
|
|
|
|
# The `RandomizedDelaySec` delay (in seconds or as a systemd time string) to randomize the `OnCalendar` start time (`matrix_synapse_auto_compressor_schedule`) of the compressor job.
|
|
# This can be set to 0 to disable randomized delays.
|
|
matrix_synapse_auto_compressor_schedule_randomized_delay_sec: 6h
|
|
|
|
# The number of state groups to work on at once.
|
|
# All of the entries from state_groups_state are requested from the database for state groups that are worked on.
|
|
# Therefore small chunk sizes may be needed on machines with low memory.
|
|
# Note: if the compressor fails to find space savings on the chunk as a whole
|
|
# (which may well happen in rooms with lots of backfill in) then the entire chunk is skipped.
|
|
matrix_synapse_auto_compressor_chunk_size: 500
|
|
|
|
# CHUNKS_TO_COMPRESS chunks of size CHUNK_SIZE will be compressed.
|
|
# The higher this number is set to, the longer the compressor will run for.
|
|
matrix_synapse_auto_compressor_chunks_to_compress: 100
|
|
|
|
matrix_synapse_auto_compressor_command: "synapse_auto_compressor -p $POSTGRES_LOCATION -c {{ matrix_synapse_auto_compressor_chunk_size }} -n {{ matrix_synapse_auto_compressor_chunks_to_compress }}"
|
|
|
|
# Controls the POSTGRES_LOCATION environment variable
|
|
matrix_synapse_auto_compressor_environment_variable_postgres_location: "{{ matrix_synapse_auto_compressor_synapse_database }}"
|
|
|
|
# matrix_synapse_auto_compressor_restart_necessary controls whether the service
|
|
# will be restarted (when true) or merely started (when false) by the
|
|
# systemd service manager role (when conditional restart is enabled).
|
|
#
|
|
# This value is automatically computed during installation based on whether
|
|
# any configuration files, the systemd service file, or the container image changed.
|
|
# The default of `false` means "no restart needed" — appropriate when the role's
|
|
# installation tasks haven't run (e.g., due to --tags skipping them).
|
|
matrix_synapse_auto_compressor_restart_necessary: false
|