Files
dokku/plugins/ps/commands
Jose Diaz-Gonzalez 70511c340d Check if command is implemented in a plugin before executing plugin code
Because of how plugin commands are implemented, their output can be incredibly verbose. Rather than executing even the `set -eo pipefail` parts of a plugin, we immediately check if the command is implemented by a plugin. If it is not, then we continue on as normal.

One side-effect of this change is that plugin commands need to be duplicated again:

- once in the command array
- once for the actual body of the command
- once in the help output

This is also quite hackish, and probably not the best way to decrease trace output. Note that we drop approximately 2k lines worth of logs with this change.
2015-09-18 16:09:59 -04:00

129 lines
3.9 KiB
Bash
Executable File

#!/usr/bin/env bash
[[ " ps ps:start ps:stop ps:rebuild ps:rebuildall ps:restart ps:restartall ps:scale help ps: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/ps/functions"
case "$1" in
ps)
[[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on"
APP="$2"; verify_app_name "$APP"; DOKKU_APP_RUNNING_CONTAINER_IDS=$(get_app_running_container_ids $APP)
! (is_deployed $APP) && echo "App $APP has not been deployed" && exit 0
for CID in $DOKKU_APP_RUNNING_CONTAINER_IDS; do
has_tty && DOKKU_RUN_OPTS="-i -t"
dokku_log_info1_quiet "running processes in container: $CID"
docker exec $DOKKU_RUN_OPTS $CID /bin/sh -c "ps auxwww"
done
;;
ps:start)
[[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on"
APP="$2"; IMAGE_TAG=$(get_running_image_tag $APP);
verify_app_name "$APP"
! (is_deployed $APP) && echo "App $APP has not been deployed" && exit 0
if ! (is_app_running $APP); then
release_and_deploy "$APP" "$IMAGE_TAG"
else
echo "App $APP already running"
fi
;;
ps:stop)
[[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on"
APP="$2"; DOKKU_APP_RUNNING_CONTAINER_IDS=$(get_app_running_container_ids $APP)
verify_app_name "$APP"
! (is_deployed $APP) && echo "App $APP has not been deployed" && exit 0
if [[ -n "$DOKKU_APP_RUNNING_CONTAINER_IDS" ]]; then
echo "Stopping $APP ..."
docker stop $DOKKU_APP_RUNNING_CONTAINER_IDS > /dev/null || true
else
echo "App $APP already stopped"
fi
;;
ps:rebuild)
[[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on"
APP="$2"; verify_app_name "$APP"
plugn trigger receive-app $APP
;;
ps:rebuildall)
shopt -s nullglob
for app in $DOKKU_ROOT/*; do
[[ ! -d $app ]] && continue
APP=$(basename $app)
is_deployed $APP && dokku ps:rebuild $APP
done
shopt -u nullglob
;;
ps:restart)
[[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on"
APP="$2"; IMAGE_TAG=$(get_running_image_tag $APP)
verify_app_name "$APP"
! (is_deployed $APP) && echo "App $APP has not been deployed" && exit 0
release_and_deploy "$APP" "$IMAGE_TAG"
;;
ps:restartall)
shopt -s nullglob
for app in $DOKKU_ROOT/*; do
[[ ! -d $app ]] && continue
APP=$(basename $app)
dokku ps:restart $APP
done
shopt -u nullglob
;;
ps:scale)
[[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on"
APP="$2"; IMAGE_TAG=$(get_running_image_tag $APP)
verify_app_name "$APP"
DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE"
shift 2
[[ ! -e $DOKKU_SCALE_FILE ]] && generate_scale_file "$APP" "$IMAGE_TAG"
if [[ -z "$@" ]];then
dokku_log_info1_quiet "Scaling for $APP"
dokku_col_log_info1_quiet "proctype" "qty"
dokku_col_log_info1_quiet "--------" "---"
while read line || [[ -n "$line" ]]; do
[[ -z "$line" ]] && continue
PROC_NAME=${line%%=*}
PROC_COUNT=${line#*=}
dokku_col_log_info1 "$PROC_NAME" "$PROC_COUNT"
done < "$DOKKU_SCALE_FILE"
else
set_scale "$APP" "$@"
release_and_deploy "$APP" "$IMAGE_TAG"
fi
;;
help | ps:help)
cat<<EOF
ps <app>, List processes running in app container(s)
ps:scale [<app> <proc>=<count> [<proc>=<count>]], Get/Set how many instances of a given process to run
ps:start <app>, Start app container(s)
ps:stop <app>, Stop app container(s)
ps:rebuild <app>, Rebuild an app
ps:rebuildall, Rebuild all apps
ps:restart <app>, Restart app container(s)
ps:restartall, Restart all deployed app containers
EOF
;;
*)
exit $DOKKU_NOT_IMPLEMENTED_EXIT
;;
esac