Merge pull request #3176 from dokku/2772-non-mixed-start

Detect mixed running status on service start
This commit is contained in:
Jose Diaz-Gonzalez
2018-04-28 15:06:19 -04:00
committed by GitHub
4 changed files with 61 additions and 32 deletions

View File

@@ -408,14 +408,17 @@ is_deployed() {
is_container_running() {
declare desc="return 0 if given docker container id is in running state"
declare deprecated=true
local CID=$1
local CONTAINER_STATUS=$(docker inspect -f '{{.State.Running}}' "$CID" || true)
declare CID="$1"
local CONTAINER_STATUS
dokku_log_warn "Deprecated: common#is_container_status"
CONTAINER_STATUS=$(docker inspect -f '{{.State.Running}}' "$CID" || true)
if [[ "$CONTAINER_STATUS" == "true" ]]; then
return 0
else
return 1
fi
return 1
}
is_container_status() {
@@ -426,14 +429,17 @@ is_container_status() {
if [[ "$CONTAINER_STATUS" == "true" ]]; then
return 0
else
return 1
fi
return 1
}
is_app_running() {
declare desc="return 0 if given app has a running container"
declare deprecated=true
local APP="$1"
dokku_log_warn "Deprecated: ps#fn-is-app-running"
verify_app_name "$APP"
local APP_RUNNING_CONTAINER_IDS=$(get_app_running_container_ids "$APP")

View File

@@ -91,17 +91,24 @@ ps_start() {
declare desc="starts app"
local APP="$1"; verify_app_name "$APP"
local IMAGE_TAG=$(get_running_image_tag "$APP");
local RUNNING
if (is_deployed "$APP"); then
plugn trigger pre-start "$APP"
if ! (is_app_running "$APP"); then
RUNNING="$(fn-ps-is-app-running "$APP")"
if [[ "$RUNNING" == "mixed" ]]; then
dokku_log_warn "App is running in mixed mode, releasing"
fi
if [[ "$RUNNING" != "true" ]]; then
release_and_deploy "$APP" "$IMAGE_TAG"
else
echo "App $APP already running"
dokku_log_warn "App $APP already running"
fi
plugn trigger proxy-build-config "$APP"
else
echo "App $APP has not been deployed"
dokku_log_warn "App $APP has not been deployed"
fi
}
@@ -109,9 +116,9 @@ ps_stop() {
declare desc="stops app"
local APP="$1"; verify_app_name "$APP"
! (is_deployed "$APP") && echo "App $APP has not been deployed" && exit 0
! (is_deployed "$APP") && dokku_log_warn "App $APP has not been deployed" && exit 0
echo "Stopping $APP ..."
dokku_log_quiet "Stopping $APP ..."
local DOKKU_SCHEDULER=$(config_get "$APP" DOKKU_SCHEDULER || echo "docker-local")
plugn trigger scheduler-stop "$DOKKU_SCHEDULER" "$APP"
plugn trigger post-stop "$APP"
@@ -132,7 +139,7 @@ ps_restart() {
if (is_deployed "$APP"); then
release_and_deploy "$APP" "$IMAGE_TAG"
else
echo "App $APP has not been deployed"
dokku_log_warn "App $APP has not been deployed"
fi
}
@@ -171,3 +178,34 @@ get_restart_policies() {
local -r phase_file_path=$1
get_raw_restart_policies "$phase_file_path" | sed -e 's/^--restart=//g'
}
fn-ps-app-status() {
declare APP="$1"
local PROCS=0 RUNNING=""
local APP_CIDS=$(get_app_container_ids "$APP");
for CID in $APP_CIDS; do
if (is_container_status "$CID" "Running"); then
RUNNING+="0"
else
RUNNING+="1"
fi
PROCS=$((PROCS + 1))
done
if [[ "${#RUNNING}" -eq 0 ]] || [[ "${#RUNNING}" -ne 0 ]] && [[ "$RUNNING" != *"0"* ]]; then
RUNNING="false"
elif [[ "$RUNNING" != *"1"* ]] && [[ "${#RUNNING}" -ne 0 ]]; then
RUNNING="true"
else
RUNNING="mixed"
fi
echo "$PROCS $RUNNING"
}
fn-ps-is-app-running() {
declare APP="$1"
APP_STATUS=$(fn-ps-app-status "$APP")
echo "$APP_STATUS" | cut -d ' ' -f 2
}

View File

@@ -33,27 +33,12 @@ cmd-ps-report-single() {
local APP_DIR="$DOKKU_ROOT/$APP"
[[ "$INFO_FLAG" == "true" ]] && INFO_FLAG=""
local passed_phases="deploy"
local APP_CIDS=$(get_app_container_ids "$APP"); local PROCS=0; local RUNNING=""
for CID in $APP_CIDS; do
if (is_container_status "$CID" "Running"); then
RUNNING+="0"
else
RUNNING+="1"
fi
PROCS=$((PROCS + 1))
done
if [[ "${#RUNNING}" -eq 0 ]] || [[ "${#RUNNING}" -ne 0 ]] && [[ "$RUNNING" != *"0"* ]]; then
RUNNING="false"
elif [[ "$RUNNING" != *"1"* ]] && [[ "${#RUNNING}" -ne 0 ]]; then
RUNNING="true";
else
RUNNING="mixed"
fi
local APP_RUNNING="$(fn-ps-app-status "$APP")"
local PROCS=$(echo "$APP_RUNNING" | cut -d ' ' -f 1)
local RUNNING=$(echo "$APP_RUNNING" | cut -d ' ' -f 2)
if (is_deployed "$APP"); then DEPLOYED="true"; else DEPLOYED="false"; fi
local passed_phases="deploy"
RESTARTPOLICY=$(get_restart_policies "$(get_phase_file_path "$passed_phases")" || true)
local CONTAINER_FILES="$(find "$DOKKU_ROOT/$APP" -maxdepth 1 -name "CONTAINER.*" -printf "%f\n" 2>/dev/null | sort -t . -k 2 -n | xargs)"

View File

@@ -10,7 +10,7 @@ ps_main_cmd() {
[[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on"
local APP="$2"; verify_app_name "$APP"
! (is_deployed "$APP") && echo "App $APP has not been deployed" && exit 0
! (is_deployed "$APP") && dokku_log_warn "App $APP has not been deployed" && exit 0
local DOKKU_APP_RUNNING_CONTAINER_IDS=$(get_app_running_container_ids "$APP")