Merge pull request #1312 from progrium/kilianc_hotfix-#1270
fixes #1270 faulty default container check (uses docker inspect)
This commit is contained in:
2
dokku
2
dokku
@@ -74,7 +74,7 @@ case "$1" in
|
|||||||
|
|
||||||
is_image_buildstep_based "$IMAGE" && DOKKU_BUILDSTEP=true
|
is_image_buildstep_based "$IMAGE" && DOKKU_BUILDSTEP=true
|
||||||
DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE"
|
DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE"
|
||||||
oldids=$(get_container_ids $APP)
|
oldids=$(get_app_container_ids $APP)
|
||||||
|
|
||||||
while read line || [ -n "$line" ]
|
while read line || [ -n "$line" ]
|
||||||
do
|
do
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ case "$1" in
|
|||||||
|
|
||||||
for dokku_app in $dokku_apps; do
|
for dokku_app in $dokku_apps; do
|
||||||
APP=$(basename $dokku_app)
|
APP=$(basename $dokku_app)
|
||||||
DOKKU_APP_CIDS=$(get_container_ids $APP)
|
DOKKU_APP_CIDS=$(get_app_container_ids $APP)
|
||||||
DOCKER_RUNNING_CONTAINERS=$(docker ps -q --no-trunc)
|
DOCKER_RUNNING_CONTAINERS=$(docker ps -q --no-trunc)
|
||||||
if [[ -n $DOKKU_APP_CIDS ]]; then
|
if [[ -n $DOKKU_APP_CIDS ]]; then
|
||||||
for DOKKU_APP_CID in $DOKKU_APP_CIDS; do
|
for DOKKU_APP_CID in $DOKKU_APP_CIDS; do
|
||||||
@@ -138,7 +138,7 @@ case "$1" in
|
|||||||
APP="$2";
|
APP="$2";
|
||||||
|
|
||||||
if (is_deployed $APP); then
|
if (is_deployed $APP); then
|
||||||
CONTAINER_IDS=( $(get_container_ids $APP) )
|
CONTAINER_IDS=( $(get_app_container_ids $APP) )
|
||||||
LAST_CONTAINER_ID=${CONTAINER_IDS[${#CONTAINER_IDS[@]} - 1]}
|
LAST_CONTAINER_ID=${CONTAINER_IDS[${#CONTAINER_IDS[@]} - 1]}
|
||||||
|
|
||||||
if [[ $3 == "-t" ]]; then
|
if [[ $3 == "-t" ]]; then
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ case "$1" in
|
|||||||
echo "Destroying $APP (including all add-ons)"
|
echo "Destroying $APP (including all add-ons)"
|
||||||
|
|
||||||
pluginhook pre-delete $APP
|
pluginhook pre-delete $APP
|
||||||
DOKKU_APP_CIDS=$(get_container_ids $APP)
|
DOKKU_APP_CIDS=$(get_app_container_ids $APP)
|
||||||
if [[ -n $DOKKU_APP_CIDS ]]; then
|
if [[ -n $DOKKU_APP_CIDS ]]; then
|
||||||
for ID in $DOKKU_APP_CIDS;do
|
for ID in $DOKKU_APP_CIDS;do
|
||||||
docker stop $ID > /dev/null || true
|
docker stop $ID > /dev/null || true
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ if [[ -z "$DOKKU_APP_LISTEN_IP" ]] && [[ -f "$DOKKU_ROOT/$APP/IP" ]]; then
|
|||||||
DOKKU_APP_LISTEN_IP=$(< "$DOKKU_ROOT/$APP/IP")
|
DOKKU_APP_LISTEN_IP=$(< "$DOKKU_ROOT/$APP/IP")
|
||||||
fi
|
fi
|
||||||
if [[ -z "$DOKKU_APP_CONTAINER_ID" ]]; then
|
if [[ -z "$DOKKU_APP_CONTAINER_ID" ]]; then
|
||||||
DOKKU_APP_CIDS=( $(get_container_ids $APP) )
|
DOKKU_APP_CIDS=( $(get_app_container_ids $APP) )
|
||||||
DOKKU_APP_CONTAINER_ID=${DOKKU_APP_CIDS[0]}
|
DOKKU_APP_CONTAINER_ID=${DOKKU_APP_CIDS[0]}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -95,7 +95,7 @@ if [[ ! -s "${TMPDIR}/CHECKS" ]] || [[ "$DOKKU_APP_CONTAINER_TYPE" != "web" ]];
|
|||||||
dokku_log_info1 "Waiting for $DOKKU_DEFAULT_WAIT seconds ..."
|
dokku_log_info1 "Waiting for $DOKKU_DEFAULT_WAIT seconds ..."
|
||||||
sleep $DOKKU_DEFAULT_WAIT
|
sleep $DOKKU_DEFAULT_WAIT
|
||||||
|
|
||||||
docker ps -q --no-trunc | grep -q "$DOKKU_APP_CONTAINER_ID" || dokku_log_fail "App container failed to start!!"
|
! (is_container_running $DOKKU_APP_CONTAINER_ID) && dokku_log_fail "App container failed to start!!"
|
||||||
dokku_log_info1 "Default container check successful!" && exit 0
|
dokku_log_info1 "Default container check successful!" && exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -178,16 +178,7 @@ copy_from_image() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
is_deployed() {
|
get_app_container_ids() {
|
||||||
APP="$1"
|
|
||||||
if [[ -f "$DOKKU_ROOT/$APP/CONTAINER" ]] || [[ $(ls $DOKKU_ROOT/$APP/CONTAINER.* &> /dev/null; echo $?) -eq 0 ]];then
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
get_container_ids() {
|
|
||||||
APP="$1"
|
APP="$1"
|
||||||
verify_app_name $APP
|
verify_app_name $APP
|
||||||
[[ -f $DOKKU_ROOT/$APP/CONTAINER ]] && DOKKU_CIDS+=$(< $DOKKU_ROOT/$APP/CONTAINER)
|
[[ -f $DOKKU_ROOT/$APP/CONTAINER ]] && DOKKU_CIDS+=$(< $DOKKU_ROOT/$APP/CONTAINER)
|
||||||
@@ -204,9 +195,53 @@ get_container_ids() {
|
|||||||
|
|
||||||
get_dockerfile_exposed_port() {
|
get_dockerfile_exposed_port() {
|
||||||
local DOCKERFILE_PORT=$(grep "^EXPOSE \+[[:digit:]]\+\(\/tcp\)\? *$" $1 | head -1 | sed 's/EXPOSE \+\([[:digit:]]\+\)\(\/tcp\)\?.*/\1/' || true)
|
local DOCKERFILE_PORT=$(grep "^EXPOSE \+[[:digit:]]\+\(\/tcp\)\? *$" $1 | head -1 | sed 's/EXPOSE \+\([[:digit:]]\+\)\(\/tcp\)\?.*/\1/' || true)
|
||||||
if [[ -n "$DOCKERFILE_PORT" ]]; then
|
echo "$DOCKERFILE_PORT"
|
||||||
echo "$DOCKERFILE_PORT"
|
}
|
||||||
|
|
||||||
|
get_app_running_container_ids() {
|
||||||
|
local APP=$1
|
||||||
|
verify_app_name $APP
|
||||||
|
|
||||||
|
! (is_deployed $APP) && dokku_log_fail "App $APP has not been deployed"
|
||||||
|
local CIDS=$(get_app_container_ids $APP)
|
||||||
|
|
||||||
|
for CID in $CIDS;do
|
||||||
|
local APP_CONTAINER_STATUS=$(docker inspect -f '{{.State.Running}}' "$CID" || true)
|
||||||
|
[[ "$APP_CONTAINER_STATUS" == "true" ]] && local APP_RUNNING_CONTAINER_IDS+="$CID "
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "$APP_RUNNING_CONTAINER_IDS"
|
||||||
|
}
|
||||||
|
|
||||||
|
is_deployed() {
|
||||||
|
APP="$1"
|
||||||
|
if [[ -f "$DOKKU_ROOT/$APP/CONTAINER" ]] || [[ $(ls $DOKKU_ROOT/$APP/CONTAINER.* &> /dev/null; echo $?) -eq 0 ]];then
|
||||||
|
return 0
|
||||||
else
|
else
|
||||||
echo ""
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
is_container_running () {
|
||||||
|
local CID=$1
|
||||||
|
local CONTAINER_STATUS=$(docker inspect -f '{{.State.Running}}' "$CID" || true)
|
||||||
|
|
||||||
|
if [[ "$CONTAINER_STATUS" == "true" ]]; then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
is_app_running() {
|
||||||
|
local APP="$1"
|
||||||
|
verify_app_name $APP
|
||||||
|
|
||||||
|
local APP_RUNNING_CONTAINER_IDS=$(get_app_running_container_ids $APP)
|
||||||
|
|
||||||
|
if [[ -n "$APP_RUNNING_CONTAINER_IDS" ]]; then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ case "$1" in
|
|||||||
shopt -u nullglob
|
shopt -u nullglob
|
||||||
fi
|
fi
|
||||||
|
|
||||||
DOKKU_APP_CIDS=($(get_container_ids $APP))
|
DOKKU_APP_CIDS=($(get_app_container_ids $APP))
|
||||||
docker cp "${DOKKU_APP_CID[0]}:/app/nginx.conf.template" "$APP_NGINX_TEMPLATE" 2> /dev/null || true
|
docker cp "${DOKKU_APP_CID[0]}:/app/nginx.conf.template" "$APP_NGINX_TEMPLATE" 2> /dev/null || true
|
||||||
|
|
||||||
[[ -f "$DOKKU_ROOT/ENV" ]] && source $DOKKU_ROOT/ENV
|
[[ -f "$DOKKU_ROOT/ENV" ]] && source $DOKKU_ROOT/ENV
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ case "$1" in
|
|||||||
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
|
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
|
||||||
verify_app_name "$2"
|
verify_app_name "$2"
|
||||||
|
|
||||||
APP="$2"; CONTAINER_IDS=$(get_container_ids $APP)
|
APP="$2"; CONTAINER_IDS=$(get_app_container_ids $APP)
|
||||||
! (is_deployed $APP) && echo "App $APP has not been deployed" && exit 0
|
! (is_deployed $APP) && echo "App $APP has not been deployed" && exit 0
|
||||||
|
|
||||||
for CID in $CONTAINER_IDS; do
|
for CID in $CONTAINER_IDS; do
|
||||||
@@ -18,12 +18,10 @@ case "$1" in
|
|||||||
|
|
||||||
ps:start)
|
ps:start)
|
||||||
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
|
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
|
||||||
verify_app_name "$2"
|
verify_app_name "$2"; APP="$2"
|
||||||
|
|
||||||
APP="$2"; CONTAINER_IDS=( $(get_container_ids $APP) )
|
|
||||||
! (is_deployed $APP) && echo "App $APP has not been deployed" && exit 0
|
! (is_deployed $APP) && echo "App $APP has not been deployed" && exit 0
|
||||||
|
|
||||||
if [[ "$(docker ps -q --no-trunc| grep -q ${CONTAINER_IDS[0]}; echo $?)" != "0" ]]; then
|
if ! (is_app_running $APP); then
|
||||||
release_and_deploy $APP
|
release_and_deploy $APP
|
||||||
else
|
else
|
||||||
echo "App $APP already running"
|
echo "App $APP already running"
|
||||||
@@ -34,15 +32,13 @@ case "$1" in
|
|||||||
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
|
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
|
||||||
verify_app_name "$2"
|
verify_app_name "$2"
|
||||||
|
|
||||||
APP="$2"; CONTAINER_IDS=$(get_container_ids $APP)
|
APP="$2"; CONTAINER_IDS=$(get_app_container_ids $APP)
|
||||||
! (is_deployed $APP) && echo "App $APP has not been deployed" && exit 0
|
! (is_deployed $APP) && echo "App $APP has not been deployed" && exit 0
|
||||||
|
|
||||||
CONTAINER_IDS_EGREP_PATTERN=$(echo $CONTAINER_IDS | xargs | sed -e "s: :|:g")
|
DOKKU_APP_RUNNING_CONTAINER_IDS=$(get_app_running_container_ids $APP)
|
||||||
if [[ "$(docker ps -q --no-trunc| egrep -q $CONTAINER_IDS_EGREP_PATTERN; echo $?)" = "0" ]]; then
|
if [[ -n "$DOKKU_APP_RUNNING_CONTAINER_IDS" ]]; then
|
||||||
echo "Stopping $APP ..."
|
echo "Stopping $APP ..."
|
||||||
for CID in $CONTAINER_IDS;do
|
docker stop $DOKKU_APP_RUNNING_CONTAINER_IDS > /dev/null || true
|
||||||
docker stop $CID > /dev/null
|
|
||||||
done
|
|
||||||
else
|
else
|
||||||
echo "App $APP already stopped"
|
echo "App $APP already stopped"
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user