Skip to content

Commit

Permalink
Merge pull request #3394 from dokku/retire-fixes
Browse files Browse the repository at this point in the history
Quiet ps:retire where possible
  • Loading branch information
josegonzalez committed Jan 13, 2019
2 parents 49af2d8 + 0375bc3 commit 5579fe0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
35 changes: 25 additions & 10 deletions plugins/scheduler-docker-local/internal-functions
Expand Up @@ -93,24 +93,39 @@ help_desc

fn-scheduler-docker-local-retire-container() {
declare APP="$1" CID="$2" DEAD_TIME="$3"
local STATE

if ! docker inspect "${CID}" >/dev/null; then
STATE="$(docker inspect -f "{{ .State.Status }}" "$CID" 2>/dev/null || true)"
if [[ -z "$STATE" ]]; then
return
fi

DOKKU_DOCKER_STOP_TIMEOUT="$(config_get "$APP" DOKKU_DOCKER_STOP_TIMEOUT || true)"
[[ $DOKKU_DOCKER_STOP_TIMEOUT ]] && DOCKER_STOP_TIME_ARG="--time=${DOKKU_DOCKER_STOP_TIMEOUT}"

# Attempt to stop, if that fails, then force a kill as docker seems
# to not send SIGKILL as the docs would indicate. If that fails, move
# on to the next.
# shellcheck disable=SC2086
docker stop $DOCKER_STOP_TIME_ARG "$CID" \
|| docker kill "$CID" \
|| dokku_log_warn "Unable to kill container ${CID}"
if [[ "$STATE" == "restarting" ]]; then
docker update --restart=no "$CID" >/dev/null 2>&1
fi

if [[ "$STATE" != "dead" ]] && [[ "$STATE" != "exited" ]]; then
# Attempt to stop, if that fails, then force a kill as docker seems
# to not send SIGKILL as the docs would indicate. If that fails, move
# on to the next.
# shellcheck disable=SC2086
docker stop $DOCKER_STOP_TIME_ARG "$CID" \
|| docker kill "$CID" \
|| dokku_log_warn "Unable to kill container ${CID}"
fi

STATE="$(docker inspect -f "{{ .State.Status }}" "$CID" 2>/dev/null || true)"
if [[ -z "$STATE" ]]; then
return
fi

if ! docker kill "$CID"; then
dokku_log_warn "Unable to kill container ${CID}"
if [[ "$STATE" != "dead" ]] && [[ "$STATE" != "exited" ]]; then
if ! docker kill "$CID"; then
dokku_log_warn "Unable to kill container ${CID}"
fi
fi
}

Expand Down
10 changes: 8 additions & 2 deletions plugins/scheduler-docker-local/scheduler-retire
Expand Up @@ -9,7 +9,7 @@ scheduler-docker-local-scheduler-retire() {
declare trigger="scheduler-docker-local scheduler-retire"

local DEAD_CONTAINER_FILE="${DOKKU_LIB_ROOT}/data/scheduler-docker-local/dead-containers"
local APP CID CURRENT_TIME DEAD_TIME
local APP CID CURRENT_TIME DEAD_TIME STATE

if [[ ! -f "$DEAD_CONTAINER_FILE" ]]; then
return
Expand All @@ -27,7 +27,13 @@ scheduler-docker-local-scheduler-retire() {
fi

fn-scheduler-docker-local-retire-container "$APP" "$CID" "$DEAD_TIME"
if docker ps -aq -f "id=${CID}" -f "status=running" >/dev/null 2>&1; then
STATE="$(docker inspect -f "{{ .State.Status }}" "$CID" 2>/dev/null || true)"
if [[ -z "$STATE" ]]; then
DEAD_CONTAINERS+=("$CID")
continue
fi

if [[ "$STATE" == "running" ]]; then
dokku_log_warn "Container ${CID} still running"
continue
fi
Expand Down

0 comments on commit 5579fe0

Please sign in to comment.