diff --git a/dokku b/dokku index e3ac8da70..550d29037 100755 --- a/dokku +++ b/dokku @@ -74,21 +74,13 @@ case "$1" in PROC_NAME=${line%%=*} PROC_COUNT=${line#*=} CONTAINER_NUM=1 + oldids=$(get_container_ids $APP) while [[ $CONTAINER_NUM -le $PROC_COUNT ]];do DOKKU_CONTAINER_ID_FILE="$DOKKU_ROOT/$APP/CONTAINER.$PROC_NAME.$CONTAINER_NUM" DOKKU_IP_FILE="$DOKKU_ROOT/$APP/IP.$PROC_NAME.$CONTAINER_NUM" DOKKU_PORT_FILE="$DOKKU_ROOT/$APP/PORT.$PROC_NAME.$CONTAINER_NUM" - # try old form even in case we're migrating dokku versions - if [[ -f "$DOKKU_CONTAINER_ID_FILE" ]]; then - oldids+=" " - oldids+=$(< "$DOKKU_CONTAINER_ID_FILE") - oldids+=" " - elif [[ -f "$DOKKU_ROOT/$APP/CONTAINER" ]]; then - oldids+=$(< "$DOKKU_ROOT/$APP/CONTAINER") - fi - # start the app DOCKER_ARGS=$(: | pluginhook docker-args $APP deploy) DOCKER_ARGS+=$(: | pluginhook docker-args-deploy $APP) diff --git a/plugins/00_dokku-standard/commands b/plugins/00_dokku-standard/commands index a4d50b49d..d8d4dd7ee 100755 --- a/plugins/00_dokku-standard/commands +++ b/plugins/00_dokku-standard/commands @@ -114,8 +114,11 @@ case "$1" in dokku_col_log_info2_quiet "App Name" "Container id" for app in $apps; do - if [[ -f $app/CONTAINER ]]; then - dokku_col_log_msg "$(basename $app)" "$(< $app/CONTAINER)" + DOKKU_APP_CIDS=$(get_container_ids "$(basename $app)") + if [[ -n $DOKKU_APP_CIDS ]]; then + for DOKKU_APP_CID in $DOKKU_APP_CIDS; do + dokku_col_log_msg "$(basename $app)" "$DOKKU_APP_CID" + done else dokku_col_log_msg "$(basename $app)" fi @@ -127,13 +130,23 @@ case "$1" in verify_app_name "$2" APP="$2"; - if [[ -f "$DOKKU_ROOT/$APP/CONTAINER" ]]; then - CONTAINER=$(<$DOKKU_ROOT/$APP/CONTAINER) + if (is_deployed $APP); then + CONTAINER_IDS=( $(get_container_ids $APP) ) + LAST_CONTAINER_ID=${CONTAINER_IDS[${#CONTAINER_IDS[@]} - 1]} + if [[ $3 == "-t" ]]; then - docker logs --follow $CONTAINER + DOKKU_LOGS_ARGS="--follow" else - docker logs $CONTAINER | tail -n 100 + DOKKU_LOGS_ARGS="--tail 100" fi + for CID in "${CONTAINER_IDS[@]}";do + if [[ "$CID" != "$LAST_CONTAINER_ID" ]];then + DOKKU_LOGS_CMD+="docker logs $DOKKU_LOGS_ARGS $CID& " + else + DOKKU_LOGS_CMD+="docker logs $DOKKU_LOGS_ARGS $CID; " + fi + done + bash -c "($DOKKU_LOGS_CMD)" else echo "Application's container not found" fi diff --git a/plugins/apps/commands b/plugins/apps/commands index a82aa1e4f..935d2b1f7 100755 --- a/plugins/apps/commands +++ b/plugins/apps/commands @@ -40,11 +40,12 @@ case "$1" in echo "Destroying $APP (including all add-ons)" pluginhook pre-delete $APP - if [[ -f "$DOKKU_ROOT/$APP/CONTAINER" ]]; then - ID=$(< "$DOKKU_ROOT/$APP/CONTAINER") - - docker stop $ID > /dev/null || true - docker rm $ID > /dev/null || true + DOKKU_APP_CIDS=$(get_container_ids $APP) + if [[ -n $DOKKU_APP_CIDS ]]; then + for ID in $DOKKU_APP_CIDS;do + docker stop $ID > /dev/null || true + docker rm $ID > /dev/null || true + done fi docker images | grep $IMAGE | awk '{print $3}' | xargs docker rmi &> /dev/null & diff --git a/plugins/checks/check-deploy b/plugins/checks/check-deploy index a6a67deb8..632f5d4e4 100755 --- a/plugins/checks/check-deploy +++ b/plugins/checks/check-deploy @@ -44,8 +44,9 @@ fi if [[ -z "$DOKKU_APP_LISTEN_IP" ]] && [[ -f "$DOKKU_ROOT/$APP/IP" ]]; then DOKKU_APP_LISTEN_IP=$(< "$DOKKU_ROOT/$APP/IP") fi -if [[ -z "$DOKKU_APP_CONTAINER_ID" ]] && [[ -f "$DOKKU_ROOT/$APP/CONTAINER" ]]; then - DOKKU_APP_CONTAINER_ID=$(< "$DOKKU_ROOT/$APP/CONTAINER") +if [[ -z "$DOKKU_APP_CONTAINER_ID" ]]; then + DOKKU_APP_CIDS=( $(get_container_ids $APP) ) + DOKKU_APP_CONTAINER_ID=${DOKKU_APP_CIDS[0]} fi diff --git a/plugins/common/functions b/plugins/common/functions index a48b5c499..809d7435d 100755 --- a/plugins/common/functions +++ b/plugins/common/functions @@ -143,3 +143,28 @@ copy_from_image() { docker cp "$CID:$SRC_FILE" "$DST_DIR" docker rm -f "$CID" } + +is_deployed() { + APP="$1" + verify_app_name $APP + if [[ -f $DOKKU_ROOT/$APP/CONTAINER ]] || ls $DOKKU_ROOT/$APP/CONTAINER.* &> /dev/null;then + return 0 + else + return 1 + fi +} + +get_container_ids() { + APP="$1" + verify_app_name $APP + [[ -f $DOKKU_ROOT/$APP/CONTAINER ]] && DOKKU_CIDS+=$(< $DOKKU_ROOT/$APP/CONTAINER) + + shopt -s nullglob + for DOKKU_CID_FILE in $DOKKU_ROOT/$APP/CONTAINER.*; do + DOKKU_CIDS+=" " + DOKKU_CIDS+=$(< $DOKKU_CID_FILE) + DOKKU_CIDS+=" " + done + shopt -u nullglob + echo $DOKKU_CIDS +} diff --git a/plugins/nginx-vhosts/commands b/plugins/nginx-vhosts/commands index bd52c7c58..8ec5b41d7 100755 --- a/plugins/nginx-vhosts/commands +++ b/plugins/nginx-vhosts/commands @@ -118,14 +118,12 @@ EOF dokku_log_info1 "Creating $SCHEME nginx.conf" mv $NGINX_CONF "$DOKKU_ROOT/$APP/nginx.conf" - if [[ -n "$DOKKU_APP_LISTEN_PORT" ]] && [[ -n "$DOKKU_APP_LISTEN_IP" ]]; then - dokku_log_info1 "Running nginx-pre-reload" - pluginhook nginx-pre-reload $APP $DOKKU_APP_LISTEN_PORT $DOKKU_APP_LISTEN_IP + dokku_log_info1 "Running nginx-pre-reload" + pluginhook nginx-pre-reload $APP $DOKKU_APP_LISTEN_PORT $DOKKU_APP_LISTEN_IP - dokku_log_verbose "Reloading nginx" - validate_nginx - restart_nginx - fi + dokku_log_verbose "Reloading nginx" + validate_nginx + restart_nginx echo "# THIS FILE IS GENERATED BY DOKKU - DO NOT EDIT, YOUR CHANGES WILL BE OVERWRITTEN" > $URLS_PATH xargs -i echo "https://{}" <<< "${SSL_VHOSTS}" >> $URLS_PATH diff --git a/plugins/ps/commands b/plugins/ps/commands index be707dc10..f1a25d7f0 100755 --- a/plugins/ps/commands +++ b/plugins/ps/commands @@ -29,20 +29,22 @@ case "$1" in [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 verify_app_name "$2" - APP="$2"; [[ -f "$DOKKU_ROOT/$APP/CONTAINER" ]] && CONTAINER_ID=$(< "$DOKKU_ROOT/$APP/CONTAINER") - [[ -z "$CONTAINER_ID" ]] && echo "App $APP has not been deployed" && exit 0 + APP="$2"; CONTAINER_IDS=$(get_container_ids $APP) + ! (is_deployed $APP) && echo "App $APP has not been deployed" && exit 0 - docker exec -ti "$CONTAINER_ID" /bin/bash -c "ps auxwww" + for CID in $CONTAINER_IDS; do + docker exec -ti "$CID" /bin/bash -c "ps auxwww" + done ;; ps:start) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 verify_app_name "$2" - APP="$2"; [[ -f "$DOKKU_ROOT/$APP/CONTAINER" ]] && CONTAINER_ID=$(< "$DOKKU_ROOT/$APP/CONTAINER") - [[ -z "$CONTAINER_ID" ]] && echo "App $APP has not been deployed" && exit 0 + APP="$2"; CONTAINER_IDS=( $(get_container_ids $APP) ) + ! (is_deployed $APP) && echo "App $APP has not been deployed" && exit 0 - if [[ "$(docker ps -q --no-trunc| grep -q $CONTAINER_ID; echo $?)" != "0" ]]; then + if [[ "$(docker ps -q --no-trunc| grep -q ${CONTAINER_IDS[0]}; echo $?)" != "0" ]]; then release_and_deploy $APP else echo "App $APP already running" @@ -53,12 +55,15 @@ case "$1" in [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 verify_app_name "$2" - APP="$2"; [[ -f "$DOKKU_ROOT/$APP/CONTAINER" ]] && CONTAINER_ID=$(< "$DOKKU_ROOT/$APP/CONTAINER") - [[ -z "$CONTAINER_ID" ]] && echo "App $APP has not been deployed" && exit 0 + APP="$2"; CONTAINER_IDS=$(get_container_ids $APP) + ! (is_deployed $APP) && echo "App $APP has not been deployed" && exit 0 - if [[ "$(docker ps -q --no-trunc| grep -q $CONTAINER_ID; echo $?)" = "0" ]]; then + CONTAINER_IDS_EGREP_PATTERN=$(echo $CONTAINER_IDS | xargs | sed -e "s: :|:g") + if [[ "$(docker ps -q --no-trunc| egrep -q $CONTAINER_IDS_EGREP_PATTERN; echo $?)" = "0" ]]; then echo "Stopping $APP ..." - docker stop $CONTAINER_ID > /dev/null + for CID in $CONTAINER_IDS;do + docker stop $CID > /dev/null + done else echo "App $APP already stopped" fi @@ -74,18 +79,19 @@ case "$1" in ps:rebuildall) shopt -s nullglob - for app in $DOKKU_ROOT/*/CONTAINER; do - APP=$(basename "$(dirname $app)"); - dokku ps:rebuild $APP + for app in $DOKKU_ROOT/*; do + APP=$(basename "$(dirname $app)") + is_deployed && dokku ps:rebuild $APP done + shopt -u nullglob ;; ps:restart) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 verify_app_name "$2" - APP="$2"; [[ -f "$DOKKU_ROOT/$APP/CONTAINER" ]] && CONTAINER_ID=$(< "$DOKKU_ROOT/$APP/CONTAINER") - [[ -z "$CONTAINER_ID" ]] && echo "App $APP has not been deployed" && exit 0 + APP="$2" + ! (is_deployed $APP) && echo "App $APP has not been deployed" && exit 0 release_and_deploy $APP ;;