From 7b0d3b14bcf6a7b5ec7364394281634822476ccc Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 9 Mar 2025 05:12:31 -0400 Subject: [PATCH] fix: stop all app containers when calling ps:stop Closes #6872 --- plugins/scheduler-docker-local/scheduler-stop | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/plugins/scheduler-docker-local/scheduler-stop b/plugins/scheduler-docker-local/scheduler-stop index 8e336e95b..aaea1299e 100755 --- a/plugins/scheduler-docker-local/scheduler-stop +++ b/plugins/scheduler-docker-local/scheduler-stop @@ -4,6 +4,12 @@ set -eo pipefail source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" +fn-stop-container() { + declare APP="$1" CID="$2" + "$DOCKER_BIN" container update --restart=no "$CID" &>/dev/null || true + "$DOCKER_BIN" container stop $DOCKER_STOP_TIME_ARG "$CID" &>/dev/null || true +} + trigger-scheduler-docker-local-scheduler-stop() { declare desc="scheduler-docker-local scheduler-stop plugin trigger" declare trigger="scheduler-stop" @@ -19,14 +25,22 @@ trigger-scheduler-docker-local-scheduler-stop() { [[ -n "$DOKKU_DOCKER_STOP_TIMEOUT" ]] && DOCKER_STOP_TIME_ARG="--time=${DOKKU_DOCKER_STOP_TIMEOUT}" if [[ -n "$DOKKU_APP_RUNNING_CONTAINER_IDS" ]]; then - # Disable the container restart policy - "$DOCKER_BIN" container update --restart=no $DOKKU_APP_RUNNING_CONTAINER_IDS &>/dev/null || true + for CID in $DOKKU_APP_RUNNING_CONTAINER_IDS; do + fn-stop-container "$APP" "$CID" + done + fi - "$DOCKER_BIN" container stop $DOCKER_STOP_TIME_ARG $DOKKU_APP_RUNNING_CONTAINER_IDS >/dev/null || true + # Stop all other containers related to the app + # fetch all containers with the com.dokku.app-name label + local DOKKU_APP_CIDS="$(docker container ls -q -f label=com.dokku.app-name="$APP")" + if [[ -n "$DOKKU_APP_CIDS" ]]; then + for CID in $DOKKU_APP_CIDS; do + fn-stop-container "$APP" "$CID" + done fi if [[ "$REMOVE_CONTAINERS" == "true" ]]; then - local DOKKU_APP_CIDS=$(get_app_container_ids "$APP") + local DOKKU_APP_CIDS="$(docker ps -q -f label=com.dokku.app-name="$APP")" if [[ -n "$DOKKU_APP_CIDS" ]]; then for CID in $DOKKU_APP_CIDS; do