diff --git a/plugins/common/functions b/plugins/common/functions index 85ca7e5ae..1ab124c6a 100755 --- a/plugins/common/functions +++ b/plugins/common/functions @@ -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" diff --git a/plugins/ps/functions b/plugins/ps/functions index b65d4cba4..9da0b8ab7 100755 --- a/plugins/ps/functions +++ b/plugins/ps/functions @@ -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 +} \ No newline at end of file diff --git a/plugins/ps/internal-functions b/plugins/ps/internal-functions index 763e2f1b2..dfa8639a0 100755 --- a/plugins/ps/internal-functions +++ b/plugins/ps/internal-functions @@ -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)"