From bff3f54d5380ce673e1f9e88c90b888fdc494513 Mon Sep 17 00:00:00 2001 From: Slavi Pantaleev Date: Fri, 16 Oct 2026 19:04:04 +0300 Subject: [PATCH] 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) --- .../defaults/main.yml | 28 +++++ .../matrix-alertmanager-receiver.service.j2 | 3 +- .../defaults/main.yml | 28 +++++ ...rix-appservice-draupnir-for-all.service.j2 | 3 +- .../defaults/main.yml | 28 +++++ .../matrix-authentication-service.service.j2 | 3 +- .../matrix-bot-baibot/defaults/main.yml | 28 +++++ .../systemd/matrix-bot-baibot.service.j2 | 3 +- .../matrix-bot-buscarron/defaults/main.yml | 28 +++++ .../systemd/matrix-bot-buscarron.service.j2 | 3 +- .../matrix-bot-draupnir/defaults/main.yml | 28 +++++ .../systemd/matrix-bot-draupnir.service.j2 | 3 +- .../matrix-bot-honoroit/defaults/main.yml | 28 +++++ .../systemd/matrix-bot-honoroit.service.j2 | 3 +- .../defaults/main.yml | 28 +++++ .../matrix-bot-matrix-reminder-bot.service.j2 | 3 +- .../matrix-bot-maubot/defaults/main.yml | 28 +++++ .../systemd/matrix-bot-maubot.service.j2 | 3 +- .../matrix-bot-meowlnir/defaults/main.yml | 28 +++++ .../systemd/matrix-bot-meowlnir.service.j2 | 3 +- .../matrix-bot-mjolnir/defaults/main.yml | 28 +++++ .../systemd/matrix-bot-mjolnir.service.j2 | 3 +- .../defaults/main.yml | 28 +++++ .../matrix-appservice-discord.service.j2 | 3 +- .../defaults/main.yml | 28 +++++ .../systemd/matrix-appservice-irc.service.j2 | 3 +- .../defaults/main.yml | 28 +++++ .../systemd/matrix-beeper-line.service.j2 | 3 +- .../defaults/main.yml | 28 +++++ .../systemd/matrix-beeper-linkedin.service.j2 | 3 +- .../defaults/main.yml | 28 +++++ .../systemd/matrix-heisenbridge.service.j2 | 3 +- .../matrix-bridge-hookshot/defaults/main.yml | 28 +++++ .../systemd/matrix-hookshot.service.j2 | 3 +- .../defaults/main.yml | 28 +++++ .../systemd/matrix-mautrix-bluesky.service.j2 | 3 +- .../defaults/main.yml | 28 +++++ .../systemd/matrix-mautrix-discord.service.j2 | 3 +- .../defaults/main.yml | 28 +++++ .../matrix-mautrix-gmessages.service.j2 | 3 +- .../defaults/main.yml | 28 +++++ .../matrix-mautrix-googlechat.service.j2 | 3 +- .../defaults/main.yml | 28 +++++ .../systemd/matrix-mautrix-gvoice.service.j2 | 3 +- .../defaults/main.yml | 28 +++++ .../matrix-mautrix-linkedin.service.j2 | 3 +- .../defaults/main.yml | 28 +++++ .../matrix-mautrix-meta-instagram.service.j2 | 3 +- .../defaults/main.yml | 28 +++++ .../matrix-mautrix-meta-messenger.service.j2 | 3 +- .../defaults/main.yml | 28 +++++ .../systemd/matrix-mautrix-signal.service.j2 | 3 +- .../defaults/main.yml | 28 +++++ .../systemd/matrix-mautrix-slack.service.j2 | 3 +- .../defaults/main.yml | 28 +++++ .../matrix-mautrix-telegram.service.j2 | 3 +- .../defaults/main.yml | 28 +++++ .../systemd/matrix-mautrix-twitter.service.j2 | 3 +- .../defaults/main.yml | 28 +++++ .../matrix-mautrix-whatsapp.service.j2 | 3 +- .../defaults/main.yml | 56 +++++++++ ...atrix-mautrix-wsproxy-syncproxy.service.j2 | 3 +- .../systemd/matrix-mautrix-wsproxy.service.j2 | 3 +- .../defaults/main.yml | 28 +++++ .../matrix-meshtastic-relay.service.j2 | 3 +- .../defaults/main.yml | 28 +++++ .../matrix-mx-puppet-groupme.service.j2 | 3 +- .../defaults/main.yml | 28 +++++ .../systemd/matrix-mx-puppet-steam.service.j2 | 3 +- .../defaults/main.yml | 28 +++++ .../systemd/matrix-postmoogle.service.j2 | 3 +- .../matrix-bridge-rustpush/defaults/main.yml | 28 +++++ .../systemd/matrix-rustpush-bridge.service.j2 | 3 +- .../matrix-bridge-sms/defaults/main.yml | 28 +++++ .../systemd/matrix-sms-bridge.service.j2 | 3 +- .../matrix-bridge-steam/defaults/main.yml | 28 +++++ .../systemd/matrix-steam-bridge.service.j2 | 3 +- .../matrix-bridge-wechat/defaults/main.yml | 56 +++++++++ .../systemd/matrix-wechat-agent.service.j2 | 3 +- .../systemd/matrix-wechat.service.j2 | 3 +- .../defaults/main.yml | 28 +++++ .../matrix-cactus-comments-client.service.j2 | 3 +- .../matrix-cactus-comments/defaults/main.yml | 28 +++++ .../systemd/matrix-cactus-comments.service.j2 | 3 +- .../matrix-client-commet/defaults/main.yml | 28 +++++ .../systemd/matrix-client-commet.service.j2 | 3 +- .../matrix-client-element/defaults/main.yml | 28 +++++ .../systemd/matrix-client-element.service.j2 | 3 +- .../defaults/main.yml | 28 +++++ .../matrix-client-fluffychat.service.j2 | 3 +- .../defaults/main.yml | 28 +++++ .../matrix-client-schildichat.service.j2 | 3 +- roles/custom/matrix-conduit/defaults/main.yml | 28 +++++ .../systemd/matrix-conduit.service.j2 | 3 +- .../matrix-continuwuity/defaults/main.yml | 28 +++++ .../systemd/matrix-continuwuity.service.j2 | 3 +- .../custom/matrix-corporal/defaults/main.yml | 28 +++++ .../systemd/matrix-corporal.service.j2 | 3 +- .../custom/matrix-dendrite/defaults/main.yml | 28 +++++ .../systemd/matrix-dendrite.service.j2 | 3 +- .../matrix-element-admin/defaults/main.yml | 28 +++++ .../systemd/matrix-element-admin.service.j2 | 3 +- .../matrix-element-call/defaults/main.yml | 28 +++++ .../systemd/matrix-element-call.service.j2 | 3 +- roles/custom/matrix-ketesa/defaults/main.yml | 28 +++++ .../systemd/matrix-ketesa.service.j2 | 3 +- .../defaults/main.yml | 28 +++++ .../matrix-livekit-jwt-service.service.j2 | 3 +- .../custom/matrix-matrixto/defaults/main.yml | 28 +++++ .../systemd/matrix-matrixto.service.j2 | 3 +- .../matrix-media-repo/defaults/main.yml | 28 +++++ .../systemd/matrix-media-repo.service.j2 | 3 +- .../matrix-pantalaimon/defaults/main.yml | 28 +++++ .../systemd/matrix-pantalaimon.service.j2 | 3 +- .../custom/matrix-rageshake/defaults/main.yml | 28 +++++ .../systemd/matrix-rageshake.service.j2 | 3 +- .../matrix-static-files/defaults/main.yml | 28 +++++ .../systemd/matrix-static-files.service.j2 | 3 +- roles/custom/matrix-sygnal/defaults/main.yml | 28 +++++ .../systemd/matrix-sygnal.service.j2 | 3 +- .../defaults/main.yml | 28 +++++ .../matrix-synapse-auto-compressor.service.j2 | 3 +- .../defaults/main.yml | 28 +++++ .../matrix-synapse-usage-exporter.service.j2 | 3 +- roles/custom/matrix-synapse/defaults/main.yml | 113 ++++++++++++++++++ .../goofys/systemd/matrix-goofys.service.j2 | 3 +- ...synapse-reverse-proxy-companion.service.j2 | 3 +- .../systemd/matrix-synapse-worker.service.j2 | 3 +- .../synapse/systemd/matrix-synapse.service.j2 | 3 +- roles/custom/matrix-tuwunel/defaults/main.yml | 28 +++++ .../systemd/matrix-tuwunel.service.j2 | 3 +- .../defaults/main.yml | 28 +++++ ...atrix-user-verification-service.service.j2 | 3 +- 133 files changed, 2002 insertions(+), 138 deletions(-) diff --git a/roles/custom/matrix-alertmanager-receiver/defaults/main.yml b/roles/custom/matrix-alertmanager-receiver/defaults/main.yml index e0524111e..6a312bfa0 100644 --- a/roles/custom/matrix-alertmanager-receiver/defaults/main.yml +++ b/roles/custom/matrix-alertmanager-receiver/defaults/main.yml @@ -90,6 +90,34 @@ matrix_alertmanager_receiver_container_labels_additional_labels: '' # A list of extra arguments to pass to the container matrix_alertmanager_receiver_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_alertmanager_receiver_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_alertmanager_receiver_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_alertmanager_receiver_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_alertmanager_receiver_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-alertmanager-receiver >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-alertmanager-receiver >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-alertmanager-receiver >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_alertmanager_receiver_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-alertmanager-receiver" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-alertmanager-receiver after {{ matrix_alertmanager_receiver_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # Controls the `--log-level` argument passed to the container process. # Valid values: error, warn, info, debug matrix_alertmanager_receiver_container_process_argument_log_level: info diff --git a/roles/custom/matrix-alertmanager-receiver/templates/systemd/matrix-alertmanager-receiver.service.j2 b/roles/custom/matrix-alertmanager-receiver/templates/systemd/matrix-alertmanager-receiver.service.j2 index 07d7d31cd..56bf20bbb 100644 --- a/roles/custom/matrix-alertmanager-receiver/templates/systemd/matrix-alertmanager-receiver.service.j2 +++ b/roles/custom/matrix-alertmanager-receiver/templates/systemd/matrix-alertmanager-receiver.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-alertmanager-receiver 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-alertmanager-receiver 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_alertmanager_receiver_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-appservice-draupnir-for-all/defaults/main.yml b/roles/custom/matrix-appservice-draupnir-for-all/defaults/main.yml index 9d4278b57..9386bfcfb 100644 --- a/roles/custom/matrix-appservice-draupnir-for-all/defaults/main.yml +++ b/roles/custom/matrix-appservice-draupnir-for-all/defaults/main.yml @@ -37,6 +37,34 @@ matrix_appservice_draupnir_for_all_container_additional_networks_custom: [] # A list of extra arguments to pass to the container matrix_appservice_draupnir_for_all_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_appservice_draupnir_for_all_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_appservice_draupnir_for_all_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_appservice_draupnir_for_all_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_appservice_draupnir_for_all_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-appservice-draupnir-for-all >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-appservice-draupnir-for-all >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-appservice-draupnir-for-all >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_appservice_draupnir_for_all_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-appservice-draupnir-for-all" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-appservice-draupnir-for-all after {{ matrix_appservice_draupnir_for_all_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # List of systemd services that matrix-bot-draupnir.service depends on matrix_appservice_draupnir_for_all_systemd_required_services_list: "{{ matrix_appservice_draupnir_for_all_systemd_required_services_list_default + matrix_appservice_draupnir_for_all_systemd_required_services_list_auto + matrix_appservice_draupnir_for_all_systemd_required_services_list_custom }}" matrix_appservice_draupnir_for_all_systemd_required_services_list_default: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}" diff --git a/roles/custom/matrix-appservice-draupnir-for-all/templates/systemd/matrix-appservice-draupnir-for-all.service.j2 b/roles/custom/matrix-appservice-draupnir-for-all/templates/systemd/matrix-appservice-draupnir-for-all.service.j2 index 8dc631ad8..7c816ed63 100644 --- a/roles/custom/matrix-appservice-draupnir-for-all/templates/systemd/matrix-appservice-draupnir-for-all.service.j2 +++ b/roles/custom/matrix-appservice-draupnir-for-all/templates/systemd/matrix-appservice-draupnir-for-all.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-appservice-draupnir-for-all 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-appservice-draupnir-for-all 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_appservice_draupnir_for_all_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-authentication-service/defaults/main.yml b/roles/custom/matrix-authentication-service/defaults/main.yml index c76338e09..fc859f0a6 100644 --- a/roles/custom/matrix-authentication-service/defaults/main.yml +++ b/roles/custom/matrix-authentication-service/defaults/main.yml @@ -46,6 +46,34 @@ matrix_authentication_service_container_additional_networks_custom: [] # A list of extra arguments to pass to the container matrix_authentication_service_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_authentication_service_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_authentication_service_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_authentication_service_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_authentication_service_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-authentication-service >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-authentication-service >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-authentication-service >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_authentication_service_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-authentication-service" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-authentication-service after {{ matrix_authentication_service_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # List of systemd services that matrix-authentication-service.service depends on matrix_authentication_service_systemd_required_services_list: "{{ matrix_authentication_service_systemd_required_services_list_default + matrix_authentication_service_systemd_required_services_list_auto + matrix_authentication_service_systemd_required_services_list_custom }}" matrix_authentication_service_systemd_required_services_list_default: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}" diff --git a/roles/custom/matrix-authentication-service/templates/systemd/matrix-authentication-service.service.j2 b/roles/custom/matrix-authentication-service/templates/systemd/matrix-authentication-service.service.j2 index ceb353f22..401a33c66 100644 --- a/roles/custom/matrix-authentication-service/templates/systemd/matrix-authentication-service.service.j2 +++ b/roles/custom/matrix-authentication-service/templates/systemd/matrix-authentication-service.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-authentication-service 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-authentication-service 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_authentication_service_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-bot-baibot/defaults/main.yml b/roles/custom/matrix-bot-baibot/defaults/main.yml index 0ca4a6145..2d2ee78cd 100644 --- a/roles/custom/matrix-bot-baibot/defaults/main.yml +++ b/roles/custom/matrix-bot-baibot/defaults/main.yml @@ -36,6 +36,34 @@ matrix_bot_baibot_container_additional_networks_custom: [] # A list of extra arguments to pass to the container matrix_bot_baibot_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_bot_baibot_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_bot_baibot_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_baibot_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_bot_baibot_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-baibot >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-bot-baibot >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-bot-baibot >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_bot_baibot_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-baibot" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-bot-baibot after {{ matrix_bot_baibot_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # List of systemd services that matrix-bot-baibot.service depends on matrix_bot_baibot_systemd_required_services_list: "{{ matrix_bot_baibot_systemd_required_services_list_default + matrix_bot_baibot_systemd_required_services_list_auto + matrix_bot_baibot_systemd_required_services_list_custom }}" matrix_bot_baibot_systemd_required_services_list_default: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}" diff --git a/roles/custom/matrix-bot-baibot/templates/systemd/matrix-bot-baibot.service.j2 b/roles/custom/matrix-bot-baibot/templates/systemd/matrix-bot-baibot.service.j2 index 3483b086b..cc1e57b62 100644 --- a/roles/custom/matrix-bot-baibot/templates/systemd/matrix-bot-baibot.service.j2 +++ b/roles/custom/matrix-bot-baibot/templates/systemd/matrix-bot-baibot.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-bot-baibot 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-bot-baibot 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_bot_baibot_container_cleanup_command | trim | replace("\n", " ") }}' {# We mount a tmpfs at /tmp, because the bot may write temporary files there diff --git a/roles/custom/matrix-bot-buscarron/defaults/main.yml b/roles/custom/matrix-bot-buscarron/defaults/main.yml index 987fc7063..42db4efa6 100644 --- a/roles/custom/matrix-bot-buscarron/defaults/main.yml +++ b/roles/custom/matrix-bot-buscarron/defaults/main.yml @@ -105,6 +105,34 @@ matrix_bot_buscarron_container_labels_additional_labels: '' # A list of extra arguments to pass to the container matrix_bot_buscarron_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_bot_buscarron_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_bot_buscarron_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_buscarron_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_bot_buscarron_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-buscarron >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-bot-buscarron >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-bot-buscarron >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_bot_buscarron_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-buscarron" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-bot-buscarron after {{ matrix_bot_buscarron_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # List of systemd services that matrix-bot-buscarron.service depends on matrix_bot_buscarron_systemd_required_services_list: "{{ matrix_bot_buscarron_systemd_required_services_list_default + matrix_bot_buscarron_systemd_required_services_list_auto + matrix_bot_buscarron_systemd_required_services_list_custom }}" matrix_bot_buscarron_systemd_required_services_list_default: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}" diff --git a/roles/custom/matrix-bot-buscarron/templates/systemd/matrix-bot-buscarron.service.j2 b/roles/custom/matrix-bot-buscarron/templates/systemd/matrix-bot-buscarron.service.j2 index 69c22f4c4..675ad72b8 100644 --- a/roles/custom/matrix-bot-buscarron/templates/systemd/matrix-bot-buscarron.service.j2 +++ b/roles/custom/matrix-bot-buscarron/templates/systemd/matrix-bot-buscarron.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-bot-buscarron 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-bot-buscarron 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_bot_buscarron_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-bot-draupnir/defaults/main.yml b/roles/custom/matrix-bot-draupnir/defaults/main.yml index 9f819efe6..dd9adb058 100644 --- a/roles/custom/matrix-bot-draupnir/defaults/main.yml +++ b/roles/custom/matrix-bot-draupnir/defaults/main.yml @@ -68,6 +68,34 @@ matrix_bot_draupnir_container_http_host_bind_port: '' # A list of extra arguments to pass to the container matrix_bot_draupnir_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_bot_draupnir_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_bot_draupnir_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_draupnir_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_bot_draupnir_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-draupnir >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-bot-draupnir >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-bot-draupnir >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_bot_draupnir_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-draupnir" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-bot-draupnir after {{ matrix_bot_draupnir_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # List of systemd services that matrix-bot-draupnir.service depends on matrix_bot_draupnir_systemd_required_services_list: "{{ matrix_bot_draupnir_systemd_required_services_list_default + matrix_bot_draupnir_systemd_required_services_list_auto + matrix_bot_draupnir_systemd_required_services_list_custom }}" matrix_bot_draupnir_systemd_required_services_list_default: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}" diff --git a/roles/custom/matrix-bot-draupnir/templates/systemd/matrix-bot-draupnir.service.j2 b/roles/custom/matrix-bot-draupnir/templates/systemd/matrix-bot-draupnir.service.j2 index 75438e5b0..ffa52edf9 100644 --- a/roles/custom/matrix-bot-draupnir/templates/systemd/matrix-bot-draupnir.service.j2 +++ b/roles/custom/matrix-bot-draupnir/templates/systemd/matrix-bot-draupnir.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-bot-draupnir 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-bot-draupnir 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_bot_draupnir_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-bot-honoroit/defaults/main.yml b/roles/custom/matrix-bot-honoroit/defaults/main.yml index 7dbdff923..39d62f02e 100644 --- a/roles/custom/matrix-bot-honoroit/defaults/main.yml +++ b/roles/custom/matrix-bot-honoroit/defaults/main.yml @@ -86,6 +86,34 @@ matrix_bot_honoroit_container_labels_additional_labels: '' # A list of extra arguments to pass to the container matrix_bot_honoroit_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_bot_honoroit_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_bot_honoroit_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_honoroit_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_bot_honoroit_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-honoroit >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-bot-honoroit >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-bot-honoroit >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_bot_honoroit_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-honoroit" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-bot-honoroit after {{ matrix_bot_honoroit_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # List of systemd services that matrix-bot-honoroit.service depends on matrix_bot_honoroit_systemd_required_services_list: "{{ matrix_bot_honoroit_systemd_required_services_list_default + matrix_bot_honoroit_systemd_required_services_list_auto + matrix_bot_honoroit_systemd_required_services_list_custom }}" matrix_bot_honoroit_systemd_required_services_list_default: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}" diff --git a/roles/custom/matrix-bot-honoroit/templates/systemd/matrix-bot-honoroit.service.j2 b/roles/custom/matrix-bot-honoroit/templates/systemd/matrix-bot-honoroit.service.j2 index dd802eb6b..4eb0d2634 100644 --- a/roles/custom/matrix-bot-honoroit/templates/systemd/matrix-bot-honoroit.service.j2 +++ b/roles/custom/matrix-bot-honoroit/templates/systemd/matrix-bot-honoroit.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-bot-honoroit 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-bot-honoroit 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_bot_honoroit_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-bot-matrix-reminder-bot/defaults/main.yml b/roles/custom/matrix-bot-matrix-reminder-bot/defaults/main.yml index 9eb2d0662..db6a32e93 100644 --- a/roles/custom/matrix-bot-matrix-reminder-bot/defaults/main.yml +++ b/roles/custom/matrix-bot-matrix-reminder-bot/defaults/main.yml @@ -36,6 +36,34 @@ matrix_bot_matrix_reminder_bot_command_prefix: "!" # A list of extra arguments to pass to the container matrix_bot_matrix_reminder_bot_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_bot_matrix_reminder_bot_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_bot_matrix_reminder_bot_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_matrix_reminder_bot_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_bot_matrix_reminder_bot_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-matrix-reminder-bot >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-bot-matrix-reminder-bot >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-bot-matrix-reminder-bot >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_bot_matrix_reminder_bot_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-matrix-reminder-bot" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-bot-matrix-reminder-bot after {{ matrix_bot_matrix_reminder_bot_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + matrix_bot_matrix_reminder_bot_container_network: "" matrix_bot_matrix_reminder_bot_container_additional_networks: "{{ matrix_bot_matrix_reminder_bot_container_additional_networks_auto + matrix_bot_matrix_reminder_bot_container_additional_networks_custom }}" diff --git a/roles/custom/matrix-bot-matrix-reminder-bot/templates/systemd/matrix-bot-matrix-reminder-bot.service.j2 b/roles/custom/matrix-bot-matrix-reminder-bot/templates/systemd/matrix-bot-matrix-reminder-bot.service.j2 index 263ca1131..1c44f198a 100644 --- a/roles/custom/matrix-bot-matrix-reminder-bot/templates/systemd/matrix-bot-matrix-reminder-bot.service.j2 +++ b/roles/custom/matrix-bot-matrix-reminder-bot/templates/systemd/matrix-bot-matrix-reminder-bot.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-bot-matrix-reminder-bot 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-bot-matrix-reminder-bot 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_bot_matrix_reminder_bot_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-bot-maubot/defaults/main.yml b/roles/custom/matrix-bot-maubot/defaults/main.yml index 8fabf24dd..90537a958 100644 --- a/roles/custom/matrix-bot-maubot/defaults/main.yml +++ b/roles/custom/matrix-bot-maubot/defaults/main.yml @@ -171,6 +171,34 @@ 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 [] }}" diff --git a/roles/custom/matrix-bot-maubot/templates/systemd/matrix-bot-maubot.service.j2 b/roles/custom/matrix-bot-maubot/templates/systemd/matrix-bot-maubot.service.j2 index 6e0206f8f..49fbc1a02 100644 --- a/roles/custom/matrix-bot-maubot/templates/systemd/matrix-bot-maubot.service.j2 +++ b/roles/custom/matrix-bot-maubot/templates/systemd/matrix-bot-maubot.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-bot-maubot 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-bot-maubot 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_bot_maubot_container_cleanup_command | trim | replace("\n", " ") }}' {# We mount a tmpfs at /tmp, because some maubot plugins may wish to write to it. diff --git a/roles/custom/matrix-bot-meowlnir/defaults/main.yml b/roles/custom/matrix-bot-meowlnir/defaults/main.yml index 7afb90cd1..829eed1f5 100644 --- a/roles/custom/matrix-bot-meowlnir/defaults/main.yml +++ b/roles/custom/matrix-bot-meowlnir/defaults/main.yml @@ -41,6 +41,34 @@ matrix_bot_meowlnir_container_http_host_bind_port: '' # A list of extra arguments to pass to the container matrix_bot_meowlnir_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_bot_meowlnir_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_bot_meowlnir_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_meowlnir_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_bot_meowlnir_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-meowlnir >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-bot-meowlnir >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-bot-meowlnir >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_bot_meowlnir_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-meowlnir" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-bot-meowlnir after {{ matrix_bot_meowlnir_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # List of systemd services that matrix-bot-meowlnir.service depends on matrix_bot_meowlnir_systemd_required_services_list: "{{ matrix_bot_meowlnir_systemd_required_services_list_default + matrix_bot_meowlnir_systemd_required_services_list_auto + matrix_bot_meowlnir_systemd_required_services_list_custom }}" matrix_bot_meowlnir_systemd_required_services_list_default: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}" diff --git a/roles/custom/matrix-bot-meowlnir/templates/systemd/matrix-bot-meowlnir.service.j2 b/roles/custom/matrix-bot-meowlnir/templates/systemd/matrix-bot-meowlnir.service.j2 index 4dc51b7e8..aa5a8dfbc 100644 --- a/roles/custom/matrix-bot-meowlnir/templates/systemd/matrix-bot-meowlnir.service.j2 +++ b/roles/custom/matrix-bot-meowlnir/templates/systemd/matrix-bot-meowlnir.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-bot-meowlnir 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-bot-meowlnir 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_bot_meowlnir_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-bot-mjolnir/defaults/main.yml b/roles/custom/matrix-bot-mjolnir/defaults/main.yml index 30e5f3fe9..a379de6bd 100644 --- a/roles/custom/matrix-bot-mjolnir/defaults/main.yml +++ b/roles/custom/matrix-bot-mjolnir/defaults/main.yml @@ -41,6 +41,34 @@ matrix_bot_mjolnir_container_additional_networks_custom: [] # A list of extra arguments to pass to the container matrix_bot_mjolnir_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_bot_mjolnir_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_bot_mjolnir_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_mjolnir_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_bot_mjolnir_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-mjolnir >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-bot-mjolnir >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-bot-mjolnir >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_bot_mjolnir_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-mjolnir" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-bot-mjolnir after {{ matrix_bot_mjolnir_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # List of systemd services that matrix-bot-mjolnir.service depends on matrix_bot_mjolnir_systemd_required_services_list: "{{ matrix_bot_mjolnir_systemd_required_services_list_default + matrix_bot_mjolnir_systemd_required_services_list_auto + matrix_bot_mjolnir_systemd_required_services_list_custom }}" matrix_bot_mjolnir_systemd_required_services_list_default: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}" diff --git a/roles/custom/matrix-bot-mjolnir/templates/systemd/matrix-bot-mjolnir.service.j2 b/roles/custom/matrix-bot-mjolnir/templates/systemd/matrix-bot-mjolnir.service.j2 index 840264c7e..2abd1a148 100644 --- a/roles/custom/matrix-bot-mjolnir/templates/systemd/matrix-bot-mjolnir.service.j2 +++ b/roles/custom/matrix-bot-mjolnir/templates/systemd/matrix-bot-mjolnir.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-bot-mjolnir 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-bot-mjolnir 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_bot_mjolnir_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-bridge-appservice-discord/defaults/main.yml b/roles/custom/matrix-bridge-appservice-discord/defaults/main.yml index 440a7f409..b66a4a380 100644 --- a/roles/custom/matrix-bridge-appservice-discord/defaults/main.yml +++ b/roles/custom/matrix-bridge-appservice-discord/defaults/main.yml @@ -51,6 +51,34 @@ matrix_bridge_appservice_discord_container_additional_networks_custom: [] # A list of extra arguments to pass to the container matrix_bridge_appservice_discord_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_bridge_appservice_discord_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_bridge_appservice_discord_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_appservice_discord_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_bridge_appservice_discord_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-appservice-discord >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-appservice-discord >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-appservice-discord >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_bridge_appservice_discord_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-appservice-discord" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-appservice-discord after {{ matrix_bridge_appservice_discord_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # List of systemd services that matrix-appservice-discord.service depends on. matrix_bridge_appservice_discord_systemd_required_services_list: "{{ matrix_bridge_appservice_discord_systemd_required_services_list_default + matrix_bridge_appservice_discord_systemd_required_services_list_auto + matrix_bridge_appservice_discord_systemd_required_services_list_custom }}" matrix_bridge_appservice_discord_systemd_required_services_list_default: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}" diff --git a/roles/custom/matrix-bridge-appservice-discord/templates/systemd/matrix-appservice-discord.service.j2 b/roles/custom/matrix-bridge-appservice-discord/templates/systemd/matrix-appservice-discord.service.j2 index 0d7beae30..740e07351 100644 --- a/roles/custom/matrix-bridge-appservice-discord/templates/systemd/matrix-appservice-discord.service.j2 +++ b/roles/custom/matrix-bridge-appservice-discord/templates/systemd/matrix-appservice-discord.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-appservice-discord 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-appservice-discord 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_bridge_appservice_discord_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-bridge-appservice-irc/defaults/main.yml b/roles/custom/matrix-bridge-appservice-irc/defaults/main.yml index 692edd6dd..240cb50bc 100644 --- a/roles/custom/matrix-bridge-appservice-irc/defaults/main.yml +++ b/roles/custom/matrix-bridge-appservice-irc/defaults/main.yml @@ -487,6 +487,34 @@ matrix_bridge_appservice_irc_container_additional_networks_custom: [] # A list of extra arguments to pass to the container matrix_bridge_appservice_irc_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_bridge_appservice_irc_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_bridge_appservice_irc_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_appservice_irc_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_bridge_appservice_irc_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-appservice-irc >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-appservice-irc >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-appservice-irc >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_bridge_appservice_irc_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-appservice-irc" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-appservice-irc after {{ matrix_bridge_appservice_irc_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # matrix_bridge_appservice_irc_container_labels_traefik_enabled controls whether labels to assist a Traefik reverse-proxy will be attached to the container. # To inject your own other container labels, see `matrix_bridge_appservice_irc_container_labels_additional_labels`. matrix_bridge_appservice_irc_container_labels_traefik_enabled: true diff --git a/roles/custom/matrix-bridge-appservice-irc/templates/systemd/matrix-appservice-irc.service.j2 b/roles/custom/matrix-bridge-appservice-irc/templates/systemd/matrix-appservice-irc.service.j2 index 881d7940f..f32f3b24a 100644 --- a/roles/custom/matrix-bridge-appservice-irc/templates/systemd/matrix-appservice-irc.service.j2 +++ b/roles/custom/matrix-bridge-appservice-irc/templates/systemd/matrix-appservice-irc.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-appservice-irc 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-appservice-irc 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_bridge_appservice_irc_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-bridge-beeper-line/defaults/main.yml b/roles/custom/matrix-bridge-beeper-line/defaults/main.yml index 7d07a77a8..d9148f34b 100644 --- a/roles/custom/matrix-bridge-beeper-line/defaults/main.yml +++ b/roles/custom/matrix-bridge-beeper-line/defaults/main.yml @@ -93,6 +93,34 @@ matrix_bridge_beeper_line_container_labels_additional_labels: '' # A list of extra arguments to pass to the container matrix_bridge_beeper_line_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_bridge_beeper_line_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_bridge_beeper_line_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_beeper_line_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_bridge_beeper_line_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-beeper-line >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-beeper-line >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-beeper-line >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_bridge_beeper_line_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-beeper-line" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-beeper-line after {{ matrix_bridge_beeper_line_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # List of systemd services that matrix-beeper-line.service depends on. matrix_bridge_beeper_line_systemd_required_services_list: "{{ matrix_bridge_beeper_line_systemd_required_services_list_default + matrix_bridge_beeper_line_systemd_required_services_list_auto + matrix_bridge_beeper_line_systemd_required_services_list_custom }}" matrix_bridge_beeper_line_systemd_required_services_list_default: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}" diff --git a/roles/custom/matrix-bridge-beeper-line/templates/systemd/matrix-beeper-line.service.j2 b/roles/custom/matrix-bridge-beeper-line/templates/systemd/matrix-beeper-line.service.j2 index a8787f180..75d037da2 100644 --- a/roles/custom/matrix-bridge-beeper-line/templates/systemd/matrix-beeper-line.service.j2 +++ b/roles/custom/matrix-bridge-beeper-line/templates/systemd/matrix-beeper-line.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-beeper-line 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-beeper-line 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_bridge_beeper_line_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-bridge-beeper-linkedin/defaults/main.yml b/roles/custom/matrix-bridge-beeper-linkedin/defaults/main.yml index 1f342e347..62364d31b 100644 --- a/roles/custom/matrix-bridge-beeper-linkedin/defaults/main.yml +++ b/roles/custom/matrix-bridge-beeper-linkedin/defaults/main.yml @@ -62,6 +62,34 @@ matrix_bridge_beeper_linkedin_container_additional_networks_custom: [] # A list of extra arguments to pass to the container matrix_bridge_beeper_linkedin_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_bridge_beeper_linkedin_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_bridge_beeper_linkedin_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_beeper_linkedin_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_bridge_beeper_linkedin_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-beeper-linkedin >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-beeper-linkedin >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-beeper-linkedin >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_bridge_beeper_linkedin_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-beeper-linkedin" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-beeper-linkedin after {{ matrix_bridge_beeper_linkedin_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # List of systemd services that matrix-beeper-linkedin.service depends on. matrix_bridge_beeper_linkedin_systemd_required_services_list: "{{ matrix_bridge_beeper_linkedin_systemd_required_services_list_default + matrix_bridge_beeper_linkedin_systemd_required_services_list_auto + matrix_bridge_beeper_linkedin_systemd_required_services_list_custom }}" matrix_bridge_beeper_linkedin_systemd_required_services_list_default: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}" diff --git a/roles/custom/matrix-bridge-beeper-linkedin/templates/systemd/matrix-beeper-linkedin.service.j2 b/roles/custom/matrix-bridge-beeper-linkedin/templates/systemd/matrix-beeper-linkedin.service.j2 index faf4aa61d..34a24312d 100644 --- a/roles/custom/matrix-bridge-beeper-linkedin/templates/systemd/matrix-beeper-linkedin.service.j2 +++ b/roles/custom/matrix-bridge-beeper-linkedin/templates/systemd/matrix-beeper-linkedin.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-beeper-linkedin 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-beeper-linkedin 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_bridge_beeper_linkedin_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-bridge-heisenbridge/defaults/main.yml b/roles/custom/matrix-bridge-heisenbridge/defaults/main.yml index 73306c13e..e83999ef8 100644 --- a/roles/custom/matrix-bridge-heisenbridge/defaults/main.yml +++ b/roles/custom/matrix-bridge-heisenbridge/defaults/main.yml @@ -77,6 +77,34 @@ matrix_bridge_heisenbridge_container_labels_additional_labels: '' # A list of extra arguments to pass to the container matrix_bridge_heisenbridge_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_bridge_heisenbridge_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_bridge_heisenbridge_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_heisenbridge_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_bridge_heisenbridge_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ matrix_bridge_heisenbridge_container_stop_grace_time_seconds }} matrix-heisenbridge >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-heisenbridge >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-heisenbridge >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_bridge_heisenbridge_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-heisenbridge" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-heisenbridge after {{ matrix_bridge_heisenbridge_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # List of systemd services that service depends on. matrix_bridge_heisenbridge_systemd_required_services_list: "{{ matrix_bridge_heisenbridge_systemd_required_services_list_default + matrix_bridge_heisenbridge_systemd_required_services_list_auto + matrix_bridge_heisenbridge_systemd_required_services_list_custom }}" matrix_bridge_heisenbridge_systemd_required_services_list_default: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}" diff --git a/roles/custom/matrix-bridge-heisenbridge/templates/systemd/matrix-heisenbridge.service.j2 b/roles/custom/matrix-bridge-heisenbridge/templates/systemd/matrix-heisenbridge.service.j2 index e164cc6b9..9558be8f5 100644 --- a/roles/custom/matrix-bridge-heisenbridge/templates/systemd/matrix-heisenbridge.service.j2 +++ b/roles/custom/matrix-bridge-heisenbridge/templates/systemd/matrix-heisenbridge.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ matrix_bridge_heisenbridge_container_stop_grace_time_seconds }} matrix-heisenbridge -ExecStartPre=-{{ devture_systemd_docker_base_host_command_docker }} rm matrix-heisenbridge +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_bridge_heisenbridge_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-bridge-hookshot/defaults/main.yml b/roles/custom/matrix-bridge-hookshot/defaults/main.yml index 7b0940ed1..4a5a8ef1b 100644 --- a/roles/custom/matrix-bridge-hookshot/defaults/main.yml +++ b/roles/custom/matrix-bridge-hookshot/defaults/main.yml @@ -262,6 +262,34 @@ matrix_bridge_hookshot_container_network: "" # A list of extra arguments to pass to the container matrix_bridge_hookshot_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_bridge_hookshot_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_bridge_hookshot_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_hookshot_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_bridge_hookshot_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} {{ matrix_bridge_hookshot_identifier }} >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f {{ matrix_bridge_hookshot_identifier }} >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect {{ matrix_bridge_hookshot_identifier }} >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_bridge_hookshot_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_bridge_hookshot_identifier }}" >&2; + exit 1; + done; + echo "Failed to remove stale container {{ matrix_bridge_hookshot_identifier }} after {{ matrix_bridge_hookshot_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # matrix_bridge_hookshot_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. # diff --git a/roles/custom/matrix-bridge-hookshot/templates/systemd/matrix-hookshot.service.j2 b/roles/custom/matrix-bridge-hookshot/templates/systemd/matrix-hookshot.service.j2 index cea9184eb..f234eff25 100644 --- a/roles/custom/matrix-bridge-hookshot/templates/systemd/matrix-hookshot.service.j2 +++ b/roles/custom/matrix-bridge-hookshot/templates/systemd/matrix-hookshot.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} {{ matrix_bridge_hookshot_identifier }} -ExecStartPre=-{{ devture_systemd_docker_base_host_command_docker }} rm {{ matrix_bridge_hookshot_identifier }} +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_bridge_hookshot_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create --rm --name {{ matrix_bridge_hookshot_identifier }} \ --log-driver=none \ --user={{ matrix_user_uid }}:{{ matrix_user_gid }} \ diff --git a/roles/custom/matrix-bridge-mautrix-bluesky/defaults/main.yml b/roles/custom/matrix-bridge-mautrix-bluesky/defaults/main.yml index 2f141e943..7571dc77a 100644 --- a/roles/custom/matrix-bridge-mautrix-bluesky/defaults/main.yml +++ b/roles/custom/matrix-bridge-mautrix-bluesky/defaults/main.yml @@ -92,6 +92,34 @@ matrix_bridge_mautrix_bluesky_container_labels_additional_labels: '' # A list of extra arguments to pass to the container matrix_bridge_mautrix_bluesky_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_bridge_mautrix_bluesky_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_bridge_mautrix_bluesky_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_mautrix_bluesky_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_bridge_mautrix_bluesky_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-mautrix-bluesky >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-mautrix-bluesky >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-mautrix-bluesky >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_bridge_mautrix_bluesky_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-mautrix-bluesky" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-mautrix-bluesky after {{ matrix_bridge_mautrix_bluesky_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # List of systemd services that matrix-mautrix-bluesky.service depends on. matrix_bridge_mautrix_bluesky_systemd_required_services_list: "{{ matrix_bridge_mautrix_bluesky_systemd_required_services_list_default + matrix_bridge_mautrix_bluesky_systemd_required_services_list_auto + matrix_bridge_mautrix_bluesky_systemd_required_services_list_custom }}" matrix_bridge_mautrix_bluesky_systemd_required_services_list_default: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}" diff --git a/roles/custom/matrix-bridge-mautrix-bluesky/templates/systemd/matrix-mautrix-bluesky.service.j2 b/roles/custom/matrix-bridge-mautrix-bluesky/templates/systemd/matrix-mautrix-bluesky.service.j2 index 589d611fc..50d761a98 100644 --- a/roles/custom/matrix-bridge-mautrix-bluesky/templates/systemd/matrix-mautrix-bluesky.service.j2 +++ b/roles/custom/matrix-bridge-mautrix-bluesky/templates/systemd/matrix-mautrix-bluesky.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-mautrix-bluesky 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-mautrix-bluesky 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_bridge_mautrix_bluesky_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-bridge-mautrix-discord/defaults/main.yml b/roles/custom/matrix-bridge-mautrix-discord/defaults/main.yml index fea94dcf0..7ac82ec81 100644 --- a/roles/custom/matrix-bridge-mautrix-discord/defaults/main.yml +++ b/roles/custom/matrix-bridge-mautrix-discord/defaults/main.yml @@ -113,6 +113,34 @@ matrix_bridge_mautrix_discord_container_labels_additional_labels: '' # A list of extra arguments to pass to the container matrix_bridge_mautrix_discord_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_bridge_mautrix_discord_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_bridge_mautrix_discord_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_mautrix_discord_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_bridge_mautrix_discord_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-mautrix-discord >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-mautrix-discord >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-mautrix-discord >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_bridge_mautrix_discord_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-mautrix-discord" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-mautrix-discord after {{ matrix_bridge_mautrix_discord_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # List of systemd services that matrix-mautrix-discord.service depends on. matrix_bridge_mautrix_discord_systemd_required_services_list: "{{ matrix_bridge_mautrix_discord_systemd_required_services_list_default + matrix_bridge_mautrix_discord_systemd_required_services_list_auto + matrix_bridge_mautrix_discord_systemd_required_services_list_custom }}" matrix_bridge_mautrix_discord_systemd_required_services_list_default: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}" diff --git a/roles/custom/matrix-bridge-mautrix-discord/templates/systemd/matrix-mautrix-discord.service.j2 b/roles/custom/matrix-bridge-mautrix-discord/templates/systemd/matrix-mautrix-discord.service.j2 index 4817b2648..c17ac00d1 100644 --- a/roles/custom/matrix-bridge-mautrix-discord/templates/systemd/matrix-mautrix-discord.service.j2 +++ b/roles/custom/matrix-bridge-mautrix-discord/templates/systemd/matrix-mautrix-discord.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-mautrix-discord 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-mautrix-discord 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_bridge_mautrix_discord_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-bridge-mautrix-gmessages/defaults/main.yml b/roles/custom/matrix-bridge-mautrix-gmessages/defaults/main.yml index bb25f2885..3aa1a46cf 100644 --- a/roles/custom/matrix-bridge-mautrix-gmessages/defaults/main.yml +++ b/roles/custom/matrix-bridge-mautrix-gmessages/defaults/main.yml @@ -92,6 +92,34 @@ matrix_bridge_mautrix_gmessages_container_labels_additional_labels: '' # A list of extra arguments to pass to the container matrix_bridge_mautrix_gmessages_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_bridge_mautrix_gmessages_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_bridge_mautrix_gmessages_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_mautrix_gmessages_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_bridge_mautrix_gmessages_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-mautrix-gmessages >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-mautrix-gmessages >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-mautrix-gmessages >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_bridge_mautrix_gmessages_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-mautrix-gmessages" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-mautrix-gmessages after {{ matrix_bridge_mautrix_gmessages_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # List of systemd services that matrix-mautrix-gmessages.service depends on. matrix_bridge_mautrix_gmessages_systemd_required_services_list: "{{ matrix_bridge_mautrix_gmessages_systemd_required_services_list_default + matrix_bridge_mautrix_gmessages_systemd_required_services_list_auto + matrix_bridge_mautrix_gmessages_systemd_required_services_list_custom }}" matrix_bridge_mautrix_gmessages_systemd_required_services_list_default: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}" diff --git a/roles/custom/matrix-bridge-mautrix-gmessages/templates/systemd/matrix-mautrix-gmessages.service.j2 b/roles/custom/matrix-bridge-mautrix-gmessages/templates/systemd/matrix-mautrix-gmessages.service.j2 index 6a39d46d9..15b164f98 100644 --- a/roles/custom/matrix-bridge-mautrix-gmessages/templates/systemd/matrix-mautrix-gmessages.service.j2 +++ b/roles/custom/matrix-bridge-mautrix-gmessages/templates/systemd/matrix-mautrix-gmessages.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-mautrix-gmessages 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-mautrix-gmessages 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_bridge_mautrix_gmessages_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-bridge-mautrix-googlechat/defaults/main.yml b/roles/custom/matrix-bridge-mautrix-googlechat/defaults/main.yml index 9553dd747..9d5c710e6 100644 --- a/roles/custom/matrix-bridge-mautrix-googlechat/defaults/main.yml +++ b/roles/custom/matrix-bridge-mautrix-googlechat/defaults/main.yml @@ -93,6 +93,34 @@ matrix_bridge_mautrix_googlechat_container_labels_additional_labels: '' # A list of extra arguments to pass to the container matrix_bridge_mautrix_googlechat_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_bridge_mautrix_googlechat_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_bridge_mautrix_googlechat_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_mautrix_googlechat_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_bridge_mautrix_googlechat_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-mautrix-googlechat >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-mautrix-googlechat >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-mautrix-googlechat >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_bridge_mautrix_googlechat_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-mautrix-googlechat" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-mautrix-googlechat after {{ matrix_bridge_mautrix_googlechat_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # List of systemd services that matrix-mautrix-googlechat.service depends on. matrix_bridge_mautrix_googlechat_systemd_required_services_list: "{{ matrix_bridge_mautrix_googlechat_systemd_required_services_list_default + matrix_bridge_mautrix_googlechat_systemd_required_services_list_auto + matrix_bridge_mautrix_googlechat_systemd_required_services_list_custom }}" matrix_bridge_mautrix_googlechat_systemd_required_services_list_default: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}" diff --git a/roles/custom/matrix-bridge-mautrix-googlechat/templates/systemd/matrix-mautrix-googlechat.service.j2 b/roles/custom/matrix-bridge-mautrix-googlechat/templates/systemd/matrix-mautrix-googlechat.service.j2 index 0a4d4f1e3..559a91d2c 100644 --- a/roles/custom/matrix-bridge-mautrix-googlechat/templates/systemd/matrix-mautrix-googlechat.service.j2 +++ b/roles/custom/matrix-bridge-mautrix-googlechat/templates/systemd/matrix-mautrix-googlechat.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-mautrix-googlechat 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-mautrix-googlechat 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_bridge_mautrix_googlechat_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-bridge-mautrix-gvoice/defaults/main.yml b/roles/custom/matrix-bridge-mautrix-gvoice/defaults/main.yml index 5ed8a929d..ca6be6e2e 100644 --- a/roles/custom/matrix-bridge-mautrix-gvoice/defaults/main.yml +++ b/roles/custom/matrix-bridge-mautrix-gvoice/defaults/main.yml @@ -88,6 +88,34 @@ matrix_bridge_mautrix_gvoice_container_labels_additional_labels: '' # A list of extra arguments to pass to the container matrix_bridge_mautrix_gvoice_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_bridge_mautrix_gvoice_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_bridge_mautrix_gvoice_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_mautrix_gvoice_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_bridge_mautrix_gvoice_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-mautrix-gvoice >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-mautrix-gvoice >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-mautrix-gvoice >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_bridge_mautrix_gvoice_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-mautrix-gvoice" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-mautrix-gvoice after {{ matrix_bridge_mautrix_gvoice_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # List of systemd services that matrix-mautrix-gvoice.service depends on. matrix_bridge_mautrix_gvoice_systemd_required_services_list: "{{ matrix_bridge_mautrix_gvoice_systemd_required_services_list_default + matrix_bridge_mautrix_gvoice_systemd_required_services_list_auto + matrix_bridge_mautrix_gvoice_systemd_required_services_list_custom }}" matrix_bridge_mautrix_gvoice_systemd_required_services_list_default: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}" diff --git a/roles/custom/matrix-bridge-mautrix-gvoice/templates/systemd/matrix-mautrix-gvoice.service.j2 b/roles/custom/matrix-bridge-mautrix-gvoice/templates/systemd/matrix-mautrix-gvoice.service.j2 index 127e2adbf..1b0f223de 100644 --- a/roles/custom/matrix-bridge-mautrix-gvoice/templates/systemd/matrix-mautrix-gvoice.service.j2 +++ b/roles/custom/matrix-bridge-mautrix-gvoice/templates/systemd/matrix-mautrix-gvoice.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-mautrix-gvoice 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-mautrix-gvoice 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_bridge_mautrix_gvoice_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-bridge-mautrix-linkedin/defaults/main.yml b/roles/custom/matrix-bridge-mautrix-linkedin/defaults/main.yml index 99fc6e40c..c14509cee 100644 --- a/roles/custom/matrix-bridge-mautrix-linkedin/defaults/main.yml +++ b/roles/custom/matrix-bridge-mautrix-linkedin/defaults/main.yml @@ -88,6 +88,34 @@ matrix_bridge_mautrix_linkedin_container_labels_additional_labels: '' # A list of extra arguments to pass to the container matrix_bridge_mautrix_linkedin_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_bridge_mautrix_linkedin_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_bridge_mautrix_linkedin_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_mautrix_linkedin_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_bridge_mautrix_linkedin_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-mautrix-linkedin >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-mautrix-linkedin >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-mautrix-linkedin >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_bridge_mautrix_linkedin_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-mautrix-linkedin" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-mautrix-linkedin after {{ matrix_bridge_mautrix_linkedin_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # List of systemd services that matrix-mautrix-linkedin.service depends on. matrix_bridge_mautrix_linkedin_systemd_required_services_list: "{{ matrix_bridge_mautrix_linkedin_systemd_required_services_list_default + matrix_bridge_mautrix_linkedin_systemd_required_services_list_auto + matrix_bridge_mautrix_linkedin_systemd_required_services_list_custom }}" matrix_bridge_mautrix_linkedin_systemd_required_services_list_default: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}" diff --git a/roles/custom/matrix-bridge-mautrix-linkedin/templates/systemd/matrix-mautrix-linkedin.service.j2 b/roles/custom/matrix-bridge-mautrix-linkedin/templates/systemd/matrix-mautrix-linkedin.service.j2 index edba7621d..63086c4b2 100644 --- a/roles/custom/matrix-bridge-mautrix-linkedin/templates/systemd/matrix-mautrix-linkedin.service.j2 +++ b/roles/custom/matrix-bridge-mautrix-linkedin/templates/systemd/matrix-mautrix-linkedin.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-mautrix-linkedin 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-mautrix-linkedin 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_bridge_mautrix_linkedin_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-bridge-mautrix-meta-instagram/defaults/main.yml b/roles/custom/matrix-bridge-mautrix-meta-instagram/defaults/main.yml index 210ed8c50..2ff394fed 100644 --- a/roles/custom/matrix-bridge-mautrix-meta-instagram/defaults/main.yml +++ b/roles/custom/matrix-bridge-mautrix-meta-instagram/defaults/main.yml @@ -80,6 +80,34 @@ matrix_bridge_mautrix_meta_instagram_container_labels_additional_labels: '' # A list of extra arguments to pass to the container matrix_bridge_mautrix_meta_instagram_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_bridge_mautrix_meta_instagram_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_bridge_mautrix_meta_instagram_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_mautrix_meta_instagram_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_bridge_mautrix_meta_instagram_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} {{ matrix_bridge_mautrix_meta_instagram_identifier }} >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f {{ matrix_bridge_mautrix_meta_instagram_identifier }} >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect {{ matrix_bridge_mautrix_meta_instagram_identifier }} >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_bridge_mautrix_meta_instagram_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_bridge_mautrix_meta_instagram_identifier }}" >&2; + exit 1; + done; + echo "Failed to remove stale container {{ matrix_bridge_mautrix_meta_instagram_identifier }} after {{ matrix_bridge_mautrix_meta_instagram_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # List of systemd services that the systemd service depends on. matrix_bridge_mautrix_meta_instagram_systemd_required_services_list: "{{ matrix_bridge_mautrix_meta_instagram_systemd_required_services_list_default + matrix_bridge_mautrix_meta_instagram_systemd_required_services_list_auto + matrix_bridge_mautrix_meta_instagram_systemd_required_services_list_custom }}" matrix_bridge_mautrix_meta_instagram_systemd_required_services_list_default: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}" diff --git a/roles/custom/matrix-bridge-mautrix-meta-instagram/templates/systemd/matrix-mautrix-meta-instagram.service.j2 b/roles/custom/matrix-bridge-mautrix-meta-instagram/templates/systemd/matrix-mautrix-meta-instagram.service.j2 index 824c9401a..49a572f15 100644 --- a/roles/custom/matrix-bridge-mautrix-meta-instagram/templates/systemd/matrix-mautrix-meta-instagram.service.j2 +++ b/roles/custom/matrix-bridge-mautrix-meta-instagram/templates/systemd/matrix-mautrix-meta-instagram.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} {{ matrix_bridge_mautrix_meta_instagram_identifier }} 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm {{ matrix_bridge_mautrix_meta_instagram_identifier }} 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_bridge_mautrix_meta_instagram_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-bridge-mautrix-meta-messenger/defaults/main.yml b/roles/custom/matrix-bridge-mautrix-meta-messenger/defaults/main.yml index f5f53c477..1c2fc909c 100644 --- a/roles/custom/matrix-bridge-mautrix-meta-messenger/defaults/main.yml +++ b/roles/custom/matrix-bridge-mautrix-meta-messenger/defaults/main.yml @@ -77,6 +77,34 @@ matrix_bridge_mautrix_meta_messenger_container_labels_additional_labels: '' # A list of extra arguments to pass to the container matrix_bridge_mautrix_meta_messenger_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_bridge_mautrix_meta_messenger_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_bridge_mautrix_meta_messenger_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_mautrix_meta_messenger_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_bridge_mautrix_meta_messenger_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} {{ matrix_bridge_mautrix_meta_messenger_identifier }} >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f {{ matrix_bridge_mautrix_meta_messenger_identifier }} >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect {{ matrix_bridge_mautrix_meta_messenger_identifier }} >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_bridge_mautrix_meta_messenger_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_bridge_mautrix_meta_messenger_identifier }}" >&2; + exit 1; + done; + echo "Failed to remove stale container {{ matrix_bridge_mautrix_meta_messenger_identifier }} after {{ matrix_bridge_mautrix_meta_messenger_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # List of systemd services that the systemd service depends on. matrix_bridge_mautrix_meta_messenger_systemd_required_services_list: "{{ matrix_bridge_mautrix_meta_messenger_systemd_required_services_list_default + matrix_bridge_mautrix_meta_messenger_systemd_required_services_list_auto + matrix_bridge_mautrix_meta_messenger_systemd_required_services_list_custom }}" matrix_bridge_mautrix_meta_messenger_systemd_required_services_list_default: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}" diff --git a/roles/custom/matrix-bridge-mautrix-meta-messenger/templates/systemd/matrix-mautrix-meta-messenger.service.j2 b/roles/custom/matrix-bridge-mautrix-meta-messenger/templates/systemd/matrix-mautrix-meta-messenger.service.j2 index c2f0a5380..dcbed5d6d 100644 --- a/roles/custom/matrix-bridge-mautrix-meta-messenger/templates/systemd/matrix-mautrix-meta-messenger.service.j2 +++ b/roles/custom/matrix-bridge-mautrix-meta-messenger/templates/systemd/matrix-mautrix-meta-messenger.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} {{ matrix_bridge_mautrix_meta_messenger_identifier }} 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm {{ matrix_bridge_mautrix_meta_messenger_identifier }} 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_bridge_mautrix_meta_messenger_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-bridge-mautrix-signal/defaults/main.yml b/roles/custom/matrix-bridge-mautrix-signal/defaults/main.yml index c01bc2e28..65a003fa3 100644 --- a/roles/custom/matrix-bridge-mautrix-signal/defaults/main.yml +++ b/roles/custom/matrix-bridge-mautrix-signal/defaults/main.yml @@ -117,6 +117,34 @@ matrix_bridge_mautrix_signal_container_labels_additional_labels: '' # A list of extra arguments to pass to the container matrix_bridge_mautrix_signal_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_bridge_mautrix_signal_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_bridge_mautrix_signal_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_mautrix_signal_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_bridge_mautrix_signal_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-mautrix-signal >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-mautrix-signal >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-mautrix-signal >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_bridge_mautrix_signal_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-mautrix-signal" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-mautrix-signal after {{ matrix_bridge_mautrix_signal_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # List of systemd services that matrix-mautrix-signal.service depends on. matrix_bridge_mautrix_signal_systemd_required_services_list: "{{ matrix_bridge_mautrix_signal_systemd_required_services_list_default + matrix_bridge_mautrix_signal_systemd_required_services_list_auto + matrix_bridge_mautrix_signal_systemd_required_services_list_custom }}" matrix_bridge_mautrix_signal_systemd_required_services_list_default: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}" diff --git a/roles/custom/matrix-bridge-mautrix-signal/templates/systemd/matrix-mautrix-signal.service.j2 b/roles/custom/matrix-bridge-mautrix-signal/templates/systemd/matrix-mautrix-signal.service.j2 index b9ef31f69..a127ced26 100644 --- a/roles/custom/matrix-bridge-mautrix-signal/templates/systemd/matrix-mautrix-signal.service.j2 +++ b/roles/custom/matrix-bridge-mautrix-signal/templates/systemd/matrix-mautrix-signal.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-mautrix-signal 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-mautrix-signal 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_bridge_mautrix_signal_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-bridge-mautrix-slack/defaults/main.yml b/roles/custom/matrix-bridge-mautrix-slack/defaults/main.yml index 40046bc58..cd2d6da6a 100644 --- a/roles/custom/matrix-bridge-mautrix-slack/defaults/main.yml +++ b/roles/custom/matrix-bridge-mautrix-slack/defaults/main.yml @@ -111,6 +111,34 @@ matrix_bridge_mautrix_slack_container_labels_additional_labels: '' # A list of extra arguments to pass to the container matrix_bridge_mautrix_slack_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_bridge_mautrix_slack_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_bridge_mautrix_slack_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_mautrix_slack_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_bridge_mautrix_slack_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-mautrix-slack >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-mautrix-slack >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-mautrix-slack >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_bridge_mautrix_slack_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-mautrix-slack" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-mautrix-slack after {{ matrix_bridge_mautrix_slack_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # List of systemd services that matrix-mautrix-slack.service depends on. matrix_bridge_mautrix_slack_systemd_required_services_list: "{{ matrix_bridge_mautrix_slack_systemd_required_services_list_default + matrix_bridge_mautrix_slack_systemd_required_services_list_auto + matrix_bridge_mautrix_slack_systemd_required_services_list_custom }}" matrix_bridge_mautrix_slack_systemd_required_services_list_default: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}" diff --git a/roles/custom/matrix-bridge-mautrix-slack/templates/systemd/matrix-mautrix-slack.service.j2 b/roles/custom/matrix-bridge-mautrix-slack/templates/systemd/matrix-mautrix-slack.service.j2 index d4f8edd96..7ce27ad85 100644 --- a/roles/custom/matrix-bridge-mautrix-slack/templates/systemd/matrix-mautrix-slack.service.j2 +++ b/roles/custom/matrix-bridge-mautrix-slack/templates/systemd/matrix-mautrix-slack.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-mautrix-slack 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-mautrix-slack 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_bridge_mautrix_slack_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-bridge-mautrix-telegram/defaults/main.yml b/roles/custom/matrix-bridge-mautrix-telegram/defaults/main.yml index c7dbb494b..4e907decf 100644 --- a/roles/custom/matrix-bridge-mautrix-telegram/defaults/main.yml +++ b/roles/custom/matrix-bridge-mautrix-telegram/defaults/main.yml @@ -98,6 +98,34 @@ matrix_bridge_mautrix_telegram_container_labels_additional_labels: '' # A list of extra arguments to pass to the container matrix_bridge_mautrix_telegram_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_bridge_mautrix_telegram_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_bridge_mautrix_telegram_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_mautrix_telegram_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_bridge_mautrix_telegram_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-mautrix-telegram >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-mautrix-telegram >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-mautrix-telegram >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_bridge_mautrix_telegram_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-mautrix-telegram" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-mautrix-telegram after {{ matrix_bridge_mautrix_telegram_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # List of systemd services that matrix-mautrix-telegram.service depends on. matrix_bridge_mautrix_telegram_systemd_required_services_list: "{{ matrix_bridge_mautrix_telegram_systemd_required_services_list_default + matrix_bridge_mautrix_telegram_systemd_required_services_list_auto + matrix_bridge_mautrix_telegram_systemd_required_services_list_custom }}" matrix_bridge_mautrix_telegram_systemd_required_services_list_default: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}" diff --git a/roles/custom/matrix-bridge-mautrix-telegram/templates/systemd/matrix-mautrix-telegram.service.j2 b/roles/custom/matrix-bridge-mautrix-telegram/templates/systemd/matrix-mautrix-telegram.service.j2 index 177500a0a..391a7cc9c 100644 --- a/roles/custom/matrix-bridge-mautrix-telegram/templates/systemd/matrix-mautrix-telegram.service.j2 +++ b/roles/custom/matrix-bridge-mautrix-telegram/templates/systemd/matrix-mautrix-telegram.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-mautrix-telegram 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-mautrix-telegram 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_bridge_mautrix_telegram_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-bridge-mautrix-twitter/defaults/main.yml b/roles/custom/matrix-bridge-mautrix-twitter/defaults/main.yml index 0fc45ca11..f5bfb1989 100644 --- a/roles/custom/matrix-bridge-mautrix-twitter/defaults/main.yml +++ b/roles/custom/matrix-bridge-mautrix-twitter/defaults/main.yml @@ -100,6 +100,34 @@ matrix_bridge_mautrix_twitter_container_labels_additional_labels: '' # A list of extra arguments to pass to the container matrix_bridge_mautrix_twitter_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_bridge_mautrix_twitter_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_bridge_mautrix_twitter_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_mautrix_twitter_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_bridge_mautrix_twitter_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-mautrix-twitter >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-mautrix-twitter >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-mautrix-twitter >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_bridge_mautrix_twitter_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-mautrix-twitter" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-mautrix-twitter after {{ matrix_bridge_mautrix_twitter_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # List of systemd services that matrix-mautrix-twitter.service depends on. matrix_bridge_mautrix_twitter_systemd_required_services_list: "{{ matrix_bridge_mautrix_twitter_systemd_required_services_list_default + matrix_bridge_mautrix_twitter_systemd_required_services_list_auto + matrix_bridge_mautrix_twitter_systemd_required_services_list_custom }}" matrix_bridge_mautrix_twitter_systemd_required_services_list_default: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}" diff --git a/roles/custom/matrix-bridge-mautrix-twitter/templates/systemd/matrix-mautrix-twitter.service.j2 b/roles/custom/matrix-bridge-mautrix-twitter/templates/systemd/matrix-mautrix-twitter.service.j2 index 585e5023c..23c850d73 100644 --- a/roles/custom/matrix-bridge-mautrix-twitter/templates/systemd/matrix-mautrix-twitter.service.j2 +++ b/roles/custom/matrix-bridge-mautrix-twitter/templates/systemd/matrix-mautrix-twitter.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-mautrix-twitter 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-mautrix-twitter 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_bridge_mautrix_twitter_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-bridge-mautrix-whatsapp/defaults/main.yml b/roles/custom/matrix-bridge-mautrix-whatsapp/defaults/main.yml index 7e52d9b2c..5b46fa0f1 100644 --- a/roles/custom/matrix-bridge-mautrix-whatsapp/defaults/main.yml +++ b/roles/custom/matrix-bridge-mautrix-whatsapp/defaults/main.yml @@ -98,6 +98,34 @@ matrix_bridge_mautrix_whatsapp_container_labels_additional_labels: '' # A list of extra arguments to pass to the container matrix_bridge_mautrix_whatsapp_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_bridge_mautrix_whatsapp_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_bridge_mautrix_whatsapp_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_mautrix_whatsapp_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_bridge_mautrix_whatsapp_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-mautrix-whatsapp >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-mautrix-whatsapp >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-mautrix-whatsapp >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_bridge_mautrix_whatsapp_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-mautrix-whatsapp" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-mautrix-whatsapp after {{ matrix_bridge_mautrix_whatsapp_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # List of systemd services that matrix-mautrix-whatsapp.service depends on. matrix_bridge_mautrix_whatsapp_systemd_required_services_list: "{{ matrix_bridge_mautrix_whatsapp_systemd_required_services_list_default + matrix_bridge_mautrix_whatsapp_systemd_required_services_list_auto + matrix_bridge_mautrix_whatsapp_systemd_required_services_list_custom }}" matrix_bridge_mautrix_whatsapp_systemd_required_services_list_default: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}" diff --git a/roles/custom/matrix-bridge-mautrix-whatsapp/templates/systemd/matrix-mautrix-whatsapp.service.j2 b/roles/custom/matrix-bridge-mautrix-whatsapp/templates/systemd/matrix-mautrix-whatsapp.service.j2 index 5970dfd94..446a21956 100644 --- a/roles/custom/matrix-bridge-mautrix-whatsapp/templates/systemd/matrix-mautrix-whatsapp.service.j2 +++ b/roles/custom/matrix-bridge-mautrix-whatsapp/templates/systemd/matrix-mautrix-whatsapp.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-mautrix-whatsapp 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-mautrix-whatsapp 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_bridge_mautrix_whatsapp_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-bridge-mautrix-wsproxy/defaults/main.yml b/roles/custom/matrix-bridge-mautrix-wsproxy/defaults/main.yml index 8592b3529..f5f730198 100644 --- a/roles/custom/matrix-bridge-mautrix-wsproxy/defaults/main.yml +++ b/roles/custom/matrix-bridge-mautrix-wsproxy/defaults/main.yml @@ -70,6 +70,34 @@ matrix_bridge_mautrix_wsproxy_container_labels_additional_labels: '' # A list of extra arguments to pass to the container matrix_bridge_mautrix_wsproxy_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_bridge_mautrix_wsproxy_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_bridge_mautrix_wsproxy_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_mautrix_wsproxy_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_bridge_mautrix_wsproxy_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-mautrix-wsproxy >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-mautrix-wsproxy >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-mautrix-wsproxy >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_bridge_mautrix_wsproxy_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-mautrix-wsproxy" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-mautrix-wsproxy after {{ matrix_bridge_mautrix_wsproxy_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # List of systemd services that matrix-mautrix-wsproxy.service depends on. matrix_bridge_mautrix_wsproxy_systemd_required_services_list: "{{ matrix_bridge_mautrix_wsproxy_systemd_required_services_list_default + matrix_bridge_mautrix_wsproxy_systemd_required_services_list_auto + matrix_bridge_mautrix_wsproxy_systemd_required_services_list_custom }}" matrix_bridge_mautrix_wsproxy_systemd_required_services_list_default: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}" @@ -149,6 +177,34 @@ matrix_bridge_mautrix_wsproxy_syncproxy_version: latest matrix_bridge_mautrix_wsproxy_syncproxy_container_image: "dock.mau.dev/mautrix/syncproxy:{{ matrix_bridge_mautrix_wsproxy_syncproxy_version }}" matrix_bridge_mautrix_wsproxy_syncproxy_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_bridge_mautrix_wsproxy_syncproxy_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_bridge_mautrix_wsproxy_syncproxy_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_mautrix_wsproxy_syncproxy_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_bridge_mautrix_wsproxy_syncproxy_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-mautrix-wsproxy-syncproxy >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-mautrix-wsproxy-syncproxy >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-mautrix-wsproxy-syncproxy >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_bridge_mautrix_wsproxy_syncproxy_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-mautrix-wsproxy-syncproxy" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-mautrix-wsproxy-syncproxy after {{ matrix_bridge_mautrix_wsproxy_syncproxy_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + matrix_bridge_mautrix_wsproxy_syncproxy_systemd_required_services_list: |- {{ ([devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else []) diff --git a/roles/custom/matrix-bridge-mautrix-wsproxy/templates/systemd/matrix-mautrix-wsproxy-syncproxy.service.j2 b/roles/custom/matrix-bridge-mautrix-wsproxy/templates/systemd/matrix-mautrix-wsproxy-syncproxy.service.j2 index 32f60703c..b94aec4f7 100644 --- a/roles/custom/matrix-bridge-mautrix-wsproxy/templates/systemd/matrix-mautrix-wsproxy-syncproxy.service.j2 +++ b/roles/custom/matrix-bridge-mautrix-wsproxy/templates/systemd/matrix-mautrix-wsproxy-syncproxy.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-mautrix-wsproxy-syncproxy 2>/dev/null' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-mautrix-wsproxy-syncproxy 2>/dev/null' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_bridge_mautrix_wsproxy_syncproxy_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-bridge-mautrix-wsproxy/templates/systemd/matrix-mautrix-wsproxy.service.j2 b/roles/custom/matrix-bridge-mautrix-wsproxy/templates/systemd/matrix-mautrix-wsproxy.service.j2 index e1a91cebb..49c17b562 100644 --- a/roles/custom/matrix-bridge-mautrix-wsproxy/templates/systemd/matrix-mautrix-wsproxy.service.j2 +++ b/roles/custom/matrix-bridge-mautrix-wsproxy/templates/systemd/matrix-mautrix-wsproxy.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-mautrix-wsproxy 2>/dev/null' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-mautrix-wsproxy 2>/dev/null' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_bridge_mautrix_wsproxy_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create --rm --name matrix-mautrix-wsproxy \ --log-driver=none \ diff --git a/roles/custom/matrix-bridge-meshtastic-relay/defaults/main.yml b/roles/custom/matrix-bridge-meshtastic-relay/defaults/main.yml index 6d8130f85..fce9f1465 100644 --- a/roles/custom/matrix-bridge-meshtastic-relay/defaults/main.yml +++ b/roles/custom/matrix-bridge-meshtastic-relay/defaults/main.yml @@ -36,6 +36,34 @@ matrix_bridge_meshtastic_relay_container_additional_networks_custom: [] # A list of extra arguments to pass to the container matrix_bridge_meshtastic_relay_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_bridge_meshtastic_relay_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_bridge_meshtastic_relay_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_meshtastic_relay_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_bridge_meshtastic_relay_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-meshtastic-relay >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-meshtastic-relay >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-meshtastic-relay >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_bridge_meshtastic_relay_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-meshtastic-relay" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-meshtastic-relay after {{ matrix_bridge_meshtastic_relay_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # List of systemd services that matrix-meshtastic-relay.service depends on. matrix_bridge_meshtastic_relay_systemd_required_services_list: "{{ matrix_bridge_meshtastic_relay_systemd_required_services_list_default + matrix_bridge_meshtastic_relay_systemd_required_services_list_auto + matrix_bridge_meshtastic_relay_systemd_required_services_list_custom }}" matrix_bridge_meshtastic_relay_systemd_required_services_list_default: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}" diff --git a/roles/custom/matrix-bridge-meshtastic-relay/templates/systemd/matrix-meshtastic-relay.service.j2 b/roles/custom/matrix-bridge-meshtastic-relay/templates/systemd/matrix-meshtastic-relay.service.j2 index dfc2110de..3b36c2962 100644 --- a/roles/custom/matrix-bridge-meshtastic-relay/templates/systemd/matrix-meshtastic-relay.service.j2 +++ b/roles/custom/matrix-bridge-meshtastic-relay/templates/systemd/matrix-meshtastic-relay.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-meshtastic-relay -ExecStartPre=-{{ devture_systemd_docker_base_host_command_docker }} rm matrix-meshtastic-relay +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_bridge_meshtastic_relay_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-bridge-mx-puppet-groupme/defaults/main.yml b/roles/custom/matrix-bridge-mx-puppet-groupme/defaults/main.yml index 9321516c0..73bdb2817 100644 --- a/roles/custom/matrix-bridge-mx-puppet-groupme/defaults/main.yml +++ b/roles/custom/matrix-bridge-mx-puppet-groupme/defaults/main.yml @@ -61,6 +61,34 @@ matrix_bridge_mx_puppet_groupme_container_additional_networks_custom: [] # A list of extra arguments to pass to the container matrix_bridge_mx_puppet_groupme_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_bridge_mx_puppet_groupme_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_bridge_mx_puppet_groupme_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_mx_puppet_groupme_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_bridge_mx_puppet_groupme_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-mx-puppet-groupme >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-mx-puppet-groupme >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-mx-puppet-groupme >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_bridge_mx_puppet_groupme_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-mx-puppet-groupme" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-mx-puppet-groupme after {{ matrix_bridge_mx_puppet_groupme_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # List of systemd services that matrix-puppet-groupme.service depends on. matrix_bridge_mx_puppet_groupme_systemd_required_services_list: "{{ matrix_bridge_mx_puppet_groupme_systemd_required_services_list_default + matrix_bridge_mx_puppet_groupme_systemd_required_services_list_auto + matrix_bridge_mx_puppet_groupme_systemd_required_services_list_custom }}" matrix_bridge_mx_puppet_groupme_systemd_required_services_list_default: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}" diff --git a/roles/custom/matrix-bridge-mx-puppet-groupme/templates/systemd/matrix-mx-puppet-groupme.service.j2 b/roles/custom/matrix-bridge-mx-puppet-groupme/templates/systemd/matrix-mx-puppet-groupme.service.j2 index 46e3cf93f..2a052e030 100644 --- a/roles/custom/matrix-bridge-mx-puppet-groupme/templates/systemd/matrix-mx-puppet-groupme.service.j2 +++ b/roles/custom/matrix-bridge-mx-puppet-groupme/templates/systemd/matrix-mx-puppet-groupme.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-mx-puppet-groupme 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-mx-puppet-groupme 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_bridge_mx_puppet_groupme_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-bridge-mx-puppet-steam/defaults/main.yml b/roles/custom/matrix-bridge-mx-puppet-steam/defaults/main.yml index c02060a33..1d9ea44ad 100644 --- a/roles/custom/matrix-bridge-mx-puppet-steam/defaults/main.yml +++ b/roles/custom/matrix-bridge-mx-puppet-steam/defaults/main.yml @@ -62,6 +62,34 @@ matrix_bridge_mx_puppet_steam_container_additional_networks_custom: [] # A list of extra arguments to pass to the container matrix_bridge_mx_puppet_steam_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_bridge_mx_puppet_steam_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_bridge_mx_puppet_steam_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_mx_puppet_steam_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_bridge_mx_puppet_steam_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-mx-puppet-steam >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-mx-puppet-steam >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-mx-puppet-steam >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_bridge_mx_puppet_steam_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-mx-puppet-steam" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-mx-puppet-steam after {{ matrix_bridge_mx_puppet_steam_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # List of systemd services that matrix-puppet-steam.service depends on. matrix_bridge_mx_puppet_steam_systemd_required_services_list: "{{ matrix_bridge_mx_puppet_steam_systemd_required_services_list_default + matrix_bridge_mx_puppet_steam_systemd_required_services_list_auto + matrix_bridge_mx_puppet_steam_systemd_required_services_list_custom }}" matrix_bridge_mx_puppet_steam_systemd_required_services_list_default: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}" diff --git a/roles/custom/matrix-bridge-mx-puppet-steam/templates/systemd/matrix-mx-puppet-steam.service.j2 b/roles/custom/matrix-bridge-mx-puppet-steam/templates/systemd/matrix-mx-puppet-steam.service.j2 index 6913829da..3dbfb10e1 100644 --- a/roles/custom/matrix-bridge-mx-puppet-steam/templates/systemd/matrix-mx-puppet-steam.service.j2 +++ b/roles/custom/matrix-bridge-mx-puppet-steam/templates/systemd/matrix-mx-puppet-steam.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-mx-puppet-steam 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-mx-puppet-steam 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_bridge_mx_puppet_steam_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-bridge-postmoogle/defaults/main.yml b/roles/custom/matrix-bridge-postmoogle/defaults/main.yml index 7a2f588c6..1b332e0c7 100644 --- a/roles/custom/matrix-bridge-postmoogle/defaults/main.yml +++ b/roles/custom/matrix-bridge-postmoogle/defaults/main.yml @@ -37,6 +37,34 @@ 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 [] }}" diff --git a/roles/custom/matrix-bridge-postmoogle/templates/systemd/matrix-postmoogle.service.j2 b/roles/custom/matrix-bridge-postmoogle/templates/systemd/matrix-postmoogle.service.j2 index 15d1e086f..0b8eaa4db 100644 --- a/roles/custom/matrix-bridge-postmoogle/templates/systemd/matrix-postmoogle.service.j2 +++ b/roles/custom/matrix-bridge-postmoogle/templates/systemd/matrix-postmoogle.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-postmoogle 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-postmoogle 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_bridge_postmoogle_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-bridge-rustpush/defaults/main.yml b/roles/custom/matrix-bridge-rustpush/defaults/main.yml index 47fcbc1ec..f7cf3450a 100644 --- a/roles/custom/matrix-bridge-rustpush/defaults/main.yml +++ b/roles/custom/matrix-bridge-rustpush/defaults/main.yml @@ -105,6 +105,34 @@ matrix_bridge_rustpush_container_labels_additional_labels: '' # A list of extra arguments to pass to the container matrix_bridge_rustpush_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_bridge_rustpush_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_bridge_rustpush_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_rustpush_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_bridge_rustpush_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-rustpush-bridge >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-rustpush-bridge >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-rustpush-bridge >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_bridge_rustpush_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-rustpush-bridge" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-rustpush-bridge after {{ matrix_bridge_rustpush_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # Override the Rust log filter passed to the bridge container via RUST_LOG. # Leave empty to use the bridge's built-in default # ("warn,rustpush=warn,rustpushgo=info,open_absinthe=info"). diff --git a/roles/custom/matrix-bridge-rustpush/templates/systemd/matrix-rustpush-bridge.service.j2 b/roles/custom/matrix-bridge-rustpush/templates/systemd/matrix-rustpush-bridge.service.j2 index 00593b665..2831a0e4b 100644 --- a/roles/custom/matrix-bridge-rustpush/templates/systemd/matrix-rustpush-bridge.service.j2 +++ b/roles/custom/matrix-bridge-rustpush/templates/systemd/matrix-rustpush-bridge.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-rustpush-bridge 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-rustpush-bridge 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_bridge_rustpush_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-bridge-sms/defaults/main.yml b/roles/custom/matrix-bridge-sms/defaults/main.yml index d2f6127c9..b9c0d8167 100644 --- a/roles/custom/matrix-bridge-sms/defaults/main.yml +++ b/roles/custom/matrix-bridge-sms/defaults/main.yml @@ -40,6 +40,34 @@ matrix_bridge_sms_container_additional_networks_custom: [] # A list of extra arguments to pass to the container matrix_bridge_sms_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_bridge_sms_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_bridge_sms_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_sms_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_bridge_sms_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-sms-bridge >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-sms-bridge >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-sms-bridge >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_bridge_sms_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-sms-bridge" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-sms-bridge after {{ matrix_bridge_sms_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # List of systemd services that service depends on. matrix_bridge_sms_systemd_required_services_list: "{{ matrix_bridge_sms_systemd_required_services_list_default + matrix_bridge_sms_systemd_required_services_list_auto + matrix_bridge_sms_systemd_required_services_list_custom }}" matrix_bridge_sms_systemd_required_services_list_default: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}" diff --git a/roles/custom/matrix-bridge-sms/templates/systemd/matrix-sms-bridge.service.j2 b/roles/custom/matrix-bridge-sms/templates/systemd/matrix-sms-bridge.service.j2 index 6219c9c9d..b50b47012 100644 --- a/roles/custom/matrix-bridge-sms/templates/systemd/matrix-sms-bridge.service.j2 +++ b/roles/custom/matrix-bridge-sms/templates/systemd/matrix-sms-bridge.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-sms-bridge 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-sms-bridge 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_bridge_sms_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-bridge-steam/defaults/main.yml b/roles/custom/matrix-bridge-steam/defaults/main.yml index 6ba00e52d..3c39093e5 100644 --- a/roles/custom/matrix-bridge-steam/defaults/main.yml +++ b/roles/custom/matrix-bridge-steam/defaults/main.yml @@ -121,6 +121,34 @@ matrix_bridge_steam_container_labels_additional_labels: '' # A list of extra arguments to pass to the container matrix_bridge_steam_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_bridge_steam_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_bridge_steam_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_steam_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_bridge_steam_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-steam-bridge >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-steam-bridge >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-steam-bridge >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_bridge_steam_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-steam-bridge" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-steam-bridge after {{ matrix_bridge_steam_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # List of systemd services that matrix-steam-bridge.service depends on. matrix_bridge_steam_systemd_required_services_list: "{{ matrix_bridge_steam_systemd_required_services_list_default + matrix_bridge_steam_systemd_required_services_list_auto + matrix_bridge_steam_systemd_required_services_list_custom }}" matrix_bridge_steam_systemd_required_services_list_default: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}" diff --git a/roles/custom/matrix-bridge-steam/templates/systemd/matrix-steam-bridge.service.j2 b/roles/custom/matrix-bridge-steam/templates/systemd/matrix-steam-bridge.service.j2 index 6a4e97dd4..0a0332b6d 100644 --- a/roles/custom/matrix-bridge-steam/templates/systemd/matrix-steam-bridge.service.j2 +++ b/roles/custom/matrix-bridge-steam/templates/systemd/matrix-steam-bridge.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-steam-bridge 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-steam-bridge 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_bridge_steam_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-bridge-wechat/defaults/main.yml b/roles/custom/matrix-bridge-wechat/defaults/main.yml index b947a9bb5..158787e54 100644 --- a/roles/custom/matrix-bridge-wechat/defaults/main.yml +++ b/roles/custom/matrix-bridge-wechat/defaults/main.yml @@ -59,6 +59,34 @@ matrix_bridge_wechat_container_additional_networks_custom: [] # A list of extra arguments to pass to the container matrix_bridge_wechat_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_bridge_wechat_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_bridge_wechat_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_wechat_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_bridge_wechat_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-wechat >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-wechat >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-wechat >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_bridge_wechat_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-wechat" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-wechat after {{ matrix_bridge_wechat_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # List of systemd services that matrix-wechat.service depends on. matrix_bridge_wechat_systemd_required_services_list: "{{ matrix_bridge_wechat_systemd_required_services_list_default + matrix_bridge_wechat_systemd_required_services_list_auto + matrix_bridge_wechat_systemd_required_services_list_custom }}" matrix_bridge_wechat_systemd_required_services_list_default: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}" @@ -162,6 +190,34 @@ matrix_bridge_wechat_agent_configuration_yaml: "{{ lookup('template', 'templates matrix_bridge_wechat_agent_configuration: "{{ matrix_bridge_wechat_agent_configuration_yaml | from_yaml }}" +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_bridge_wechat_agent_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_bridge_wechat_agent_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_wechat_agent_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_bridge_wechat_agent_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-wechat-agent >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-wechat-agent >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-wechat-agent >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_bridge_wechat_agent_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-wechat-agent" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-wechat-agent after {{ matrix_bridge_wechat_agent_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # matrix_bridge_wechat_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). diff --git a/roles/custom/matrix-bridge-wechat/templates/systemd/matrix-wechat-agent.service.j2 b/roles/custom/matrix-bridge-wechat/templates/systemd/matrix-wechat-agent.service.j2 index ed0975140..786f22648 100644 --- a/roles/custom/matrix-bridge-wechat/templates/systemd/matrix-wechat-agent.service.j2 +++ b/roles/custom/matrix-bridge-wechat/templates/systemd/matrix-wechat-agent.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-wechat-agent 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-wechat-agent 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_bridge_wechat_agent_container_cleanup_command | trim | replace("\n", " ") }}' {# The agent needs to write to /home/user/.vnc. diff --git a/roles/custom/matrix-bridge-wechat/templates/systemd/matrix-wechat.service.j2 b/roles/custom/matrix-bridge-wechat/templates/systemd/matrix-wechat.service.j2 index b748402df..e8eef43a5 100644 --- a/roles/custom/matrix-bridge-wechat/templates/systemd/matrix-wechat.service.j2 +++ b/roles/custom/matrix-bridge-wechat/templates/systemd/matrix-wechat.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-wechat 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-wechat 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_bridge_wechat_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-cactus-comments-client/defaults/main.yml b/roles/custom/matrix-cactus-comments-client/defaults/main.yml index 0fafcc748..b427f1259 100644 --- a/roles/custom/matrix-cactus-comments-client/defaults/main.yml +++ b/roles/custom/matrix-cactus-comments-client/defaults/main.yml @@ -68,6 +68,34 @@ matrix_cactus_comments_client_container_labels_additional_labels: '' # A list of extra arguments to pass to the container matrix_cactus_comments_client_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_cactus_comments_client_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_cactus_comments_client_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_cactus_comments_client_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_cactus_comments_client_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-cactus-comments-client >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-cactus-comments-client >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-cactus-comments-client >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_cactus_comments_client_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-cactus-comments-client" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-cactus-comments-client after {{ matrix_cactus_comments_client_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # Controls the SERVER_PORT environment variable. # See: https://static-web-server.net/configuration/environment-variables/ matrix_cactus_comments_client_environment_variable_server_port: 8080 diff --git a/roles/custom/matrix-cactus-comments-client/templates/systemd/matrix-cactus-comments-client.service.j2 b/roles/custom/matrix-cactus-comments-client/templates/systemd/matrix-cactus-comments-client.service.j2 index bb7601042..d9c3930e8 100755 --- a/roles/custom/matrix-cactus-comments-client/templates/systemd/matrix-cactus-comments-client.service.j2 +++ b/roles/custom/matrix-cactus-comments-client/templates/systemd/matrix-cactus-comments-client.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-cactus-comments-client 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-cactus-comments-client 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_cactus_comments_client_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-cactus-comments/defaults/main.yml b/roles/custom/matrix-cactus-comments/defaults/main.yml index e70629108..43d99e396 100644 --- a/roles/custom/matrix-cactus-comments/defaults/main.yml +++ b/roles/custom/matrix-cactus-comments/defaults/main.yml @@ -48,6 +48,34 @@ matrix_cactus_comments_container_additional_networks_custom: [] # A list of extra arguments to pass to the container matrix_cactus_comments_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_cactus_comments_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_cactus_comments_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_cactus_comments_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_cactus_comments_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-cactus-comments >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-cactus-comments >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-cactus-comments >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_cactus_comments_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-cactus-comments" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-cactus-comments after {{ matrix_cactus_comments_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # List of systemd services that matrix-cactus-comments.service depends on matrix_cactus_comments_systemd_required_services_list: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}" diff --git a/roles/custom/matrix-cactus-comments/templates/systemd/matrix-cactus-comments.service.j2 b/roles/custom/matrix-cactus-comments/templates/systemd/matrix-cactus-comments.service.j2 index 5db5accc9..131a89d78 100644 --- a/roles/custom/matrix-cactus-comments/templates/systemd/matrix-cactus-comments.service.j2 +++ b/roles/custom/matrix-cactus-comments/templates/systemd/matrix-cactus-comments.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-cactus-comments 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-cactus-comments 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_cactus_comments_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-client-commet/defaults/main.yml b/roles/custom/matrix-client-commet/defaults/main.yml index b59a9b519..3f60a9e17 100644 --- a/roles/custom/matrix-client-commet/defaults/main.yml +++ b/roles/custom/matrix-client-commet/defaults/main.yml @@ -87,6 +87,34 @@ matrix_client_commet_container_labels_additional_labels: "" # Extra arguments to pass to docker create matrix_client_commet_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_client_commet_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_client_commet_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_client_commet_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_client_commet_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-client-commet >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-client-commet >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-client-commet >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_client_commet_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-client-commet" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-client-commet after {{ matrix_client_commet_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # --------------------------------------------------------------------------- # HTTP security headers # --------------------------------------------------------------------------- diff --git a/roles/custom/matrix-client-commet/templates/systemd/matrix-client-commet.service.j2 b/roles/custom/matrix-client-commet/templates/systemd/matrix-client-commet.service.j2 index afd4a4310..bb82e3803 100644 --- a/roles/custom/matrix-client-commet/templates/systemd/matrix-client-commet.service.j2 +++ b/roles/custom/matrix-client-commet/templates/systemd/matrix-client-commet.service.j2 @@ -16,8 +16,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-client-commet 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-client-commet 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_client_commet_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-client-element/defaults/main.yml b/roles/custom/matrix-client-element/defaults/main.yml index 288a97f93..8c1a50559 100644 --- a/roles/custom/matrix-client-element/defaults/main.yml +++ b/roles/custom/matrix-client-element/defaults/main.yml @@ -106,6 +106,34 @@ matrix_client_element_container_labels_additional_labels: '' # A list of extra arguments to pass to the container matrix_client_element_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_client_element_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_client_element_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_client_element_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_client_element_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-client-element >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-client-element >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-client-element >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_client_element_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-client-element" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-client-element after {{ matrix_client_element_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # List of systemd services that matrix-client-element.service depends on matrix_client_element_systemd_required_services_list: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}" diff --git a/roles/custom/matrix-client-element/templates/systemd/matrix-client-element.service.j2 b/roles/custom/matrix-client-element/templates/systemd/matrix-client-element.service.j2 index 74726330e..95e89bf08 100644 --- a/roles/custom/matrix-client-element/templates/systemd/matrix-client-element.service.j2 +++ b/roles/custom/matrix-client-element/templates/systemd/matrix-client-element.service.j2 @@ -10,8 +10,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-client-element 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-client-element 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_client_element_container_cleanup_command | trim | replace("\n", " ") }}' {# The custom healthcheck command is a patch until https://github.com/element-hq/element-web/pull/29471 diff --git a/roles/custom/matrix-client-fluffychat/defaults/main.yml b/roles/custom/matrix-client-fluffychat/defaults/main.yml index 629bba1a8..5b34d6381 100644 --- a/roles/custom/matrix-client-fluffychat/defaults/main.yml +++ b/roles/custom/matrix-client-fluffychat/defaults/main.yml @@ -85,6 +85,34 @@ matrix_client_fluffychat_container_labels_additional_labels: '' # A list of extra arguments to pass to the container matrix_client_fluffychat_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_client_fluffychat_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_client_fluffychat_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_client_fluffychat_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_client_fluffychat_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-client-fluffychat >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-client-fluffychat >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-client-fluffychat >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_client_fluffychat_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-client-fluffychat" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-client-fluffychat after {{ matrix_client_fluffychat_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # List of systemd services that matrix-client-fluffychat.service depends on matrix_client_fluffychat_systemd_required_services_list: "{{ matrix_client_fluffychat_systemd_required_services_list_default + matrix_client_fluffychat_systemd_required_services_list_auto + matrix_client_fluffychat_systemd_required_services_list_custom }}" matrix_client_fluffychat_systemd_required_services_list_default: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}" diff --git a/roles/custom/matrix-client-fluffychat/templates/systemd/matrix-client-fluffychat.service.j2 b/roles/custom/matrix-client-fluffychat/templates/systemd/matrix-client-fluffychat.service.j2 index 6e7b23cce..4e216eb81 100644 --- a/roles/custom/matrix-client-fluffychat/templates/systemd/matrix-client-fluffychat.service.j2 +++ b/roles/custom/matrix-client-fluffychat/templates/systemd/matrix-client-fluffychat.service.j2 @@ -10,8 +10,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-client-fluffychat 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-client-fluffychat 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_client_fluffychat_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-client-schildichat/defaults/main.yml b/roles/custom/matrix-client-schildichat/defaults/main.yml index ec160ff40..0ef02842e 100644 --- a/roles/custom/matrix-client-schildichat/defaults/main.yml +++ b/roles/custom/matrix-client-schildichat/defaults/main.yml @@ -82,6 +82,34 @@ matrix_client_schildichat_container_labels_additional_labels: '' # A list of extra arguments to pass to the container matrix_client_schildichat_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_client_schildichat_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_client_schildichat_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_client_schildichat_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_client_schildichat_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-client-schildichat >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-client-schildichat >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-client-schildichat >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_client_schildichat_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-client-schildichat" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-client-schildichat after {{ matrix_client_schildichat_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # List of systemd services that matrix-client-schildichat.service depends on matrix_client_schildichat_systemd_required_services_list: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}" diff --git a/roles/custom/matrix-client-schildichat/templates/systemd/matrix-client-schildichat.service.j2 b/roles/custom/matrix-client-schildichat/templates/systemd/matrix-client-schildichat.service.j2 index fdfefa8a4..744752f10 100644 --- a/roles/custom/matrix-client-schildichat/templates/systemd/matrix-client-schildichat.service.j2 +++ b/roles/custom/matrix-client-schildichat/templates/systemd/matrix-client-schildichat.service.j2 @@ -10,8 +10,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-client-schildichat 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-client-schildichat 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_client_schildichat_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-conduit/defaults/main.yml b/roles/custom/matrix-conduit/defaults/main.yml index 9e673aaa5..a81b965b8 100644 --- a/roles/custom/matrix-conduit/defaults/main.yml +++ b/roles/custom/matrix-conduit/defaults/main.yml @@ -118,6 +118,34 @@ matrix_conduit_container_labels_additional_labels: '' # Extra arguments for the Docker container matrix_conduit_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_conduit_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_conduit_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_conduit_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_conduit_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-conduit >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-conduit >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-conduit >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_conduit_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-conduit" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-conduit after {{ matrix_conduit_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # Specifies which template files to use when configuring Conduit. # If you'd like to have your own different configuration, feel free to copy and paste # the original files into your inventory (e.g. in `inventory/host_vars/matrix.example.com/`) diff --git a/roles/custom/matrix-conduit/templates/systemd/matrix-conduit.service.j2 b/roles/custom/matrix-conduit/templates/systemd/matrix-conduit.service.j2 index a8b76d610..41130aa0d 100644 --- a/roles/custom/matrix-conduit/templates/systemd/matrix-conduit.service.j2 +++ b/roles/custom/matrix-conduit/templates/systemd/matrix-conduit.service.j2 @@ -9,8 +9,7 @@ After={{ service }} [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-conduit 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-conduit 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_conduit_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-continuwuity/defaults/main.yml b/roles/custom/matrix-continuwuity/defaults/main.yml index 63c1ce315..58dca4169 100644 --- a/roles/custom/matrix-continuwuity/defaults/main.yml +++ b/roles/custom/matrix-continuwuity/defaults/main.yml @@ -132,6 +132,34 @@ matrix_continuwuity_container_labels_additional_labels: '' # Extra arguments for the Docker container matrix_continuwuity_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_continuwuity_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_continuwuity_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_continuwuity_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_continuwuity_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-continuwuity >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-continuwuity >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-continuwuity >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_continuwuity_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-continuwuity" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-continuwuity after {{ matrix_continuwuity_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # Specifies which template files to use when configuring continuwuity. # If you'd like to have your own different configuration, feel free to copy and paste # the original files into your inventory (e.g. in `inventory/host_vars/matrix.example.com/`) diff --git a/roles/custom/matrix-continuwuity/templates/systemd/matrix-continuwuity.service.j2 b/roles/custom/matrix-continuwuity/templates/systemd/matrix-continuwuity.service.j2 index da53c33be..448c8109d 100644 --- a/roles/custom/matrix-continuwuity/templates/systemd/matrix-continuwuity.service.j2 +++ b/roles/custom/matrix-continuwuity/templates/systemd/matrix-continuwuity.service.j2 @@ -12,8 +12,7 @@ Wants={{ service }} [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-continuwuity 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-continuwuity 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_continuwuity_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-corporal/defaults/main.yml b/roles/custom/matrix-corporal/defaults/main.yml index e33c02cbf..8d8bcce95 100644 --- a/roles/custom/matrix-corporal/defaults/main.yml +++ b/roles/custom/matrix-corporal/defaults/main.yml @@ -34,6 +34,34 @@ matrix_corporal_container_http_api_host_bind_port: '' # A list of extra arguments to pass to the container matrix_corporal_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_corporal_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_corporal_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_corporal_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_corporal_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-corporal >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-corporal >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-corporal >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_corporal_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-corporal" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-corporal after {{ matrix_corporal_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # The base container network. It will be auto-created by this role if it doesn't exist already. matrix_corporal_container_network: "" diff --git a/roles/custom/matrix-corporal/templates/systemd/matrix-corporal.service.j2 b/roles/custom/matrix-corporal/templates/systemd/matrix-corporal.service.j2 index 73cec888e..940a40264 100644 --- a/roles/custom/matrix-corporal/templates/systemd/matrix-corporal.service.j2 +++ b/roles/custom/matrix-corporal/templates/systemd/matrix-corporal.service.j2 @@ -10,8 +10,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-corporal 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-corporal 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_corporal_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-dendrite/defaults/main.yml b/roles/custom/matrix-dendrite/defaults/main.yml index 35debaae4..dda1aef15 100644 --- a/roles/custom/matrix-dendrite/defaults/main.yml +++ b/roles/custom/matrix-dendrite/defaults/main.yml @@ -184,6 +184,34 @@ matrix_dendrite_container_extra_arguments_auto: [] # If you'd like to inject your own arguments, see `matrix_dendrite_container_extra_arguments`. matrix_dendrite_container_arguments: "{{ matrix_dendrite_container_extra_arguments + matrix_dendrite_container_extra_arguments_auto }}" +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_dendrite_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_dendrite_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_dendrite_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_dendrite_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-dendrite >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-dendrite >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-dendrite >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_dendrite_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-dendrite" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-dendrite after {{ matrix_dendrite_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # A list of extra arguments to pass to the container process (`dendrite-monolith` command) # Example: # matrix_dendrite_process_extra_arguments: diff --git a/roles/custom/matrix-dendrite/templates/systemd/matrix-dendrite.service.j2 b/roles/custom/matrix-dendrite/templates/systemd/matrix-dendrite.service.j2 index 698ae0835..f5e2997e2 100644 --- a/roles/custom/matrix-dendrite/templates/systemd/matrix-dendrite.service.j2 +++ b/roles/custom/matrix-dendrite/templates/systemd/matrix-dendrite.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-dendrite 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-dendrite 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_dendrite_container_cleanup_command | trim | replace("\n", " ") }}' {% if (postgres_identifier + '.service') in matrix_dendrite_systemd_required_services_list %} # Dendrite is too quick to start in relation to its Postgres dependency. diff --git a/roles/custom/matrix-element-admin/defaults/main.yml b/roles/custom/matrix-element-admin/defaults/main.yml index c6906ae27..76f0cf427 100644 --- a/roles/custom/matrix-element-admin/defaults/main.yml +++ b/roles/custom/matrix-element-admin/defaults/main.yml @@ -72,6 +72,34 @@ matrix_element_admin_container_labels_additional_labels: '' # A list of extra arguments to pass to the container matrix_element_admin_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_element_admin_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_element_admin_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_element_admin_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_element_admin_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-element-admin >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-element-admin >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-element-admin >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_element_admin_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-element-admin" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-element-admin after {{ matrix_element_admin_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # A list of extra arguments to pass to the container process. matrix_element_admin_container_process_extra_arguments: [] diff --git a/roles/custom/matrix-element-admin/templates/systemd/matrix-element-admin.service.j2 b/roles/custom/matrix-element-admin/templates/systemd/matrix-element-admin.service.j2 index 03511f8f5..b0aa27acd 100644 --- a/roles/custom/matrix-element-admin/templates/systemd/matrix-element-admin.service.j2 +++ b/roles/custom/matrix-element-admin/templates/systemd/matrix-element-admin.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-element-admin 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-element-admin 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_element_admin_container_cleanup_command | trim | replace("\n", " ") }}' {# We mount a tmpfs at /tmp, because `/docker-entrypoint.d/replace-config.sh` writes temporary files there. diff --git a/roles/custom/matrix-element-call/defaults/main.yml b/roles/custom/matrix-element-call/defaults/main.yml index bec5a7a98..54aff48cc 100644 --- a/roles/custom/matrix-element-call/defaults/main.yml +++ b/roles/custom/matrix-element-call/defaults/main.yml @@ -87,6 +87,34 @@ matrix_element_call_container_labels_additional_labels: '' # A list of extra arguments to pass to the container matrix_element_call_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_element_call_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_element_call_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_element_call_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_element_call_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-element-call >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-element-call >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-element-call >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_element_call_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-element-call" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-element-call after {{ matrix_element_call_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # List of systemd services that matrix-element-call.service depends on matrix_element_call_systemd_required_services_list: "{{ matrix_element_call_systemd_required_services_list_default + matrix_element_call_systemd_required_services_list_auto + matrix_element_call_systemd_required_services_list_custom }}" matrix_element_call_systemd_required_services_list_default: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}" diff --git a/roles/custom/matrix-element-call/templates/systemd/matrix-element-call.service.j2 b/roles/custom/matrix-element-call/templates/systemd/matrix-element-call.service.j2 index 13794f7bb..6d000acb5 100644 --- a/roles/custom/matrix-element-call/templates/systemd/matrix-element-call.service.j2 +++ b/roles/custom/matrix-element-call/templates/systemd/matrix-element-call.service.j2 @@ -10,8 +10,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-element-call 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-element-call 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_element_call_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-ketesa/defaults/main.yml b/roles/custom/matrix-ketesa/defaults/main.yml index 1a7dccf10..788941c8b 100644 --- a/roles/custom/matrix-ketesa/defaults/main.yml +++ b/roles/custom/matrix-ketesa/defaults/main.yml @@ -49,6 +49,34 @@ matrix_ketesa_container_http_host_bind_port: '' # A list of extra arguments to pass to the container matrix_ketesa_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_ketesa_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_ketesa_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_ketesa_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_ketesa_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-ketesa >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-ketesa >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-ketesa >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_ketesa_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-ketesa" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-ketesa after {{ matrix_ketesa_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # matrix_ketesa_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. # diff --git a/roles/custom/matrix-ketesa/templates/systemd/matrix-ketesa.service.j2 b/roles/custom/matrix-ketesa/templates/systemd/matrix-ketesa.service.j2 index 809a7e1b7..5304ce9b8 100644 --- a/roles/custom/matrix-ketesa/templates/systemd/matrix-ketesa.service.j2 +++ b/roles/custom/matrix-ketesa/templates/systemd/matrix-ketesa.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-ketesa 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-ketesa 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_ketesa_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-livekit-jwt-service/defaults/main.yml b/roles/custom/matrix-livekit-jwt-service/defaults/main.yml index 571a55b5c..6164b51d7 100644 --- a/roles/custom/matrix-livekit-jwt-service/defaults/main.yml +++ b/roles/custom/matrix-livekit-jwt-service/defaults/main.yml @@ -67,6 +67,34 @@ matrix_livekit_jwt_service_container_labels_additional_labels: '' # A list of extra arguments to pass to the container matrix_livekit_jwt_service_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_livekit_jwt_service_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_livekit_jwt_service_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_livekit_jwt_service_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_livekit_jwt_service_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-livekit-jwt-service >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-livekit-jwt-service >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-livekit-jwt-service >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_livekit_jwt_service_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-livekit-jwt-service" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-livekit-jwt-service after {{ matrix_livekit_jwt_service_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # Controls whether the container's built-in healthcheck is left enabled. # # The bind-address handling was fixed in v0.7.0. If you pin v0.6.0, disable diff --git a/roles/custom/matrix-livekit-jwt-service/templates/systemd/matrix-livekit-jwt-service.service.j2 b/roles/custom/matrix-livekit-jwt-service/templates/systemd/matrix-livekit-jwt-service.service.j2 index bcfcc7fd3..313617aeb 100644 --- a/roles/custom/matrix-livekit-jwt-service/templates/systemd/matrix-livekit-jwt-service.service.j2 +++ b/roles/custom/matrix-livekit-jwt-service/templates/systemd/matrix-livekit-jwt-service.service.j2 @@ -9,8 +9,7 @@ Requires={{ service }} [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-livekit-jwt-service 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-livekit-jwt-service 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_livekit_jwt_service_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-matrixto/defaults/main.yml b/roles/custom/matrix-matrixto/defaults/main.yml index da3bf9e0d..0dd01d8a9 100644 --- a/roles/custom/matrix-matrixto/defaults/main.yml +++ b/roles/custom/matrix-matrixto/defaults/main.yml @@ -115,6 +115,34 @@ matrix_matrixto_container_labels_additional_labels: "" # A list of extra arguments to pass to the container (`docker run` command) matrix_matrixto_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_matrixto_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_matrixto_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_matrixto_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_matrixto_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} {{ matrix_matrixto_identifier }} >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f {{ matrix_matrixto_identifier }} >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect {{ matrix_matrixto_identifier }} >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_matrixto_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_matrixto_identifier }}" >&2; + exit 1; + done; + echo "Failed to remove stale container {{ matrix_matrixto_identifier }} after {{ matrix_matrixto_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # Specifies the value of the `X-XSS-Protection` header # Stops pages from loading when they detect reflected cross-site scripting (XSS) attacks. # diff --git a/roles/custom/matrix-matrixto/templates/systemd/matrix-matrixto.service.j2 b/roles/custom/matrix-matrixto/templates/systemd/matrix-matrixto.service.j2 index a3849f9eb..16b86e045 100644 --- a/roles/custom/matrix-matrixto/templates/systemd/matrix-matrixto.service.j2 +++ b/roles/custom/matrix-matrixto/templates/systemd/matrix-matrixto.service.j2 @@ -20,8 +20,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} {{ matrix_matrixto_identifier }} 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm {{ matrix_matrixto_identifier }} 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_matrixto_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-media-repo/defaults/main.yml b/roles/custom/matrix-media-repo/defaults/main.yml index 991f92f78..0b61356d1 100755 --- a/roles/custom/matrix-media-repo/defaults/main.yml +++ b/roles/custom/matrix-media-repo/defaults/main.yml @@ -71,6 +71,34 @@ matrix_media_repo_container_metrics_host_bind_port: "" # Extra arguments for the Docker container matrix_media_repo_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_media_repo_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_media_repo_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_media_repo_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_media_repo_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} {{ matrix_media_repo_identifier }} >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f {{ matrix_media_repo_identifier }} >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect {{ matrix_media_repo_identifier }} >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_media_repo_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_media_repo_identifier }}" >&2; + exit 1; + done; + echo "Failed to remove stale container {{ matrix_media_repo_identifier }} after {{ matrix_media_repo_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # matrix_media_repo_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. # diff --git a/roles/custom/matrix-media-repo/templates/media-repo/systemd/matrix-media-repo.service.j2 b/roles/custom/matrix-media-repo/templates/media-repo/systemd/matrix-media-repo.service.j2 index cf0c605d4..8f4a1b028 100755 --- a/roles/custom/matrix-media-repo/templates/media-repo/systemd/matrix-media-repo.service.j2 +++ b/roles/custom/matrix-media-repo/templates/media-repo/systemd/matrix-media-repo.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} {{ matrix_media_repo_identifier }} 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm {{ matrix_media_repo_identifier }} 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_media_repo_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-pantalaimon/defaults/main.yml b/roles/custom/matrix-pantalaimon/defaults/main.yml index 4ff97c4d7..b01ce2601 100644 --- a/roles/custom/matrix-pantalaimon/defaults/main.yml +++ b/roles/custom/matrix-pantalaimon/defaults/main.yml @@ -36,6 +36,34 @@ matrix_pantalaimon_container_additional_networks_custom: [] # A list of extra arguments to pass to the container matrix_pantalaimon_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_pantalaimon_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_pantalaimon_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_pantalaimon_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_pantalaimon_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-pantalaimon >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-pantalaimon >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-pantalaimon >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_pantalaimon_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-pantalaimon" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-pantalaimon after {{ matrix_pantalaimon_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # List of systemd services that matrix-pantalaimon.service depends on matrix_pantalaimon_systemd_required_services_list: "{{ matrix_pantalaimon_systemd_required_services_list_default + matrix_pantalaimon_systemd_required_services_list_auto + matrix_pantalaimon_systemd_required_services_list_custom }}" matrix_pantalaimon_systemd_required_services_list_default: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}" diff --git a/roles/custom/matrix-pantalaimon/templates/systemd/matrix-pantalaimon.service.j2 b/roles/custom/matrix-pantalaimon/templates/systemd/matrix-pantalaimon.service.j2 index 85fbe9d29..00654e7c4 100644 --- a/roles/custom/matrix-pantalaimon/templates/systemd/matrix-pantalaimon.service.j2 +++ b/roles/custom/matrix-pantalaimon/templates/systemd/matrix-pantalaimon.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} kill matrix-pantalaimon 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-pantalaimon 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_pantalaimon_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-rageshake/defaults/main.yml b/roles/custom/matrix-rageshake/defaults/main.yml index ce1e78b25..59222654b 100644 --- a/roles/custom/matrix-rageshake/defaults/main.yml +++ b/roles/custom/matrix-rageshake/defaults/main.yml @@ -87,6 +87,34 @@ matrix_rageshake_container_labels_additional_labels: '' # A list of extra arguments to pass to the container matrix_rageshake_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_rageshake_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_rageshake_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_rageshake_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_rageshake_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-rageshake >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-rageshake >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-rageshake >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_rageshake_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-rageshake" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-rageshake after {{ matrix_rageshake_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # List of systemd services that matrix-rageshake.service depends on matrix_rageshake_systemd_required_services_list: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}" diff --git a/roles/custom/matrix-rageshake/templates/systemd/matrix-rageshake.service.j2 b/roles/custom/matrix-rageshake/templates/systemd/matrix-rageshake.service.j2 index a90ecdb1e..5bec089eb 100644 --- a/roles/custom/matrix-rageshake/templates/systemd/matrix-rageshake.service.j2 +++ b/roles/custom/matrix-rageshake/templates/systemd/matrix-rageshake.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-rageshake 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-rageshake 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_rageshake_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-static-files/defaults/main.yml b/roles/custom/matrix-static-files/defaults/main.yml index 36e94ee0a..911739dbb 100644 --- a/roles/custom/matrix-static-files/defaults/main.yml +++ b/roles/custom/matrix-static-files/defaults/main.yml @@ -22,6 +22,34 @@ matrix_static_files_public_well_known_path: "{{ matrix_static_files_public_path matrix_static_files_public_well_known_matrix_path: "{{ matrix_static_files_public_well_known_path }}/matrix" matrix_static_files_public_well_known_element_path: "{{ matrix_static_files_public_well_known_path }}/element" +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_static_files_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_static_files_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_static_files_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_static_files_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-static-files >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-static-files >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-static-files >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_static_files_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-static-files" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-static-files after {{ matrix_static_files_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # List of systemd services that matrix-static-files.service depends on matrix_static_files_systemd_required_services_list: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}" diff --git a/roles/custom/matrix-static-files/templates/systemd/matrix-static-files.service.j2 b/roles/custom/matrix-static-files/templates/systemd/matrix-static-files.service.j2 index 759c4d8cf..687d56cd9 100755 --- a/roles/custom/matrix-static-files/templates/systemd/matrix-static-files.service.j2 +++ b/roles/custom/matrix-static-files/templates/systemd/matrix-static-files.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-static-files 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-static-files 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_static_files_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-sygnal/defaults/main.yml b/roles/custom/matrix-sygnal/defaults/main.yml index bb2a9ffb7..3afe08870 100644 --- a/roles/custom/matrix-sygnal/defaults/main.yml +++ b/roles/custom/matrix-sygnal/defaults/main.yml @@ -86,6 +86,34 @@ matrix_sygnal_container_labels_additional_labels: '' # A list of extra arguments to pass to the container matrix_sygnal_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_sygnal_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_sygnal_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_sygnal_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_sygnal_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-sygnal >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-sygnal >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-sygnal >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_sygnal_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-sygnal" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-sygnal after {{ matrix_sygnal_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # A map (dictionary) of apps instances that this server works with. # # Example configuration: diff --git a/roles/custom/matrix-sygnal/templates/systemd/matrix-sygnal.service.j2 b/roles/custom/matrix-sygnal/templates/systemd/matrix-sygnal.service.j2 index b948673f3..4dccfb009 100644 --- a/roles/custom/matrix-sygnal/templates/systemd/matrix-sygnal.service.j2 +++ b/roles/custom/matrix-sygnal/templates/systemd/matrix-sygnal.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-sygnal 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-sygnal 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_sygnal_container_cleanup_command | trim | replace("\n", " ") }}' {# --no-healthcheck is used below, because the healthcheck hardcoded in the image (since v0.16.0) can never pass - it relies on curl, which the image does not include. diff --git a/roles/custom/matrix-synapse-auto-compressor/defaults/main.yml b/roles/custom/matrix-synapse-auto-compressor/defaults/main.yml index 5cb83ba0d..4dd635efc 100644 --- a/roles/custom/matrix-synapse-auto-compressor/defaults/main.yml +++ b/roles/custom/matrix-synapse-auto-compressor/defaults/main.yml @@ -45,6 +45,34 @@ 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 [] }}" diff --git a/roles/custom/matrix-synapse-auto-compressor/templates/matrix-synapse-auto-compressor.service.j2 b/roles/custom/matrix-synapse-auto-compressor/templates/matrix-synapse-auto-compressor.service.j2 index b5a36cefe..14c23ff7e 100644 --- a/roles/custom/matrix-synapse-auto-compressor/templates/matrix-synapse-auto-compressor.service.j2 +++ b/roles/custom/matrix-synapse-auto-compressor/templates/matrix-synapse-auto-compressor.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=oneshot Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-synapse-auto-compressor 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-synapse-auto-compressor 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_synapse_auto_compressor_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} {{ matrix_synapse_auto_compressor_base_path }}/matrix-synapse-auto-compressor-fix.sh ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ diff --git a/roles/custom/matrix-synapse-usage-exporter/defaults/main.yml b/roles/custom/matrix-synapse-usage-exporter/defaults/main.yml index 030581bc9..e6d02b5eb 100644 --- a/roles/custom/matrix-synapse-usage-exporter/defaults/main.yml +++ b/roles/custom/matrix-synapse-usage-exporter/defaults/main.yml @@ -59,6 +59,34 @@ 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. diff --git a/roles/custom/matrix-synapse-usage-exporter/templates/systemd/matrix-synapse-usage-exporter.service.j2 b/roles/custom/matrix-synapse-usage-exporter/templates/systemd/matrix-synapse-usage-exporter.service.j2 index 6a3c8d68f..2ba9e06b7 100644 --- a/roles/custom/matrix-synapse-usage-exporter/templates/systemd/matrix-synapse-usage-exporter.service.j2 +++ b/roles/custom/matrix-synapse-usage-exporter/templates/systemd/matrix-synapse-usage-exporter.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} {{ matrix_synapse_usage_exporter_identifier }} 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm {{ matrix_synapse_usage_exporter_identifier }} 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_synapse_usage_exporter_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-synapse/defaults/main.yml b/roles/custom/matrix-synapse/defaults/main.yml index 5c52a94ca..dbe53c0c1 100644 --- a/roles/custom/matrix-synapse/defaults/main.yml +++ b/roles/custom/matrix-synapse/defaults/main.yml @@ -356,6 +356,34 @@ matrix_synapse_container_extra_arguments_auto: [] # If you'd like to inject your own arguments, see `matrix_synapse_container_extra_arguments`. matrix_synapse_container_arguments: "{{ matrix_synapse_container_extra_arguments + matrix_synapse_container_extra_arguments_auto }}" +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_synapse_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_synapse_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_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_synapse_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 >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-synapse >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-synapse >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_synapse_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" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-synapse after {{ matrix_synapse_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # matrix_synapse_container_master_extra_arguments contains arguments specific to the master process whereas # matrix_synapse_container_arguments contains arguments the apply to all Synapse containers (master and worker). matrix_synapse_container_master_extra_arguments: [] @@ -372,6 +400,34 @@ matrix_synapse_systemd_wanted_services_list_default: [] matrix_synapse_systemd_wanted_services_list_auto: [] matrix_synapse_systemd_wanted_services_list_custom: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_synapse_goofys_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_synapse_goofys_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_goofys_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_synapse_goofys_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} %n >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f %n >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect %n >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_synapse_goofys_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 %n" >&2; + exit 1; + done; + echo "Failed to remove stale container %n after {{ matrix_synapse_goofys_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # List of systemd services that matrix-goofys.service depends on matrix_synapse_goofys_systemd_required_services_list: "{{ matrix_synapse_goofys_systemd_required_services_list_default + matrix_synapse_goofys_systemd_required_services_list_auto + matrix_synapse_goofys_systemd_required_services_list_custom }}" matrix_synapse_goofys_systemd_required_services_list_default: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}" @@ -1010,6 +1066,35 @@ matrix_synapse_workers_presets: # It takes "*" to signify "bind on all interfaces" ("0.0.0.0" is IPv4-only). matrix_synapse_workers_container_host_bind_address: '' +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_synapse_worker_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_synapse_worker_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. +# It is rendered once per worker, with `matrix_synapse_worker_container_name` set to that worker's container name. +matrix_synapse_worker_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_synapse_worker_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_worker_container_name }} >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f {{ matrix_synapse_worker_container_name }} >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect {{ matrix_synapse_worker_container_name }} >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_synapse_worker_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_worker_container_name }}" >&2; + exit 1; + done; + echo "Failed to remove stale container {{ matrix_synapse_worker_container_name }} after {{ matrix_synapse_worker_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # matrix_synapse_worker_container_labels_traefik_enabled controls whether labels to assist a Traefik reverse-proxy will be attached to Synapse worker containers. # See `../templates/worker-labels.j2` for details. # @@ -2069,6 +2154,34 @@ matrix_synapse_reverse_proxy_companion_container_extra_arguments_auto: [] # If you'd like to inject your own arguments, see `matrix_synapse_reverse_proxy_companion_container_extra_arguments`. matrix_synapse_reverse_proxy_companion_container_arguments: "{{ matrix_synapse_reverse_proxy_companion_container_extra_arguments + matrix_synapse_reverse_proxy_companion_container_extra_arguments_auto }}" +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_synapse_reverse_proxy_companion_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_synapse_reverse_proxy_companion_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_reverse_proxy_companion_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_synapse_reverse_proxy_companion_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-reverse-proxy-companion >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-synapse-reverse-proxy-companion >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-synapse-reverse-proxy-companion >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_synapse_reverse_proxy_companion_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-reverse-proxy-companion" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-synapse-reverse-proxy-companion after {{ matrix_synapse_reverse_proxy_companion_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # The amount of worker processes and connections # Consider increasing these when you are expecting high amounts of traffic # http://nginx.org/en/docs/ngx_core_module.html#worker_connections diff --git a/roles/custom/matrix-synapse/templates/goofys/systemd/matrix-goofys.service.j2 b/roles/custom/matrix-synapse/templates/goofys/systemd/matrix-goofys.service.j2 index 5d7ebe10a..229a0dc2a 100644 --- a/roles/custom/matrix-synapse/templates/goofys/systemd/matrix-goofys.service.j2 +++ b/roles/custom/matrix-synapse/templates/goofys/systemd/matrix-goofys.service.j2 @@ -10,8 +10,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} %n -ExecStartPre=-{{ devture_systemd_docker_base_host_command_docker }} rm %n +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_synapse_goofys_container_cleanup_command | trim | replace("\n", " ") }}' ExecStart={{ devture_systemd_docker_base_host_command_docker }} run --rm --name %n \ --log-driver=none \ diff --git a/roles/custom/matrix-synapse/templates/reverse_proxy_companion/systemd/matrix-synapse-reverse-proxy-companion.service.j2 b/roles/custom/matrix-synapse/templates/reverse_proxy_companion/systemd/matrix-synapse-reverse-proxy-companion.service.j2 index 6a47dbf8f..e7904ea99 100755 --- a/roles/custom/matrix-synapse/templates/reverse_proxy_companion/systemd/matrix-synapse-reverse-proxy-companion.service.j2 +++ b/roles/custom/matrix-synapse/templates/reverse_proxy_companion/systemd/matrix-synapse-reverse-proxy-companion.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-synapse-reverse-proxy-companion 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-synapse-reverse-proxy-companion 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_synapse_reverse_proxy_companion_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-synapse/templates/synapse/systemd/matrix-synapse-worker.service.j2 b/roles/custom/matrix-synapse/templates/synapse/systemd/matrix-synapse-worker.service.j2 index 1ff0e9606..aa846ce44 100644 --- a/roles/custom/matrix-synapse/templates/synapse/systemd/matrix-synapse-worker.service.j2 +++ b/roles/custom/matrix-synapse/templates/synapse/systemd/matrix-synapse-worker.service.j2 @@ -37,8 +37,7 @@ Requires=matrix-synapse.service Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} {{ matrix_synapse_worker_container_name }} 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm {{ matrix_synapse_worker_container_name }} 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_synapse_worker_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-synapse/templates/synapse/systemd/matrix-synapse.service.j2 b/roles/custom/matrix-synapse/templates/synapse/systemd/matrix-synapse.service.j2 index ecedbaecf..c3fdbe5e4 100644 --- a/roles/custom/matrix-synapse/templates/synapse/systemd/matrix-synapse.service.j2 +++ b/roles/custom/matrix-synapse/templates/synapse/systemd/matrix-synapse.service.j2 @@ -21,8 +21,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-synapse 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-synapse 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_synapse_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-tuwunel/defaults/main.yml b/roles/custom/matrix-tuwunel/defaults/main.yml index c6be9de7f..51496f874 100644 --- a/roles/custom/matrix-tuwunel/defaults/main.yml +++ b/roles/custom/matrix-tuwunel/defaults/main.yml @@ -152,6 +152,34 @@ matrix_tuwunel_container_labels_additional_labels: '' # Extra arguments for the Docker container matrix_tuwunel_container_extra_arguments: [] +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_tuwunel_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_tuwunel_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_tuwunel_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_tuwunel_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-tuwunel >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-tuwunel >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-tuwunel >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_tuwunel_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-tuwunel" >&2; + exit 1; + done; + echo "Failed to remove stale container matrix-tuwunel after {{ matrix_tuwunel_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # Specifies which template files to use when configuring tuwunel. # To override the rendered config wholesale, copy the template into your inventory and point this at it: # matrix_tuwunel_template_tuwunel_config: "{{ playbook_dir }}/inventory/host_vars/matrix.example.com/tuwunel.toml.j2" diff --git a/roles/custom/matrix-tuwunel/templates/systemd/matrix-tuwunel.service.j2 b/roles/custom/matrix-tuwunel/templates/systemd/matrix-tuwunel.service.j2 index 05af8f7ab..16f8ba205 100644 --- a/roles/custom/matrix-tuwunel/templates/systemd/matrix-tuwunel.service.j2 +++ b/roles/custom/matrix-tuwunel/templates/systemd/matrix-tuwunel.service.j2 @@ -12,8 +12,7 @@ Wants={{ service }} [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-tuwunel 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-tuwunel 2>/dev/null || true' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_tuwunel_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ diff --git a/roles/custom/matrix-user-verification-service/defaults/main.yml b/roles/custom/matrix-user-verification-service/defaults/main.yml index 7e3bc963f..8b2c71a97 100644 --- a/roles/custom/matrix-user-verification-service/defaults/main.yml +++ b/roles/custom/matrix-user-verification-service/defaults/main.yml @@ -53,6 +53,34 @@ matrix_user_verification_service_systemd_wanted_services_list: [] matrix_user_verification_service_systemd_service_basename: "matrix-user-verification-service" matrix_user_verification_service_systemd_service_name: "{{ matrix_user_verification_service_systemd_service_basename }}.service" +# Controls how long the pre-start cleanup should wait for stale container-name release +# before failing startup explicitly. +matrix_user_verification_service_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}" + +# Controls the delay between pre-start cleanup retries. +matrix_user_verification_service_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_user_verification_service_container_cleanup_command: | + i=0; + while [ "$i" -lt {{ matrix_user_verification_service_container_cleanup_timeout_seconds }} ]; do + {{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} {{ matrix_user_verification_service_container_name }} >/dev/null 2>&1 || true; + {{ devture_systemd_docker_base_host_command_docker }} rm -f {{ matrix_user_verification_service_container_name }} >/dev/null 2>&1 || true; + if {{ devture_systemd_docker_base_host_command_docker }} container inspect {{ matrix_user_verification_service_container_name }} >/dev/null 2>&1; then + i=$((i + 1)); + sleep {{ matrix_user_verification_service_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_user_verification_service_container_name }}" >&2; + exit 1; + done; + echo "Failed to remove stale container {{ matrix_user_verification_service_container_name }} after {{ matrix_user_verification_service_container_cleanup_timeout_seconds }} attempts" >&2; + exit 1 + # Matrix User Verification Service Configuration ## REQUIRED diff --git a/roles/custom/matrix-user-verification-service/templates/systemd/matrix-user-verification-service.service.j2 b/roles/custom/matrix-user-verification-service/templates/systemd/matrix-user-verification-service.service.j2 index 4be4b6446..3e7f242b2 100644 --- a/roles/custom/matrix-user-verification-service/templates/systemd/matrix-user-verification-service.service.j2 +++ b/roles/custom/matrix-user-verification-service/templates/systemd/matrix-user-verification-service.service.j2 @@ -13,8 +13,7 @@ DefaultDependencies=no [Service] Type=simple Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} {{ matrix_user_verification_service_container_name }} 2>/dev/null' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm {{ matrix_user_verification_service_container_name }} 2>/dev/null' +ExecStartPre={{ devture_systemd_docker_base_host_command_sh }} -c '{{ matrix_user_verification_service_container_cleanup_command | trim | replace("\n", " ") }}' ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \