Files
matrix-docker-ansible-deploy/roles/custom/matrix-bot-maubot/defaults/main.yml
T
Slavi PantaleevandClaude Opus 5.5 bff3f54d53 Harden pre-start container cleanup against name-release races
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>
2026-10-16 19:04:04 +03:00

220 lines
13 KiB
YAML

# SPDX-FileCopyrightText: 2022 - 2025 Slavi Pantaleev
# SPDX-FileCopyrightText: 2022 Julian-Samuel Gebühr
# SPDX-FileCopyrightText: 2022 Stuart Mumford
# SPDX-FileCopyrightText: 2023 Nikita Chernyi
# SPDX-FileCopyrightText: 2023 Samuel Meenzen
# SPDX-FileCopyrightText: 2023 Shreyas Ajjarapu
# SPDX-FileCopyrightText: 2024 Fabio Bonelli
#
# SPDX-License-Identifier: AGPL-3.0-or-later
---
# maubot is a plugin-based Matrix bot system.
# Project source code URL: https://mau.dev/maubot/maubot
matrix_bot_maubot_enabled: true
matrix_bot_maubot_login: bot.maubot
# This is just initial password and it will not manage subsequent password changes.
# Use a tool like synapse-admin if you need to change it.
matrix_bot_maubot_initial_password: ''
matrix_bot_maubot_scheme: https
matrix_bot_maubot_hostname: ''
# The path at which maubot is exposed.
# This value must either be `/` or not end with a slash (e.g. `/_matrix/maubot`).
matrix_bot_maubot_path_prefix: /_matrix/maubot
matrix_bot_maubot_container_image_self_build: false
matrix_bot_maubot_container_repo: "https://mau.dev/maubot/maubot.git"
matrix_bot_maubot_container_repo_version: "{{ 'master' if matrix_bot_maubot_version == 'latest' else matrix_bot_maubot_version }}"
# renovate: datasource=docker depName=dock.mau.dev/maubot/maubot
matrix_bot_maubot_version: v0.6.0
matrix_bot_maubot_container_image: "{{ matrix_bot_maubot_container_image_registry_prefix }}maubot/maubot:{{ matrix_bot_maubot_version }}"
matrix_bot_maubot_container_image_registry_prefix: "{{ 'localhost/' if matrix_bot_maubot_container_image_self_build else matrix_bot_maubot_container_image_registry_prefix_upstream }}"
matrix_bot_maubot_container_image_registry_prefix_upstream: "{{ matrix_bot_maubot_container_image_registry_prefix_upstream_default }}"
matrix_bot_maubot_container_image_registry_prefix_upstream_default: "dock.mau.dev/"
# matrix_bot_maubot_container_image_customized is the name of the locally built maubot image
# which adds various customizations on top of the original (upstream) maubot image.
# This image will be based on the upstream `matrix_bot_maubot_container_image` image, only if `matrix_bot_maubot_container_image_customizations_enabled: true`.
matrix_bot_maubot_container_image_customized: "localhost/maubot/maubot:{{ matrix_bot_maubot_version }}-customized"
# Controls whether the customized image (`matrix_bot_maubot_container_image_customized`) is to be force-built without layer caching enabled.
matrix_bot_maubot_container_image_customized_build_nocache: false
# Controls whether the customized image (`matrix_bot_maubot_container_image_customized`) is to be built, even if it already exists.
# Related to: matrix_bot_maubot_container_image_customized_build_nocache
matrix_bot_maubot_container_image_customized_force_source: "{{ matrix_bot_maubot_container_image_customized_build_nocache }}"
# matrix_bot_maubot_container_image_final holds the name of the maubot image to run depending on whether or not customizations are enabled.
matrix_bot_maubot_container_image_final: "{{ matrix_bot_maubot_container_image_customized if matrix_bot_maubot_container_image_customizations_enabled else matrix_bot_maubot_container_image }} "
matrix_bot_maubot_base_path: "{{ matrix_base_data_path }}/maubot"
matrix_bot_maubot_data_path: "{{ matrix_bot_maubot_base_path }}/data"
matrix_bot_maubot_config_path: "{{ matrix_bot_maubot_base_path }}/config"
matrix_bot_maubot_container_src_files_path: "{{ matrix_bot_maubot_base_path }}/docker-src"
matrix_bot_maubot_customized_container_src_files_path: "{{ matrix_bot_maubot_base_path }}/customized-docker-src"
# Traefik strips the path prefix before proxying, so maubot sees relative paths internally.
matrix_bot_maubot_bot_server_public_url: "{{ matrix_bot_maubot_scheme }}://{{ matrix_bot_maubot_hostname }}{{ '' if matrix_bot_maubot_path_prefix == '/' else matrix_bot_maubot_path_prefix }}"
matrix_bot_maubot_bot_server_ui_base_path: /
matrix_bot_maubot_bot_server_plugin_base_path: /plugin/
matrix_bot_maubot_proxy_management_interface: true
matrix_bot_maubot_database_engine: sqlite
matrix_bot_maubot_sqlite_database_path_local: "{{ matrix_bot_maubot_data_path }}/maubot.db"
matrix_bot_maubot_sqlite_database_path_in_container: "/data/maubot.db"
matrix_bot_maubot_database_username: matrix_bot_maubot
matrix_bot_maubot_database_password: ~
matrix_bot_maubot_database_hostname: ''
matrix_bot_maubot_database_port: 5432
matrix_bot_maubot_database_name: matrix_bot_maubot
matrix_bot_maubot_database_sslmode: disable
matrix_bot_maubot_database_connection_string: postgres://{{ matrix_bot_maubot_database_username }}:{{ matrix_bot_maubot_database_password }}@{{ matrix_bot_maubot_database_hostname }}:{{ matrix_bot_maubot_database_port }}/{{ matrix_bot_maubot_database_name }}?sslmode={{ matrix_bot_maubot_database_sslmode }}
matrix_bot_maubot_database_uri: "{{ {
'sqlite': ('sqlite:///' + matrix_bot_maubot_sqlite_database_path_in_container),
'postgres': matrix_bot_maubot_database_connection_string,
}[matrix_bot_maubot_database_engine] }}"
# Defines the port number where the management interface is
# To actually expose the management interface outside of the container, use `matrix_bot_maubot_container_management_interface_http_bind_port`
matrix_bot_maubot_server_port: 29316
matrix_bot_maubot_unshared_secret: 'generate'
matrix_bot_maubot_homeserver_name: "{{ matrix_domain }}"
matrix_bot_maubot_homeserver_url: ""
matrix_bot_maubot_homeserver_secret: ""
matrix_bot_maubot_admins: []
# Specifies the default log level for all bot loggers.
matrix_bot_maubot_logging_level: WARNING
# Controls whether the maubot container exposes its HTTP management interface port (tcp/29316 in the container).
#
# Takes an "<ip>:<port>" or "<port>" value (e.g. "127.0.0.1:29316"), or empty string to not expose.
# If you'll be setting this at all, it should be defined in terms of `matrix_bot_maubot_server_port`.
# Example:
# matrix_bot_maubot_container_management_interface_http_bind_port: "127.0.0.1:{{ matrix_bot_maubot_server_port }}"
matrix_bot_maubot_container_management_interface_http_bind_port: ''
matrix_bot_maubot_container_network: ""
matrix_bot_maubot_container_additional_networks: "{{ matrix_bot_maubot_container_additional_networks_auto + matrix_bot_maubot_container_additional_networks_custom }}"
matrix_bot_maubot_container_additional_networks_auto: []
matrix_bot_maubot_container_additional_networks_custom: []
# matrix_bot_maubot_container_image_customizations_enabled controls whether a customized maubot image will be built.
#
# We toggle this variable to `true` when certain features which require a custom build are enabled.
# Feel free to toggle this to `true` yourself and specify build steps in `matrix_bot_maubot_container_image_customizations_dockerfile_body_custom`.
#
# See:
# - `roles/custom/matrix-bot-maubot/templates/maubot/customizations/Dockerfile.j2`
# - `matrix_bot_maubot_container_image_customizations_dockerfile_body_custom`
# - `matrix_bot_maubot_container_image_customized`
# - `matrix_bot_maubot_container_image_final`
matrix_bot_maubot_container_image_customizations_enabled: false
# matrix_bot_maubot_container_image_customizations_dockerfile_body contains your custom Dockerfile steps
# for building your customized maubot image based on the original (upstream) image (`matrix_bot_maubot_container_image`).
# A `FROM …` clause is included automatically so you don't have to.
#
# For this to take effect, you need to enable customizations (`matrix_bot_maubot_container_image_customizations_enabled: true`).
#
# Example:
# matrix_bot_maubot_container_image_customizations_dockerfile_body_custom: |
# RUN echo 'This is a custom step for building the customized container image for maubot.'
# RUN echo 'You can override matrix_bot_maubot_container_image_customizations_dockerfile_body_custom to add your own steps.'
# RUN echo 'You do NOT need to include a FROM clause yourself.'
matrix_bot_maubot_container_image_customizations_dockerfile_body_custom: ''
# matrix_bot_maubot_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_bot_maubot_container_labels_additional_labels`.
matrix_bot_maubot_container_labels_traefik_enabled: true
matrix_bot_maubot_container_labels_traefik_docker_network: "{{ matrix_bot_maubot_container_network }}"
matrix_bot_maubot_container_labels_traefik_entrypoints: web-secure
matrix_bot_maubot_container_labels_traefik_tls_certResolver: default # noqa var-naming
# Controls whether labels will be added that expose maubot's management endpoints
matrix_bot_maubot_container_labels_management_enabled: true
matrix_bot_maubot_container_labels_management_hostname: "{{ matrix_bot_maubot_hostname }}"
matrix_bot_maubot_container_labels_management_prefix: "{{ matrix_bot_maubot_path_prefix }}"
matrix_bot_maubot_container_labels_management_traefik_rule: "Host(`{{ matrix_bot_maubot_container_labels_management_hostname }}`) && PathPrefix(`{{ matrix_bot_maubot_container_labels_management_prefix }}`)"
matrix_bot_maubot_container_labels_management_traefik_priority: 0
matrix_bot_maubot_container_labels_management_traefik_entrypoints: "{{ matrix_bot_maubot_container_labels_traefik_entrypoints }}"
matrix_bot_maubot_container_labels_management_traefik_tls: "{{ matrix_bot_maubot_container_labels_management_traefik_entrypoints != 'web' }}"
matrix_bot_maubot_container_labels_management_traefik_tls_certResolver: "{{ matrix_bot_maubot_container_labels_traefik_tls_certResolver }}" # noqa var-naming
# matrix_bot_maubot_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_bot_maubot_container_labels_additional_labels: |
# my.label=1
# another.label="here"
matrix_bot_maubot_container_labels_additional_labels: ''
# A list of extra arguments to pass to the container
matrix_bot_maubot_container_extra_arguments: []
# Controls how long the pre-start cleanup should wait for stale container-name release
# before failing startup explicitly.
matrix_bot_maubot_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}"
# Controls the delay between pre-start cleanup retries.
matrix_bot_maubot_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_bot_maubot_container_cleanup_command: |
i=0;
while [ "$i" -lt {{ matrix_bot_maubot_container_cleanup_timeout_seconds }} ]; do
{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-bot-maubot >/dev/null 2>&1 || true;
{{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-bot-maubot >/dev/null 2>&1 || true;
if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-bot-maubot >/dev/null 2>&1; then
i=$((i + 1));
sleep {{ matrix_bot_maubot_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-bot-maubot" >&2;
exit 1;
done;
echo "Failed to remove stale container matrix-bot-maubot after {{ matrix_bot_maubot_container_cleanup_timeout_seconds }} attempts" >&2;
exit 1
# List of systemd services that matrix-bot-maubot.service depends on
matrix_bot_maubot_systemd_required_services_list: "{{ matrix_bot_maubot_systemd_required_services_list_default + matrix_bot_maubot_systemd_required_services_list_auto + matrix_bot_maubot_systemd_required_services_list_custom }}"
matrix_bot_maubot_systemd_required_services_list_default: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}"
matrix_bot_maubot_systemd_required_services_list_auto: []
matrix_bot_maubot_systemd_required_services_list_custom: []
# List of systemd services that matrix-bot-maubot.service wants
matrix_bot_maubot_systemd_wanted_services_list: []
# matrix_bot_maubot_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_bot_maubot_restart_necessary: false