From ae972cf3cd7df8f08afbcb3013066755212856fc Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Tue, 28 Jun 2016 20:32:04 -0700 Subject: [PATCH] only attempt to stop a checks-disabled container if it is actually running. closes #2278 --- plugins/checks/check-deploy | 2 +- plugins/common/functions | 12 ++++++------ tests/unit/10_checks.bats | 29 +++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/plugins/checks/check-deploy b/plugins/checks/check-deploy index 22f0263be..4dc3474eb 100755 --- a/plugins/checks/check-deploy +++ b/plugins/checks/check-deploy @@ -58,7 +58,7 @@ checks_check_deploy() { eval "$(config_export global)" eval "$(config_export app "$APP")" - if [[ "$(is_app_proctype_checks_skipped "$APP" "$PROC_TYPE")" == "true" ]]; then + if [[ "$(is_app_proctype_checks_skipped "$APP" "$DOKKU_APP_CONTAINER_TYPE")" == "true" ]]; then dokku_log_info2_quiet "Zero downtime checks for app ($APP) have been skipped. moving on..." exit 0 fi diff --git a/plugins/common/functions b/plugins/common/functions index d7d15dbc4..764fd9c15 100755 --- a/plugins/common/functions +++ b/plugins/common/functions @@ -288,7 +288,7 @@ copy_from_image() { } get_app_container_ids() { - declare desc="returns list of docker container ids for given app/container_type" + declare desc="returns list of docker container ids for given app and optional container_type" local APP="$1"; local CONTAINER_TYPE="$2" verify_app_name "$APP" [[ -f $DOKKU_ROOT/$APP/CONTAINER ]] && DOKKU_CIDS+=$(< "$DOKKU_ROOT/$APP/CONTAINER") @@ -315,15 +315,15 @@ get_app_container_ids() { } get_app_running_container_ids() { - declare desc="return list of running docker container ids for given apps" - local APP=$1 + declare desc="return list of running docker container ids for given app and optional container_type" + local APP="$1" CONTAINER_TYPE="$2" verify_app_name "$APP" ! (is_deployed "$APP") && dokku_log_fail "App $APP has not been deployed" - local CIDS=$(get_app_container_ids "$APP") + local CIDS=$(get_app_container_ids "$APP" "$CONTAINER_TYPE") for CID in $CIDS; do - local APP_CONTAINER_STATUS=$(docker inspect -f '{{.State.Running}}' "$CID" || true) + local APP_CONTAINER_STATUS=$(docker inspect -f '{{.State.Running}}' "$CID" 2>/dev/null || true) [[ "$APP_CONTAINER_STATUS" == "true" ]] && local APP_RUNNING_CONTAINER_IDS+="$CID " done @@ -540,7 +540,7 @@ dokku_deploy_cmd() { if [[ "$(is_app_proctype_checks_disabled "$APP" "$PROC_TYPE")" == "true" ]]; then dokku_log_info1 "zero downtime is disabled for app ($APP.$PROC_TYPE). stopping currently running containers" - local cid proctype_oldids="$(get_app_container_ids "$APP" "$PROC_TYPE")" + local cid proctype_oldids="$(get_app_running_container_ids "$APP" "$PROC_TYPE")" for cid in $proctype_oldids; do dokku_log_info2 "stopping $APP.$PROC_TYPE ($cid)" # shellcheck disable=SC2086 diff --git a/tests/unit/10_checks.bats b/tests/unit/10_checks.bats index 2d49ae37f..b5b8f90f8 100644 --- a/tests/unit/10_checks.bats +++ b/tests/unit/10_checks.bats @@ -172,3 +172,32 @@ teardown() { echo "status: "$status assert_output "web,notifications" } + +@test "(checks) checks:disable -> app start with missing containers" { + run bash -c "dokku ps:scale $TEST_APP worker=1" + echo "output: "$output + echo "status: "$status + assert_success + + deploy_app + + run bash -c "dokku checks:disable $TEST_APP worker" + echo "output: "$output + echo "status: "$status + assert_success + + run bash -c "dokku ps:stop $TEST_APP" + echo "output: "$output + echo "status: "$status + assert_success + + run bash -c "dokku cleanup" + echo "output: "$output + echo "status: "$status + assert_success + + run bash -c "dokku ps:start $TEST_APP" + echo "output: "$output + echo "status: "$status + assert_success +}