refactor: use a single method for running the ps:*all commands
This reduces the duplication at the cost of slightly more complexity.
This commit is contained in:
@@ -4,6 +4,7 @@ set -eo pipefail
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/ps/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/ps/internal-functions"
|
||||
|
||||
ps_restore_cmd() {
|
||||
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
|
||||
|
||||
DOKKU_SCHEDULER=$(get_app_scheduler "$APP")
|
||||
plugn trigger pre-restore "$DOKKU_SCHEDULER"
|
||||
plugn trigger pre-restore "$DOKKU_SCHEDULER" "$APP"
|
||||
|
||||
if [[ -n "$APP" ]]; then
|
||||
if ! (is_deployed "$APP"); then
|
||||
@@ -22,43 +23,11 @@ ps_restore_cmd() {
|
||||
|
||||
DOKKU_APP_RESTORE="$(config_get "$APP" DOKKU_APP_RESTORE || true)"
|
||||
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
|
||||
else
|
||||
ps_restore_all
|
||||
fn-ps-parallel-cmd "restore"
|
||||
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 "$@"
|
||||
|
||||
Reference in New Issue
Block a user