From b6e7fb5839ef8e6816cd6804c20425bbd9f4f02f Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 8 Jan 2018 04:41:26 -0500 Subject: [PATCH] refactor: ensure parallel runs properly for non-restorable apps and moreutils parallel Refs #3023 --- plugins/ps/subcommands/restore | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/plugins/ps/subcommands/restore b/plugins/ps/subcommands/restore index 818c3d980..19d0a75d6 100755 --- a/plugins/ps/subcommands/restore +++ b/plugins/ps/subcommands/restore @@ -7,9 +7,29 @@ source "$PLUGIN_AVAILABLE_PATH/ps/functions" ps_restore_cmd() { declare desc="starts all apps with DOKKU_APP_RESTORE not set to 0 via command line" local cmd="ps:restore" + local APP="$1" + + if [[ -n "$APP" ]]; then + 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" + fi + else + ps_restore_all + fi +} + +ps_restore_all() { + local GNU_PARALLEL if which parallel > /dev/null 2>&1; then - dokku_apps | parallel dokku ps:start + dokku_log_info1 "Restarting in parallel" + GNU_PARALLEL=$(parallel -V 2>&1 | grep GNU || true) + if [[ -z "$GNU_PARALLEL" ]]; then + parallel -i bash -c "dokku ps:restore {}" -- $(dokku_apps) + else + dokku_apps | parallel --will-cite 'dokku ps:restore {}' + fi return fi