From b6e7fb5839ef8e6816cd6804c20425bbd9f4f02f Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 8 Jan 2018 04:41:26 -0500 Subject: [PATCH 1/8] 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 From 652530a4b4a5764983c48d111e2f4a22b394911e Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 8 Jan 2018 04:45:34 -0500 Subject: [PATCH 2/8] fix: ignore shellcheck rule --- plugins/ps/subcommands/restore | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/ps/subcommands/restore b/plugins/ps/subcommands/restore index 19d0a75d6..f67bd8bb0 100755 --- a/plugins/ps/subcommands/restore +++ b/plugins/ps/subcommands/restore @@ -26,6 +26,7 @@ ps_restore_all() { dokku_log_info1 "Restarting in parallel" GNU_PARALLEL=$(parallel -V 2>&1 | grep GNU || true) if [[ -z "$GNU_PARALLEL" ]]; then + # shellcheck disable=SC2086 parallel -i bash -c "dokku ps:restore {}" -- $(dokku_apps) else dokku_apps | parallel --will-cite 'dokku ps:restore {}' From 58332d707b5b43eb90b4b1038a2b0afaf976c971 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 8 Jan 2018 04:49:42 -0500 Subject: [PATCH 3/8] fix: ignore correct rule --- plugins/ps/subcommands/restore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/ps/subcommands/restore b/plugins/ps/subcommands/restore index f67bd8bb0..5dc244aba 100755 --- a/plugins/ps/subcommands/restore +++ b/plugins/ps/subcommands/restore @@ -26,7 +26,7 @@ ps_restore_all() { dokku_log_info1 "Restarting in parallel" GNU_PARALLEL=$(parallel -V 2>&1 | grep GNU || true) if [[ -z "$GNU_PARALLEL" ]]; then - # shellcheck disable=SC2086 + # shellcheck disable=SC2046 parallel -i bash -c "dokku ps:restore {}" -- $(dokku_apps) else dokku_apps | parallel --will-cite 'dokku ps:restore {}' From 226a3da87dd5973b98f3fda72b8f1410b2208eb4 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Thu, 11 Jan 2018 00:12:41 -0500 Subject: [PATCH 4/8] fix: use correct parameter for APP name --- plugins/ps/subcommands/restore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/ps/subcommands/restore b/plugins/ps/subcommands/restore index 5dc244aba..a363477d1 100755 --- a/plugins/ps/subcommands/restore +++ b/plugins/ps/subcommands/restore @@ -7,7 +7,7 @@ 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" + local APP="$2" if [[ -n "$APP" ]]; then DOKKU_APP_RESTORE="$(config_get "$APP" DOKKU_APP_RESTORE || true)" From 7330a849a5cb60cfb2e5ad14de7577b09a925485 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Thu, 11 Jan 2018 22:35:38 -0500 Subject: [PATCH 5/8] fix: drop will-cite --- plugins/ps/subcommands/restore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/ps/subcommands/restore b/plugins/ps/subcommands/restore index a363477d1..25face8bf 100755 --- a/plugins/ps/subcommands/restore +++ b/plugins/ps/subcommands/restore @@ -29,7 +29,7 @@ ps_restore_all() { # shellcheck disable=SC2046 parallel -i bash -c "dokku ps:restore {}" -- $(dokku_apps) else - dokku_apps | parallel --will-cite 'dokku ps:restore {}' + dokku_apps | parallel 'dokku ps:restore {}' fi return fi From f0ee6288fbe88c78ebc8648ce787a3429853e2a6 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Fri, 12 Jan 2018 01:12:14 -0500 Subject: [PATCH 6/8] feat: ensure we don't try to restore an app that wasn't deployed --- plugins/ps/subcommands/restore | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/ps/subcommands/restore b/plugins/ps/subcommands/restore index 25face8bf..0264d7ec4 100755 --- a/plugins/ps/subcommands/restore +++ b/plugins/ps/subcommands/restore @@ -10,6 +10,11 @@ ps_restore_cmd() { local APP="$2" if [[ -n "$APP" ]]; then + if ! (is_deployed "$APP"); then + dokku_log_warn "App $APP has not been deployed" + return + fi + 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" @@ -37,7 +42,7 @@ ps_restore_all() { for app in $(dokku_apps); do local DOKKU_APP_RESTORE=$(config_get "$app" DOKKU_APP_RESTORE || true) if [[ $DOKKU_APP_RESTORE != 0 ]]; then - echo "Restoring app $app ..." + dokku_log_verbose "Restoring app $app ..." if ps_start "$app"; then continue fi From 7a4ab91ecff115b6d9f6f129ce50812bf6822a75 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Fri, 12 Jan 2018 01:33:29 -0500 Subject: [PATCH 7/8] fix: skip undeployed apps when parallel is not available --- plugins/ps/subcommands/restore | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/ps/subcommands/restore b/plugins/ps/subcommands/restore index 0264d7ec4..9f37cf524 100755 --- a/plugins/ps/subcommands/restore +++ b/plugins/ps/subcommands/restore @@ -40,6 +40,11 @@ ps_restore_all() { 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 ..." From 95243b17571b6557f9005e3932cc621bb2d302e1 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Fri, 12 Jan 2018 04:42:53 -0500 Subject: [PATCH 8/8] fix: test was incorrect --- tests/unit/10_ps-herokuish.bats | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/10_ps-herokuish.bats b/tests/unit/10_ps-herokuish.bats index 6be9d85fb..4bd794222 100644 --- a/tests/unit/10_ps-herokuish.bats +++ b/tests/unit/10_ps-herokuish.bats @@ -142,7 +142,7 @@ teardown() { echo "status: "$status assert_success - run bash -c "dokku ps:restore" + run bash -c "dokku --trace ps:restore" echo "output: "$output echo "status: "$status assert_success @@ -152,7 +152,7 @@ teardown() { echo "status: "$status assert_success - run bash -c "dokku --quiet ls | grep $TEST_APP | grep -q running" + run bash -c "dokku --quiet ls | grep $TEST_APP | grep -q stopped" echo "output: "$output echo "status: "$status assert_success