mirror of
https://github.com/spantaleev/matrix-docker-ansible-deploy.git
synced 2026-10-20 21:34:15 +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>
161 lines
11 KiB
YAML
161 lines
11 KiB
YAML
# SPDX-FileCopyrightText: 2024 - 2026 Slavi Pantaleev
|
|
# SPDX-FileCopyrightText: 2024 Michael Hollister
|
|
# SPDX-FileCopyrightText: 2024 Suguru Hirahara
|
|
#
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
---
|
|
|
|
# Synapse Usage Exporter
|
|
# Project source code URL: https://github.com/loelkes/synapse-usage-exporter
|
|
|
|
matrix_synapse_usage_exporter_enabled: false
|
|
|
|
# Controls the hostname and path that the usage-stats ingestion endpoint is exposed on.
|
|
# Only used if `matrix_synapse_usage_exporter_proxying_enabled` is true.
|
|
#
|
|
# The metrics endpoint is exposed separately.
|
|
# See `matrix_synapse_usage_exporter_metrics_proxying_enabled` and friends.
|
|
matrix_synapse_usage_exporter_hostname: "{{ matrix_server_fqn_matrix }}"
|
|
matrix_synapse_usage_exporter_path_prefix: /report-usage-stats/push
|
|
|
|
# matrix_synapse_usage_exporter_identifier controls the identifier of this synapse-usage-exporter instance, which influences:
|
|
# - the default storage path
|
|
# - the names of systemd services and containers
|
|
matrix_synapse_usage_exporter_identifier: matrix-synapse-usage-exporter
|
|
matrix_synapse_usage_exporter_container_port: 5000
|
|
|
|
# No docker images are currently hosted for the repo, so defaulting to true
|
|
matrix_synapse_usage_exporter_container_image_self_build: true
|
|
matrix_synapse_usage_exporter_container_image_self_build_repo: "https://github.com/loelkes/synapse-usage-exporter.git"
|
|
|
|
matrix_synapse_usage_exporter_container_image_path: "loelkes/synapse-usage-exporter"
|
|
matrix_synapse_usage_exporter_container_image: "{{ matrix_synapse_usage_exporter_container_image_registry_prefix }}{{ matrix_synapse_usage_exporter_container_image_path }}:{{ matrix_synapse_usage_exporter_container_image_tag }}"
|
|
matrix_synapse_usage_exporter_container_image_registry_prefix: "{{ 'localhost/' if matrix_synapse_usage_exporter_container_image_self_build else matrix_synapse_usage_exporter_container_image_registry_prefix_upstream }}"
|
|
matrix_synapse_usage_exporter_container_image_registry_prefix_upstream: "{{ matrix_synapse_usage_exporter_container_image_registry_prefix_upstream_default }}"
|
|
matrix_synapse_usage_exporter_container_image_registry_prefix_upstream_default: "docker.io/"
|
|
matrix_synapse_usage_exporter_container_image_tag: "{{ 'main' if matrix_synapse_usage_exporter_container_image_self_build else 'latest' }}"
|
|
|
|
matrix_synapse_usage_exporter_base_path: "{{ matrix_base_data_path }}/{{ matrix_synapse_usage_exporter_identifier }}"
|
|
matrix_synapse_usage_exporter_docker_src_files_path: "{{ matrix_synapse_usage_exporter_base_path }}/docker-src"
|
|
|
|
# List of systemd services that synapse-usage-exporter.service depends on
|
|
matrix_synapse_usage_exporter_systemd_required_services_list: "{{ matrix_synapse_usage_exporter_systemd_required_services_list_default + matrix_synapse_usage_exporter_systemd_required_services_list_auto + matrix_synapse_usage_exporter_systemd_required_services_list_custom }}"
|
|
matrix_synapse_usage_exporter_systemd_required_services_list_default: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}"
|
|
matrix_synapse_usage_exporter_systemd_required_services_list_auto: []
|
|
matrix_synapse_usage_exporter_systemd_required_services_list_custom: []
|
|
|
|
# List of systemd services that synapse-usage-exporter.service wants
|
|
matrix_synapse_usage_exporter_systemd_wanted_services_list: []
|
|
|
|
# The base container network. It will be auto-created by this role if it doesn't exist already.
|
|
matrix_synapse_usage_exporter_container_network: "{{ matrix_synapse_usage_exporter_identifier }}"
|
|
|
|
# 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_usage_exporter_container_additional_networks: []
|
|
|
|
# Extra arguments for the Docker container
|
|
matrix_synapse_usage_exporter_container_extra_arguments: []
|
|
|
|
# Controls how long the pre-start cleanup should wait for stale container-name release
|
|
# before failing startup explicitly.
|
|
matrix_synapse_usage_exporter_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}"
|
|
|
|
# Controls the delay between pre-start cleanup retries.
|
|
matrix_synapse_usage_exporter_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_usage_exporter_container_cleanup_command: |
|
|
i=0;
|
|
while [ "$i" -lt {{ matrix_synapse_usage_exporter_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_usage_exporter_identifier }} >/dev/null 2>&1 || true;
|
|
{{ devture_systemd_docker_base_host_command_docker }} rm -f {{ matrix_synapse_usage_exporter_identifier }} >/dev/null 2>&1 || true;
|
|
if {{ devture_systemd_docker_base_host_command_docker }} container inspect {{ matrix_synapse_usage_exporter_identifier }} >/dev/null 2>&1; then
|
|
i=$((i + 1));
|
|
sleep {{ matrix_synapse_usage_exporter_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_usage_exporter_identifier }}" >&2;
|
|
exit 1;
|
|
done;
|
|
echo "Failed to remove stale container {{ matrix_synapse_usage_exporter_identifier }} after {{ matrix_synapse_usage_exporter_container_cleanup_timeout_seconds }} attempts" >&2;
|
|
exit 1
|
|
|
|
# Controls whether the synapse-usage-exporter's usage-stats ingestion endpoint should be proxied (exposed publicly).
|
|
#
|
|
# Exposure happens on `matrix.example.com/report-usage-stats/push` by default.
|
|
# See: `matrix_synapse_usage_exporter_hostname` and `matrix_synapse_usage_exporter_path_prefix`.
|
|
#
|
|
# This variable does not affect the metrics endpoint in any way.
|
|
# Metrics are always served on the container network (which is enough for a local Prometheus to scrape them)
|
|
# and are exposed publicly via `matrix_synapse_usage_exporter_metrics_proxying_enabled`.
|
|
matrix_synapse_usage_exporter_proxying_enabled: false
|
|
|
|
# Controls whether synapse-usage-exporter metrics should be proxied (exposed) on `matrix.example.com/metrics/synapse-usage-exporter`.
|
|
#
|
|
# Metrics are always served by the service on the container network, so a local (in-container) Prometheus
|
|
# can scrape them without any of this. Exposing them publicly is only necessary
|
|
# if metrics need to be consumed by another (external) Prometheus server.
|
|
matrix_synapse_usage_exporter_metrics_proxying_enabled: false
|
|
matrix_synapse_usage_exporter_metrics_proxying_hostname: ''
|
|
matrix_synapse_usage_exporter_metrics_proxying_path: /metrics/synapse-usage-exporter
|
|
|
|
# matrix_synapse_usage_exporter_container_labels_traefik_enabled controls whether labels to assist a Traefik reverse-proxy will be attached to the container.
|
|
# See `../templates/labels.j2` for details.
|
|
#
|
|
# To inject your own other container labels, see `matrix_synapse_usage_exporter_container_labels_additional_labels`.
|
|
matrix_synapse_usage_exporter_container_labels_traefik_enabled: true
|
|
matrix_synapse_usage_exporter_container_labels_traefik_docker_network: "{{ matrix_synapse_usage_exporter_container_network }}"
|
|
|
|
# Controls whether labels will be added that expose the usage-stats ingestion endpoint (see `matrix_synapse_usage_exporter_proxying_enabled`)
|
|
matrix_synapse_usage_exporter_container_labels_traefik_usage_stats_enabled: "{{ matrix_synapse_usage_exporter_proxying_enabled }}"
|
|
matrix_synapse_usage_exporter_container_labels_traefik_path_prefix: "{{ matrix_synapse_usage_exporter_path_prefix }}"
|
|
matrix_synapse_usage_exporter_container_labels_traefik_rule: "Host(`{{ matrix_synapse_usage_exporter_hostname }}`) && PathPrefix(`{{ matrix_synapse_usage_exporter_container_labels_traefik_path_prefix }}`)"
|
|
matrix_synapse_usage_exporter_container_labels_traefik_priority: 0
|
|
matrix_synapse_usage_exporter_container_labels_traefik_entrypoints: "web-secure"
|
|
matrix_synapse_usage_exporter_container_labels_traefik_tls: "{{ matrix_synapse_usage_exporter_container_labels_traefik_entrypoints != 'web' }}"
|
|
matrix_synapse_usage_exporter_container_labels_traefik_tls_certResolver: default # noqa var-naming
|
|
|
|
# Controls whether labels will be added that expose the metrics endpoint (see `matrix_synapse_usage_exporter_metrics_proxying_enabled`)
|
|
matrix_synapse_usage_exporter_container_labels_traefik_metrics_enabled: "{{ matrix_synapse_usage_exporter_metrics_proxying_enabled }}"
|
|
matrix_synapse_usage_exporter_container_labels_traefik_metrics_path: "{{ matrix_synapse_usage_exporter_metrics_proxying_path }}"
|
|
matrix_synapse_usage_exporter_container_labels_traefik_metrics_rule: "Host(`{{ matrix_synapse_usage_exporter_metrics_proxying_hostname }}`) && Path(`{{ matrix_synapse_usage_exporter_container_labels_traefik_metrics_path }}`)"
|
|
matrix_synapse_usage_exporter_container_labels_traefik_metrics_priority: 0
|
|
matrix_synapse_usage_exporter_container_labels_traefik_metrics_entrypoints: "{{ matrix_synapse_usage_exporter_container_labels_traefik_entrypoints }}"
|
|
matrix_synapse_usage_exporter_container_labels_traefik_metrics_tls: "{{ matrix_synapse_usage_exporter_container_labels_traefik_metrics_entrypoints != 'web' }}"
|
|
matrix_synapse_usage_exporter_container_labels_traefik_metrics_tls_certResolver: "{{ matrix_synapse_usage_exporter_container_labels_traefik_tls_certResolver }}" # noqa var-naming
|
|
|
|
matrix_synapse_usage_exporter_container_labels_traefik_metrics_middleware_basic_auth_enabled: false
|
|
# See: https://doc.traefik.io/traefik/middlewares/http/basicauth/#users
|
|
matrix_synapse_usage_exporter_container_labels_traefik_metrics_middleware_basic_auth_users: ''
|
|
|
|
# matrix_synapse_usage_exporter_container_labels_additional_labels contains a multiline string with additional labels to add to the container label file.
|
|
# See `../templates/labels.j2` for details.
|
|
#
|
|
# Example:
|
|
# matrix_synapse_usage_exporter_container_labels_additional_labels: |
|
|
# my.label=1
|
|
# another.label="here"
|
|
matrix_synapse_usage_exporter_container_labels_additional_labels: ''
|
|
|
|
# matrix_synapse_usage_exporter_dashboard_urls contains a list of URLs with Grafana dashboard definitions.
|
|
# If the Grafana role is enabled, these dashboards will be downloaded.
|
|
matrix_synapse_usage_exporter_dashboard_urls:
|
|
- https://raw.githubusercontent.com/spantaleev/matrix-docker-ansible-deploy/master/roles/custom/matrix-synapse-usage-exporter/templates/grafana/synapse-usage-exporter.json
|
|
|
|
# matrix_synapse_usage_exporter_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_usage_exporter_restart_necessary: false
|