Files
matrix-docker-ansible-deploy/roles/custom/matrix-bridge-postmoogle/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

223 lines
10 KiB
YAML

# SPDX-FileCopyrightText: 2022 - 2024 Nikita Chernyi
# SPDX-FileCopyrightText: 2022 - 2025 Slavi Pantaleev
# SPDX-FileCopyrightText: 2023 Luke D Iremadze
# SPDX-FileCopyrightText: 2023 Samuel Meenzen
# SPDX-FileCopyrightText: 2024 - 2025 Suguru Hirahara
#
# SPDX-License-Identifier: AGPL-3.0-or-later
---
# postmoogle is an email to Matrix bridge using its bot user
# Project source code URL: https://github.com/etkecc/postmoogle
matrix_bridge_postmoogle_enabled: true
matrix_bridge_postmoogle_container_image_self_build: false
matrix_bridge_postmoogle_container_repo: "https://github.com/etkecc/postmoogle.git"
matrix_bridge_postmoogle_container_repo_version: "{{ 'main' if matrix_bridge_postmoogle_version == 'latest' else matrix_bridge_postmoogle_version }}"
matrix_bridge_postmoogle_container_src_files_path: "{{ matrix_base_data_path }}/postmoogle/docker-src"
# renovate: datasource=docker depName=ghcr.io/etkecc/postmoogle
matrix_bridge_postmoogle_version: v0.9.31
matrix_bridge_postmoogle_container_image: "{{ matrix_bridge_postmoogle_container_image_registry_prefix }}etkecc/postmoogle:{{ matrix_bridge_postmoogle_version }}"
matrix_bridge_postmoogle_container_image_registry_prefix: "{{ 'localhost/' if matrix_bridge_postmoogle_container_image_self_build else matrix_bridge_postmoogle_container_image_registry_prefix_upstream }}"
matrix_bridge_postmoogle_container_image_registry_prefix_upstream: "{{ matrix_bridge_postmoogle_container_image_registry_prefix_upstream_default }}"
matrix_bridge_postmoogle_container_image_registry_prefix_upstream_default: "ghcr.io/"
matrix_bridge_postmoogle_base_path: "{{ matrix_base_data_path }}/postmoogle"
matrix_bridge_postmoogle_config_path: "{{ matrix_bridge_postmoogle_base_path }}/config"
matrix_bridge_postmoogle_data_path: "{{ matrix_bridge_postmoogle_base_path }}/data"
matrix_bridge_postmoogle_container_network: ""
matrix_bridge_postmoogle_container_additional_networks: "{{ matrix_bridge_postmoogle_container_additional_networks_auto + matrix_bridge_postmoogle_container_additional_networks_custom }}"
matrix_bridge_postmoogle_container_additional_networks_auto: []
matrix_bridge_postmoogle_container_additional_networks_custom: []
# A list of extra arguments to pass to the container
matrix_bridge_postmoogle_container_extra_arguments: []
# Controls how long the pre-start cleanup should wait for stale container-name release
# before failing startup explicitly.
matrix_bridge_postmoogle_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}"
# Controls the delay between pre-start cleanup retries.
matrix_bridge_postmoogle_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_bridge_postmoogle_container_cleanup_command: |
i=0;
while [ "$i" -lt {{ matrix_bridge_postmoogle_container_cleanup_timeout_seconds }} ]; do
{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-postmoogle >/dev/null 2>&1 || true;
{{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-postmoogle >/dev/null 2>&1 || true;
if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-postmoogle >/dev/null 2>&1; then
i=$((i + 1));
sleep {{ matrix_bridge_postmoogle_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-postmoogle" >&2;
exit 1;
done;
echo "Failed to remove stale container matrix-postmoogle after {{ matrix_bridge_postmoogle_container_cleanup_timeout_seconds }} attempts" >&2;
exit 1
# List of systemd services that matrix-postmoogle.service depends on
matrix_bridge_postmoogle_systemd_required_services_list: "{{ matrix_bridge_postmoogle_systemd_required_services_list_default + matrix_bridge_postmoogle_systemd_required_services_list_auto + matrix_bridge_postmoogle_systemd_required_services_list_custom }}"
matrix_bridge_postmoogle_systemd_required_services_list_default: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}"
matrix_bridge_postmoogle_systemd_required_services_list_auto: []
matrix_bridge_postmoogle_systemd_required_services_list_custom: []
# List of systemd services that matrix-postmoogle.service wants
matrix_bridge_postmoogle_systemd_wanted_services_list: []
# Database-related configuration fields.
#
# To use SQLite, stick to these defaults.
#
# To use Postgres:
# - change the engine (`matrix_bridge_postmoogle_database_engine: 'postgres'`)
# - adjust your database credentials via the `matrix_bridge_postmoogle_database_*` variables
matrix_bridge_postmoogle_database_engine: 'sqlite'
matrix_bridge_postmoogle_sqlite_database_path_local: "{{ matrix_bridge_postmoogle_data_path }}/bot.db"
matrix_bridge_postmoogle_sqlite_database_path_in_container: "/data/bot.db"
matrix_bridge_postmoogle_database_username: 'postmoogle'
matrix_bridge_postmoogle_database_password: 'some-password'
matrix_bridge_postmoogle_database_hostname: ''
matrix_bridge_postmoogle_database_port: 5432
matrix_bridge_postmoogle_database_name: 'postmoogle'
matrix_bridge_postmoogle_database_sslmode: disable
matrix_bridge_postmoogle_database_connection_string: 'postgres://{{ matrix_bridge_postmoogle_database_username }}:{{ matrix_bridge_postmoogle_database_password }}@{{ matrix_bridge_postmoogle_database_hostname }}:{{ matrix_bridge_postmoogle_database_port }}/{{ matrix_bridge_postmoogle_database_name }}?sslmode={{ matrix_bridge_postmoogle_database_sslmode }}'
matrix_bridge_postmoogle_storage_database: "{{ {
'sqlite': matrix_bridge_postmoogle_sqlite_database_path_in_container,
'postgres': matrix_bridge_postmoogle_database_connection_string,
}[matrix_bridge_postmoogle_database_engine] }}"
matrix_bridge_postmoogle_database_dialect: "{{ {
'sqlite': 'sqlite3',
'postgres': 'postgres',
}[matrix_bridge_postmoogle_database_engine] }}"
# The bot's username. This user needs to be created manually beforehand.
# Also see `matrix_bridge_postmoogle_password` or `matrix_bridge_postmoogle_sharedsecret`
matrix_bridge_postmoogle_login: "postmoogle"
# The password that the bot uses to authenticate.
matrix_bridge_postmoogle_password: ''
# Alternative to password - shared secret requires matrix_bridge_postmoogle_login to be MXID
matrix_bridge_postmoogle_sharedsecret: ''
matrix_bridge_postmoogle_homeserver: ""
# Command prefix
matrix_bridge_postmoogle_prefix: '!pm'
# Max email size in megabytes, including attachments
matrix_bridge_postmoogle_maxsize: '1024'
# Optional SMTP relay mode
matrix_bridge_postmoogle_relay_host: ''
matrix_bridge_postmoogle_relay_port: ''
matrix_bridge_postmoogle_relay_username: ''
matrix_bridge_postmoogle_relay_password: ''
# A list of admins
# Example set of rules:
# matrix_bridge_postmoogle_admins:
# - '@alice:example.com'
# - '@bob:example.com'
# - '@bot.*:example.com'
# - '@*:example.net'
matrix_bridge_postmoogle_admins: "{{ [matrix_admin] if matrix_admin else [] }}"
# Sentry DSN. Deprecated, use matrix_bridge_postmoogle_monitoring_sentry_dsn
matrix_bridge_postmoogle_sentry: ''
# Sentry integration
matrix_bridge_postmoogle_monitoring_sentry_dsn: "{{ matrix_bridge_postmoogle_sentry }}"
matrix_bridge_postmoogle_monitoring_sentry_rate: 20
# healthchecks.io integration
matrix_bridge_postmoogle_monitoring_healthchecks_uuid: ''
matrix_bridge_postmoogle_monitoring_healthchecks_duration: 60
# Log level
matrix_bridge_postmoogle_loglevel: 'INFO'
# deprecated, use matrix_bridge_postmoogle_domains
matrix_bridge_postmoogle_domain: "{{ matrix_server_fqn_matrix }}"
matrix_bridge_postmoogle_domains:
- "{{ matrix_bridge_postmoogle_domain }}" # backward compatibility
# Password (passphrase) to encrypt account data
matrix_bridge_postmoogle_data_secret: ""
# in-container ports
matrix_bridge_postmoogle_port: '2525'
matrix_bridge_postmoogle_tls_port: '25587'
# on-host ports
matrix_bridge_postmoogle_smtp_host_bind_port: '25'
matrix_bridge_postmoogle_submission_host_bind_port: '587'
### SSL
## on-host SSL dir
matrix_bridge_postmoogle_ssl_path: ""
## in-container SSL paths
# matrix_bridge_postmoogle_tls_cert is the SSL certificates' certificates.
# This var is likely set via group_vars/matrix_servers, so you don't need to set certs manually.
# If you do need to set it manually, note that this is an in-container path.
# To mount a certificates volumes into the container, use matrix_bridge_postmoogle_ssl_path
# Example value: /ssl/live/{{ matrix_bridge_postmoogle_domain }}/fullchain.pem
matrix_bridge_postmoogle_tls_cert: ""
# matrix_bridge_postmoogle_tls_key is the SSL certificates' keys.
# This var is likely set via group_vars/matrix_servers, so you don't need to set keys manually.
# If you do need to set it manually, note that this is an in-container path.
# To mount a certificates volumes into the container, use matrix_bridge_postmoogle_ssl_path
# Example value: /ssl/live/{{ matrix_bridge_postmoogle_domain }}/privkey.pem
matrix_bridge_postmoogle_tls_key: ""
# Mandatory TLS, even on plain SMTP port
matrix_bridge_postmoogle_tls_required: false
# trusted proxies
matrix_bridge_postmoogle_proxies: []
# known forwarders
matrix_bridge_postmoogle_mailboxes_forwarded: []
# reserved mailboxes
matrix_bridge_postmoogle_mailboxes_reserved: []
# mailbox activation flow
matrix_bridge_postmoogle_mailboxes_activation: none
# Additional environment variables to pass to the postmoogle container
#
# Example:
# matrix_bridge_postmoogle_environment_variables_extension: |
# postmoogle_TEXT_DONE=Done
matrix_bridge_postmoogle_environment_variables_extension: ''
# matrix_bridge_postmoogle_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_bridge_postmoogle_restart_necessary: false