refactor: deprecate is_app_running in favor of ps#fn-ps-is-app-running

This will allow us to _actually_ introspect on the running state of an application. In certain cases, the detected state can be "mixed", meaning that we may need to take action, depending on what we want to do in mixed mode.
This commit is contained in:
Jose Diaz-Gonzalez
2018-04-28 01:19:23 -04:00
parent e47f6e5803
commit 8d07ffe775
3 changed files with 36 additions and 19 deletions

View File

@@ -433,6 +433,7 @@ is_container_status() {
is_app_running() {
declare desc="return 0 if given app has a running container"
dokku_log_warn "Deprecated: ps#fn-is-app-running"
local APP="$1"
verify_app_name "$APP"

View File

@@ -171,3 +171,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)"