subcommand restructure and bashstyle refactor. closes #1579

This commit is contained in:
Michael S. Hobbs
2016-03-01 13:26:35 -08:00
committed by Michael Hobbs
parent 76e27f0333
commit 89f289b433
105 changed files with 1969 additions and 1306 deletions

View File

@@ -1,63 +1,8 @@
#!/usr/bin/env bash
[[ " ps ps:start ps:stop ps:rebuild ps:rebuildall ps:restart ps:restartall ps:restore ps:scale help ps:help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT"
[[ " 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"
ps_main "$2"
;;
ps:start)
[[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on"
ps_start "$2"
;;
ps:stop)
[[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on"
ps_stop "$2"
;;
ps:rebuild)
[[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on"
ps_rebuild "$2"
;;
ps:rebuildall)
for app in $(dokku_apps); do
is_deployed "$app" && ps_rebuild "$app"
done
;;
ps:restart)
[[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on"
ps_restart "$2"
;;
ps:restartall)
for app in $(dokku_apps); do
ps_restart "$app"
done
;;
ps:restore)
for app in $(dokku_apps); do
DOKKU_APP_RESTORE=$(dokku config:get "$app" DOKKU_APP_RESTORE || true)
if [[ $DOKKU_APP_RESTORE != 0 ]]; then
echo "Restoring app $app ..."
ps_start "$app"
fi
done
;;
ps:scale)
[[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on"
shift 1
ps_scale "$@"
;;
help | ps:help)
cat<<EOF
ps <app>, List processes running in app container(s)

View File

@@ -3,6 +3,7 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
print_dokku_scale_file() {
local desc="prints contents of DOKKU_SCALE file"
local APP="$1"; local DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE"
while read -r line || [[ -n "$line" ]]; do
dokku_log_info2_quiet "$line"
@@ -10,6 +11,7 @@ print_dokku_scale_file() {
}
extract_procfile() {
local desc="extracts procfile from app image"
local APP="$1"
local IMAGE_TAG="$(get_running_image_tag "$APP")"
local IMAGE="$(get_app_image_name "$APP" "$IMAGE_TAG")"
@@ -25,6 +27,7 @@ extract_procfile() {
}
remove_procfile() {
local desc="removes DOKKU_PROCFILE"
local APP="$1"; local DOKKU_PROCFILE="$DOKKU_ROOT/$APP/DOKKU_PROCFILE"
if [[ -f "$DOKKU_PROCFILE" ]]; then
rm -f "$DOKKU_PROCFILE"
@@ -32,6 +35,7 @@ remove_procfile() {
}
generate_scale_file() {
local desc="generates DOKKU_SCALE file"
local APP="$1"; local IMAGE_TAG="$2"; local IMAGE=$(get_app_image_name "$APP" "$IMAGE_TAG"); local DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE"
local DOKKU_PROCFILE="$DOKKU_ROOT/$APP/DOKKU_PROCFILE"
verify_app_name "$APP"
@@ -64,6 +68,7 @@ generate_scale_file() {
}
set_scale() {
local desc="sets app proc type scaling"
local APP="$1"; local DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE"
shift 1
local SCALE_SETTINGS=("$@")
@@ -80,21 +85,8 @@ set_scale() {
done
}
ps_main() {
local APP="$1"; verify_app_name "$APP"
local 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"
# shellcheck disable=SC2086
docker exec $DOKKU_RUN_OPTS $CID /bin/sh -c "ps auxwww"
done
}
ps_start() {
local desc="starts app"
local APP="$1"; verify_app_name "$APP"
local IMAGE_TAG=$(get_running_image_tag "$APP");
@@ -108,6 +100,7 @@ ps_start() {
}
ps_stop() {
local desc="stops app"
local APP="$1"; verify_app_name "$APP"
local DOKKU_APP_RUNNING_CONTAINER_IDS=$(get_app_running_container_ids "$APP")
@@ -124,12 +117,14 @@ ps_stop() {
}
ps_rebuild() {
local desc="rebuilds app from base image"
local APP="$1"; verify_app_name "$APP"
plugn trigger receive-app "$APP"
}
ps_restart() {
local desc="restarts app"
local APP="$1"; verify_app_name "$APP"
local IMAGE_TAG=$(get_running_image_tag "$APP")
@@ -139,6 +134,7 @@ ps_restart() {
}
ps_scale() {
local desc="sets app scaling config according arguments; otherwise according to DOKKU_SCALE file"
local APP="$1"; verify_app_name "$APP"
local IMAGE_TAG=$(get_running_image_tag "$APP")
local DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE"

23
plugins/ps/subcommands/default Executable file
View File

@@ -0,0 +1,23 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
ps_main_cmd() {
local desc="shows running processes in all running app containers"
local cmd="ps"
[[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on"
local APP="$2"; verify_app_name "$APP"
local 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"
# shellcheck disable=SC2086
docker exec $DOKKU_RUN_OPTS $CID /bin/sh -c "ps auxwww"
done
}
ps_main_cmd "$@"

13
plugins/ps/subcommands/rebuild Executable file
View File

@@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_AVAILABLE_PATH/ps/functions"
ps_rebuild_cmd() {
local desc="rebuilds app via command line"
local cmd="ps:rebuild"
[[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on"
ps_rebuild "$2"
}
ps_rebuild_cmd "$@"

View File

@@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_AVAILABLE_PATH/ps/functions"
ps_rebuildall_cmd() {
local desc="rebuilds all deployed apps via command line"
local cmd="ps:rebuildall"
for app in $(dokku_apps); do
is_deployed "$app" && ps_rebuild "$app"
done
}
ps_rebuildall_cmd "$@"

13
plugins/ps/subcommands/restart Executable file
View File

@@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_AVAILABLE_PATH/ps/functions"
ps_restart_cmd() {
local desc="restarts app via command line"
local cmd="ps:restart"
[[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on"
ps_restart "$2"
}
ps_restart_cmd "$@"

View File

@@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_AVAILABLE_PATH/ps/functions"
ps_restartall_cmd() {
local desc="restarts all apps via command line"
local cmd="ps:restartall"
for app in $(dokku_apps); do
ps_restart "$app"
done
}
ps_restartall_cmd "$@"

18
plugins/ps/subcommands/restore Executable file
View File

@@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_AVAILABLE_PATH/ps/functions"
ps_restore_cmd() {
local desc="starts all apps with DOKKU_APP_RESTORE not set to 0 via command line"
local cmd="ps:restore"
for app in $(dokku_apps); do
local DOKKU_APP_RESTORE=$(dokku config:get "$app" DOKKU_APP_RESTORE || true)
if [[ $DOKKU_APP_RESTORE != 0 ]]; then
echo "Restoring app $app ..."
ps_start "$app"
fi
done
}
ps_restore_cmd "$@"

14
plugins/ps/subcommands/scale Executable file
View File

@@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_AVAILABLE_PATH/ps/functions"
ps_scale_cmd() {
local desc="sets app scaling config via command line"
local cmd="ps:scale"
[[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on"
shift 1
ps_scale "$@"
}
ps_scale_cmd "$@"

13
plugins/ps/subcommands/start Executable file
View File

@@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_AVAILABLE_PATH/ps/functions"
ps_start_cmd() {
local desc="starts app via command line"
local cmd="ps:start"
[[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on"
ps_start "$2"
}
ps_start_cmd "$@"

13
plugins/ps/subcommands/stop Executable file
View File

@@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_AVAILABLE_PATH/ps/functions"
ps_stop_cmd() {
local desc="stops app via command line"
local cmd="ps:stop"
[[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on"
ps_stop "$2"
}
ps_stop_cmd "$@"