Merge pull request #3586 from dokku/parallel-cleanup
ps plugin parallel usage cleanup
This commit is contained in:
8 files changed
+71
-143
No files matched your search
@@ -114,6 +114,7 @@ The following list config variables have special meaning and can be set in a var
|
|||||||
| `DOKKU_DOCKERFILE_ENTRYPOINT` | dockerfile entrypoint | `dokku config:set` | |
|
| `DOKKU_DOCKERFILE_ENTRYPOINT` | dockerfile entrypoint | `dokku config:set` | |
|
||||||
| `DOKKU_DOCKERFILE_PORTS` | dockerfile ports | `dokku config:set` | |
|
| `DOKKU_DOCKERFILE_PORTS` | dockerfile ports | `dokku config:set` | |
|
||||||
| `DOKKU_DOCKERFILE_START_CMD` | none | `dokku config:set` | |
|
| `DOKKU_DOCKERFILE_START_CMD` | none | `dokku config:set` | |
|
||||||
|
| `DOKKU_PARALLEL_ARGUMENTS`. | none | `dokku config:set` | Allows passing custom arguments to parallel for `ps:*all` commands |
|
||||||
| `DOKKU_PROXY_PORT` | automatically assigned | `dokku config:set` | |
|
| `DOKKU_PROXY_PORT` | automatically assigned | `dokku config:set` | |
|
||||||
| `DOKKU_PROXY_SSL_PORT` | automatically assigned | `dokku config:set` | |
|
| `DOKKU_PROXY_SSL_PORT` | automatically assigned | `dokku config:set` | |
|
||||||
| `DOKKU_PROXY_PORT_MAP` | automatically assigned | `dokku proxy:ports-add` <br /> `dokku proxy:ports-remove`, `dokku proxy:ports-clear` | |
|
| `DOKKU_PROXY_PORT_MAP` | automatically assigned | `dokku proxy:ports-add` <br /> `dokku proxy:ports-remove`, `dokku proxy:ports-clear` | |
|
||||||
|
|||||||
@@ -118,6 +118,13 @@ set_scale() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ps_restore() {
|
||||||
|
declare desc="restores app"
|
||||||
|
local APP="$1"
|
||||||
|
|
||||||
|
ps_start "$APP"
|
||||||
|
}
|
||||||
|
|
||||||
ps_start() {
|
ps_start() {
|
||||||
declare desc="starts app"
|
declare desc="starts app"
|
||||||
local APP="$1"
|
local APP="$1"
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||||
source "$PLUGIN_AVAILABLE_PATH/docker-options/functions"
|
source "$PLUGIN_AVAILABLE_PATH/docker-options/functions"
|
||||||
|
source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
||||||
source "$PLUGIN_AVAILABLE_PATH/ps/functions"
|
source "$PLUGIN_AVAILABLE_PATH/ps/functions"
|
||||||
set -eo pipefail
|
set -eo pipefail
|
||||||
[[ $DOKKU_TRACE ]] && set -x
|
[[ $DOKKU_TRACE ]] && set -x
|
||||||
@@ -117,3 +118,53 @@ cmd-ps-report-single() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn-ps-parallel-cmd() {
|
||||||
|
declare desc="Run a ps command against all apps"
|
||||||
|
declare CMD="$1"
|
||||||
|
local GNU_PARALLEL has_apps=false
|
||||||
|
|
||||||
|
for APP in $(dokku_apps); do
|
||||||
|
has_apps=true
|
||||||
|
break
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ "$has_apps" == "false" ]]; then
|
||||||
|
dokku_log_info1 "No apps detected"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
if which parallel >/dev/null 2>&1; then
|
||||||
|
dokku_log_info1 "Running 'dokku ps:${CMD}' in parallel"
|
||||||
|
GNU_PARALLEL=$(parallel -V 2>&1 | grep GNU || true)
|
||||||
|
if [[ -z "$GNU_PARALLEL" ]]; then
|
||||||
|
# shellcheck disable=SC2046
|
||||||
|
parallel $DOKKU_PARALLEL_ARGUMENTS -i bash -c "dokku ps:${CMD} {}" -- $(dokku_apps)
|
||||||
|
else
|
||||||
|
# shellcheck disable=SC2046
|
||||||
|
dokku_apps | parallel $DOKKU_PARALLEL_ARGUMENTS "dokku ps:${CMD} {}"
|
||||||
|
fi
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
dokku_log_info1 "Running 'dokku ps:${CMD}' in serially"
|
||||||
|
for APP in $(dokku_apps); do
|
||||||
|
if ! (is_deployed "$APP"); then
|
||||||
|
dokku_log_warn "App $APP has not been deployed"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$CMD" == "restore" ]]; then
|
||||||
|
local DOKKU_APP_RESTORE=$(config_get "$APP" DOKKU_APP_RESTORE || true)
|
||||||
|
if [[ "$DOKKU_APP_RESTORE" == 0 ]]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
dokku_log_verbose "Running 'dokku ps:${CMD} $APP' ..."
|
||||||
|
if ps_${CMD} "$APP"; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
dokku_log_warn "dokku ps:${CMD} $APP failed"
|
||||||
|
done
|
||||||
|
}
|
||||||
@@ -2,38 +2,13 @@
|
|||||||
set -eo pipefail
|
set -eo pipefail
|
||||||
[[ $DOKKU_TRACE ]] && set -x
|
[[ $DOKKU_TRACE ]] && set -x
|
||||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||||
source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
source "$PLUGIN_AVAILABLE_PATH/ps/internal-functions"
|
||||||
source "$PLUGIN_AVAILABLE_PATH/ps/functions"
|
|
||||||
|
|
||||||
ps_rebuildall_cmd() {
|
ps_rebuildall_cmd() {
|
||||||
declare desc="rebuilds all apps from source"
|
declare desc="rebuilds all apps from source"
|
||||||
local cmd="ps:rebuildall"
|
local cmd="ps:rebuildall"
|
||||||
local GNU_PARALLEL
|
|
||||||
|
|
||||||
if which parallel >/dev/null 2>&1; then
|
fn-ps-parallel-cmd "rebuild"
|
||||||
dokku_log_info1 "Rebuilding in parallel"
|
|
||||||
GNU_PARALLEL=$(parallel -V 2>&1 | grep GNU || true)
|
|
||||||
if [[ -z "$GNU_PARALLEL" ]]; then
|
|
||||||
# shellcheck disable=SC2046
|
|
||||||
parallel -i bash -c "dokku ps:rebuild {}" -- $(dokku_apps)
|
|
||||||
else
|
|
||||||
dokku_apps | parallel 'dokku ps:rebuild {}'
|
|
||||||
fi
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
for app in $(dokku_apps); do
|
|
||||||
if ! (is_deployed "$app"); then
|
|
||||||
dokku_log_warn "App $app has not been deployed"
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
dokku_log_verbose "Rebuilding app $app ..."
|
|
||||||
if ps_rebuild "$app"; then
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
dokku_log_warn "dokku ps:rebuild ${app} failed"
|
|
||||||
done
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ps_rebuildall_cmd "$@"
|
ps_rebuildall_cmd "$@"
|
||||||
@@ -2,38 +2,13 @@
|
|||||||
set -eo pipefail
|
set -eo pipefail
|
||||||
[[ $DOKKU_TRACE ]] && set -x
|
[[ $DOKKU_TRACE ]] && set -x
|
||||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||||
source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
source "$PLUGIN_AVAILABLE_PATH/ps/internal-functions"
|
||||||
source "$PLUGIN_AVAILABLE_PATH/ps/functions"
|
|
||||||
|
|
||||||
ps_restartall_cmd() {
|
ps_restartall_cmd() {
|
||||||
declare desc="restarts all apps via command line"
|
declare desc="restarts all apps via command line"
|
||||||
local cmd="ps:restartall"
|
local cmd="ps:restartall"
|
||||||
local GNU_PARALLEL
|
|
||||||
|
|
||||||
if which parallel >/dev/null 2>&1; then
|
fn-ps-parallel-cmd "restart"
|
||||||
dokku_log_info1 "Restarting in parallel"
|
|
||||||
GNU_PARALLEL=$(parallel -V 2>&1 | grep GNU || true)
|
|
||||||
if [[ -z "$GNU_PARALLEL" ]]; then
|
|
||||||
# shellcheck disable=SC2046
|
|
||||||
parallel -i bash -c "dokku ps:restart {}" -- $(dokku_apps)
|
|
||||||
else
|
|
||||||
dokku_apps | parallel 'dokku ps:restart {}'
|
|
||||||
fi
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
for app in $(dokku_apps); do
|
|
||||||
if ! (is_deployed "$app"); then
|
|
||||||
dokku_log_warn "App $app has not been deployed"
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
dokku_log_verbose "Restarting app $app ..."
|
|
||||||
if ps_restart "$app"; then
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
dokku_log_warn "dokku ps:restart ${app} failed"
|
|
||||||
done
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ps_restartall_cmd "$@"
|
ps_restartall_cmd "$@"
|
||||||
@@ -4,6 +4,7 @@ set -eo pipefail
|
|||||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||||
source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
||||||
source "$PLUGIN_AVAILABLE_PATH/ps/functions"
|
source "$PLUGIN_AVAILABLE_PATH/ps/functions"
|
||||||
|
source "$PLUGIN_AVAILABLE_PATH/ps/internal-functions"
|
||||||
|
|
||||||
ps_restore_cmd() {
|
ps_restore_cmd() {
|
||||||
declare desc="starts all apps with DOKKU_APP_RESTORE not set to 0 via command line"
|
declare desc="starts all apps with DOKKU_APP_RESTORE not set to 0 via command line"
|
||||||
@@ -12,7 +13,7 @@ ps_restore_cmd() {
|
|||||||
local DOKKU_SCHEDULER
|
local DOKKU_SCHEDULER
|
||||||
|
|
||||||
DOKKU_SCHEDULER=$(get_app_scheduler "$APP")
|
DOKKU_SCHEDULER=$(get_app_scheduler "$APP")
|
||||||
plugn trigger pre-restore "$DOKKU_SCHEDULER"
|
plugn trigger pre-restore "$DOKKU_SCHEDULER" "$APP"
|
||||||
|
|
||||||
if [[ -n "$APP" ]]; then
|
if [[ -n "$APP" ]]; then
|
||||||
if ! (is_deployed "$APP"); then
|
if ! (is_deployed "$APP"); then
|
||||||
@@ -22,43 +23,11 @@ ps_restore_cmd() {
|
|||||||
|
|
||||||
DOKKU_APP_RESTORE="$(config_get "$APP" DOKKU_APP_RESTORE || true)"
|
DOKKU_APP_RESTORE="$(config_get "$APP" DOKKU_APP_RESTORE || true)"
|
||||||
if [[ $DOKKU_APP_RESTORE != 0 ]]; then
|
if [[ $DOKKU_APP_RESTORE != 0 ]]; then
|
||||||
ps_start "$APP" || dokku_log_warn "dokku ps:restore ${APP} failed"
|
ps_restore "$APP" || dokku_log_warn "dokku ps:restore ${APP} failed"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
ps_restore_all
|
fn-ps-parallel-cmd "restore"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
ps_restore_all() {
|
|
||||||
local GNU_PARALLEL
|
|
||||||
|
|
||||||
if which parallel >/dev/null 2>&1; then
|
|
||||||
dokku_log_info1 "Restarting in parallel"
|
|
||||||
GNU_PARALLEL=$(parallel -V 2>&1 | grep GNU || true)
|
|
||||||
if [[ -z "$GNU_PARALLEL" ]]; then
|
|
||||||
# shellcheck disable=SC2046
|
|
||||||
parallel -i bash -c "dokku ps:restore {}" -- $(dokku_apps)
|
|
||||||
else
|
|
||||||
dokku_apps | parallel 'dokku ps:restore {}'
|
|
||||||
fi
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
for app in $(dokku_apps); do
|
|
||||||
if ! (is_deployed "$app"); then
|
|
||||||
dokku_log_warn "App $app has not been deployed"
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
local DOKKU_APP_RESTORE=$(config_get "$app" DOKKU_APP_RESTORE || true)
|
|
||||||
if [[ $DOKKU_APP_RESTORE != 0 ]]; then
|
|
||||||
dokku_log_verbose "Restoring app $app ..."
|
|
||||||
if ps_start "$app"; then
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
dokku_log_warn "dokku ps:restore ${app} failed"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
ps_restore_cmd "$@"
|
ps_restore_cmd "$@"
|
||||||
@@ -2,38 +2,13 @@
|
|||||||
set -eo pipefail
|
set -eo pipefail
|
||||||
[[ $DOKKU_TRACE ]] && set -x
|
[[ $DOKKU_TRACE ]] && set -x
|
||||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||||
source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
source "$PLUGIN_AVAILABLE_PATH/ps/internal-functions"
|
||||||
source "$PLUGIN_AVAILABLE_PATH/ps/functions"
|
|
||||||
|
|
||||||
ps_startall_cmd() {
|
ps_startall_cmd() {
|
||||||
declare desc="starts all apps via command line"
|
declare desc="starts all apps via command line"
|
||||||
local cmd="ps:startall"
|
local cmd="ps:startall"
|
||||||
local GNU_PARALLEL
|
|
||||||
|
|
||||||
if which parallel >/dev/null 2>&1; then
|
fn-ps-parallel-cmd "start"
|
||||||
dokku_log_info1 "Starting in parallel"
|
|
||||||
GNU_PARALLEL=$(parallel -V 2>&1 | grep GNU || true)
|
|
||||||
if [[ -z "$GNU_PARALLEL" ]]; then
|
|
||||||
# shellcheck disable=SC2046
|
|
||||||
parallel -i bash -c "dokku ps:start {}" -- $(dokku_apps)
|
|
||||||
else
|
|
||||||
dokku_apps | parallel 'dokku ps:start {}'
|
|
||||||
fi
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
for app in $(dokku_apps); do
|
|
||||||
if ! (is_deployed "$app"); then
|
|
||||||
dokku_log_warn "App $app has not been deployed"
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
dokku_log_verbose "Starting app $app ..."
|
|
||||||
if ps_start "$app"; then
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
dokku_log_warn "dokku ps:start ${app} failed"
|
|
||||||
done
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ps_startall_cmd "$@"
|
ps_startall_cmd "$@"
|
||||||
@@ -2,38 +2,13 @@
|
|||||||
set -eo pipefail
|
set -eo pipefail
|
||||||
[[ $DOKKU_TRACE ]] && set -x
|
[[ $DOKKU_TRACE ]] && set -x
|
||||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||||
source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
source "$PLUGIN_AVAILABLE_PATH/ps/internal-functions"
|
||||||
source "$PLUGIN_AVAILABLE_PATH/ps/functions"
|
|
||||||
|
|
||||||
ps_stopall_cmd() {
|
ps_stopall_cmd() {
|
||||||
declare desc="stops all apps via command line"
|
declare desc="stops all apps via command line"
|
||||||
local cmd="ps:stopall"
|
local cmd="ps:stopall"
|
||||||
local GNU_PARALLEL
|
|
||||||
|
|
||||||
if which parallel >/dev/null 2>&1; then
|
fn-ps-parallel-cmd "stop"
|
||||||
dokku_log_info1 "Stopping in parallel"
|
|
||||||
GNU_PARALLEL=$(parallel -V 2>&1 | grep GNU || true)
|
|
||||||
if [[ -z "$GNU_PARALLEL" ]]; then
|
|
||||||
# shellcheck disable=SC2046
|
|
||||||
parallel -i bash -c "dokku ps:stop {}" -- $(dokku_apps)
|
|
||||||
else
|
|
||||||
dokku_apps | parallel 'dokku ps:stop {}'
|
|
||||||
fi
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
for app in $(dokku_apps); do
|
|
||||||
if ! (is_deployed "$app"); then
|
|
||||||
dokku_log_warn "App $app has not been deployed"
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
dokku_log_verbose "Stopping app $app ..."
|
|
||||||
if ps_stop "$app"; then
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
dokku_log_warn "dokku ps:stop ${app} failed"
|
|
||||||
done
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ps_stopall_cmd "$@"
|
ps_stopall_cmd "$@"
|
||||||
Reference in new issue
Block a user