From 0f9ce0a82b589a6412cf44512e7fdc44ae77b886 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 14 Aug 2026 23:35:44 +0000 Subject: [PATCH] Add a flag to permanently retire shared coturn without auto-reinstalling it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ensure_coturn_user() auto-installs shared coturn (services/coturn.sh) any time $DOCKER_DIR/coturn doesn't exist — correct behavior for "first service that needs TURN", wrong behavior for "an operator deliberately decided every consumer should run its own dedicated coturn instead and removed the shared one on purpose". The function had no way to tell those two states apart, so deleting ~/docker/coturn didn't actually retire it — the next service to call this function (a Mattermost reinstall, a fresh Asterisk install) would silently bring it right back. touch ~/docker/.coturn-retired now short-circuits the function straight to the existing "no TURN available, caller degrades gracefully" return path, before it ever looks at install_coturn. Every existing consumer (Asterisk, Mattermost) already handles that path correctly today — it's exactly what happens if shared coturn simply fails to install — so this needed no changes on the consumer side, only closing the gap in the shared function. Verified with a mock: with the flag present, install_coturn is never invoked and the function returns empty COTURN_HOST/rc=1 as expected. --- lib/common.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/common.sh b/lib/common.sh index 016aaf5..477491b 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -1031,6 +1031,21 @@ ensure_coturn_user() { local _consumer="$1" COTURN_HOST="" COTURN_PORT="" COTURN_USERNAME="" COTURN_PASSWORD="" + # An operator can permanently retire shared coturn (e.g. deciding every + # consumer should run its own dedicated instance instead) by creating + # this flag file. Without checking it here first, retiring shared coturn + # by just deleting $DOCKER_DIR/coturn wouldn't actually stick — the very + # next service that calls this function (a Mattermost reinstall, a fresh + # Asterisk install, ...) would silently reinstall it right back, since + # the only signal this function otherwise has is "does the directory + # exist yet", which looks identical to "never installed" and "removed on + # purpose". touch/rm $DOCKER_DIR/.coturn-retired to toggle this. + if [ -f "$DOCKER_DIR/.coturn-retired" ]; then + log_info "Shared coturn is retired on this box ($DOCKER_DIR/.coturn-retired exists) —" + log_info "$_consumer will run its own dedicated coturn instead." + return 1 + fi + if [ ! -d "$DOCKER_DIR/coturn" ]; then if declare -F install_coturn >/dev/null 2>&1; then log_info "No shared coturn (TURN/STUN) server yet — setting one up for $_consumer..."