fix: quiet ps:retire where possible

Log output for ps:retire was previously a bit too verbose because we weren't handling the following edge-cases.

- if a container doesn't exist, remove it from the dead container list
- ensure a restarting container is properly killed
- only attempt to stop/kill if the state is not dead or exited
- do not attempt to do anything if the container doesn't exist
- correct check on running state
This commit is contained in:
Jose Diaz-Gonzalez committed 2019-01-12 22:49:23 -05:00
1 parent 49af2d8062
commit 0375bc3e97
2 files changed
+24 -3

No files matched your search

@@ -93,14 +93,21 @@ help_desc
fn-scheduler-docker-local-retire-container() { fn-scheduler-docker-local-retire-container() {
declare APP="$1" CID="$2" DEAD_TIME="$3" 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 return
fi fi
DOKKU_DOCKER_STOP_TIMEOUT="$(config_get "$APP" DOKKU_DOCKER_STOP_TIMEOUT || true)" 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}" [[ $DOKKU_DOCKER_STOP_TIMEOUT ]] && DOCKER_STOP_TIME_ARG="--time=${DOKKU_DOCKER_STOP_TIMEOUT}"
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 # 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 # to not send SIGKILL as the docs would indicate. If that fails, move
# on to the next. # on to the next.
@@ -108,10 +115,18 @@ fn-scheduler-docker-local-retire-container() {
docker stop $DOCKER_STOP_TIME_ARG "$CID" \ docker stop $DOCKER_STOP_TIME_ARG "$CID" \
|| docker kill "$CID" \ || docker kill "$CID" \
|| dokku_log_warn "Unable to kill container ${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 [[ "$STATE" != "dead" ]] && [[ "$STATE" != "exited" ]]; then
if ! docker kill "$CID"; then if ! docker kill "$CID"; then
dokku_log_warn "Unable to kill container ${CID}" dokku_log_warn "Unable to kill container ${CID}"
fi fi
fi
} }
fn-scheduler-docker-local-register-retired-container() { fn-scheduler-docker-local-register-retired-container() {
@@ -9,7 +9,7 @@ scheduler-docker-local-scheduler-retire() {
declare trigger="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 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 if [[ ! -f "$DEAD_CONTAINER_FILE" ]]; then
return return
@@ -27,7 +27,13 @@ scheduler-docker-local-scheduler-retire() {
fi fi
fn-scheduler-docker-local-retire-container "$APP" "$CID" "$DEAD_TIME" 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" dokku_log_warn "Container ${CID} still running"
continue continue
fi fi