From 792b36d5cc99886d0fe2a3752299c635def0a59b Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Thu, 26 Apr 2018 17:34:06 -0400 Subject: [PATCH] feat: add ps:startall command --- contrib/dokku_client.sh | 2 +- docs/deployment/process-management.md | 11 ++++++++ plugins/ps/commands | 1 + plugins/ps/subcommands/startall | 38 +++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 1 deletion(-) create mode 100755 plugins/ps/subcommands/startall diff --git a/contrib/dokku_client.sh b/contrib/dokku_client.sh index 85c1c1480..1b4b71b2f 100755 --- a/contrib/dokku_client.sh +++ b/contrib/dokku_client.sh @@ -139,7 +139,7 @@ main() { esac [[ " apps certs help ls nginx shell storage trace version " == *" $CMD "* ]] && unset APP - [[ " certs:chain domains:add-global domains:remove-global domains:set-global ps:rebuildall ps:restartall ps:restore " == *" $CMD "* ]] && unset APP + [[ " certs:chain domains:add-global domains:remove-global domains:set-global ps:rebuildall ps:restartall ps:restore ps:startall ps:stopall " == *" $CMD "* ]] && unset APP [[ "$CMD" =~ events*|plugin*|ssh-keys* ]] && unset APP [[ -n "$APP_ARG" ]] && [[ "$APP_ARG" == "--global" ]] && unset APP [[ -n "$@" ]] && [[ -n "$APP" ]] && app_arg="--app $APP" diff --git a/docs/deployment/process-management.md b/docs/deployment/process-management.md index 3e8884a75..b11a919cc 100644 --- a/docs/deployment/process-management.md +++ b/docs/deployment/process-management.md @@ -13,6 +13,7 @@ ps:restartall # Restart all deployed app contai ps:scale = [=] # Get/Set how many instances of a given process to run ps:set-restart-policy # Sets app restart-policy ps:start # Start app container(s) +ps:startall # Start all deployed app containers ps:stop # Stop app container(s) ps:stopall # Stop all app container(s) ``` @@ -114,6 +115,16 @@ All stopped containers can be started using the `ps:start` command. This is simi dokku ps:start node-js-app ``` +### Starting all applications + +In some cases, it may be necessary to start all applications from scratch - eg. if all Docker containers have been manually stopped. This can be executed via the `ps:startall` command, which supports parallelism in the same manner `ps:rebuildall`, `ps:restartall`, and `ps:stopall` do. + +Be aware that no action will be taken if the application containers are running. + +```shell +dokku ps:startall +``` + ## Restart Policies > New as of 0.7.0 diff --git a/plugins/ps/commands b/plugins/ps/commands index ea471f27a..9e6389eb9 100755 --- a/plugins/ps/commands +++ b/plugins/ps/commands @@ -10,6 +10,7 @@ case "$1" in ps , List processes running in app container(s) ps:scale = [=...], Get/Set how many instances of a given process to run ps:start , Start app container(s) + ps:startall, Starts all apps via command line ps:stop , Stop app container(s) ps:stopall, Stop all app container(s) ps:rebuild , Rebuild an app from source diff --git a/plugins/ps/subcommands/startall b/plugins/ps/subcommands/startall new file mode 100755 index 000000000..63c620900 --- /dev/null +++ b/plugins/ps/subcommands/startall @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_AVAILABLE_PATH/config/functions" +source "$PLUGIN_AVAILABLE_PATH/ps/functions" + +ps_startall_cmd() { + declare desc="starts all apps via command line" + local cmd="ps:startall" + local GNU_PARALLEL + + if which parallel > /dev/null 2>&1; then + 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 "$@"