diff --git a/plugins/00_dokku-standard/commands b/plugins/00_dokku-standard/commands index a3dc43779e8..00abdf9dcba 100755 --- a/plugins/00_dokku-standard/commands +++ b/plugins/00_dokku-standard/commands @@ -1,5 +1,5 @@ #!/usr/bin/env bash -[[ " build release trace delete ls logs run url urls version help " == *" $1 "* ]] || exit $DOKKU_NOT_IMPLEMENTED_EXIT +[[ " build release trace delete ls run url urls version help " == *" $1 "* ]] || exit $DOKKU_NOT_IMPLEMENTED_EXIT set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" @@ -126,32 +126,6 @@ case "$1" in done ;; - logs) - [[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on" - APP="$2"; verify_app_name "$2" - - if (is_deployed $APP); then - CONTAINER_IDS=( $(get_app_container_ids $APP) ) - LAST_CONTAINER_ID=${CONTAINER_IDS[${#CONTAINER_IDS[@]} - 1]} - - if [[ $3 == "-t" ]]; then - DOKKU_LOGS_ARGS="--follow --tail 100" - else - 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 - ;; - run) [[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on" APP="$2"; IMAGE_TAG=$(get_running_image_tag $APP); IMAGE=$(get_app_image_name $APP $IMAGE_TAG) @@ -217,7 +191,6 @@ case "$1" in help) cat< [-t], Show the last logs for an application (-t follows) run , Run a command in the environment of an application url , Show the first URL for an application (compatibility) urls , Show all URLs for an application diff --git a/plugins/logs/commands b/plugins/logs/commands new file mode 100755 index 00000000000..d6778f02275 --- /dev/null +++ b/plugins/logs/commands @@ -0,0 +1,49 @@ +#!/usr/bin/env bash +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_AVAILABLE_PATH/config/functions" +source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/functions" + +case "$1" in + logs) + [[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on" + APP="$2"; verify_app_name "$2" + APP_ROOT="$DOKKU_ROOT/$APP" + COLORS=(36 33 32 35 31) + + if (is_deployed "$APP"); then + CONTAINERS=("$APP_ROOT"/CONTAINER.*) + if [[ $3 == "-t" ]]; then + DOKKU_LOGS_ARGS="--follow --tail 100" + else + DOKKU_LOGS_ARGS="--tail 100" + fi + ((MAX_INDEX=${#CONTAINERS[*]} - 1)) || true + for i in ${!CONTAINERS[*]}; do + DYNO=$(echo "${CONTAINERS[i]}" | sed -r 's/.*CONTAINER\.(.*)/\1/') + CID=$(< "${CONTAINERS[i]}") + COLOR=${COLORS[i % ${#COLORS[*]}]} + DOKKU_LOGS_CMD+="(docker logs -t $DOKKU_LOGS_ARGS $CID 2>&1 | sed -r 's/^([^Z]+Z )/\x1b[${COLOR}m\1$APP[$DYNO]:\x1b[0m /gm')" + if [[ $i != "$MAX_INDEX" ]]; then + DOKKU_LOGS_CMD+="& " + else + DOKKU_LOGS_CMD+="; " + fi + done + bash -c "($DOKKU_LOGS_CMD)" + else + echo "Application's container not found" + fi + ;; + + help) + cat< [-t], Show the last logs for an application (-t follows) +EOF + ;; + + *) + exit $DOKKU_NOT_IMPLEMENTED_EXIT + ;; + +esac diff --git a/plugins/logs/plugin.toml b/plugins/logs/plugin.toml new file mode 100644 index 00000000000..574203ea3f0 --- /dev/null +++ b/plugins/logs/plugin.toml @@ -0,0 +1,4 @@ +[plugin] +description = "dokku core logs plugin" +version = "0.4.0" +[plugin.config]