diff --git a/.stickler.yml b/.stickler.yml index 0304acb21..aa3813b99 100644 --- a/.stickler.yml +++ b/.stickler.yml @@ -1,7 +1,7 @@ linters: shellcheck: shell: bash - exclude: SC2034 + exclude: SC2034,SC1090 golint: files: diff --git a/docs/deployment/process-management.md b/docs/deployment/process-management.md index db31b020d..3e8884a75 100644 --- a/docs/deployment/process-management.md +++ b/docs/deployment/process-management.md @@ -14,6 +14,7 @@ ps:scale = [=] # Get/Set how many instances of a ps:set-restart-policy # Sets app restart-policy ps:start # Start app container(s) ps:stop # Stop app container(s) +ps:stopall # Stop all app container(s) ``` By default, Dokku will only start a single `web` process - if defined - though process scaling can be managed by the `ps` plugin or [via a custom `DOKKU_SCALE` file](/docs/deployment/process-management.md#manually-managing-process-scaling). @@ -99,6 +100,12 @@ Deployed applications can be stopped using the `ps:stop` command. This turns off dokku ps:stop node-js-app ``` +You may also stop all applications at once: + +```shell +dokku ps:stopall +``` + ### Starting applications All stopped containers can be started using the `ps:start` command. This is similar to running `ps:restart`, except no action will be taken if the application containers are running. diff --git a/docs/development/plugin-triggers.md b/docs/development/plugin-triggers.md index 0e3148c43..8ffb93740 100644 --- a/docs/development/plugin-triggers.md +++ b/docs/development/plugin-triggers.md @@ -744,7 +744,7 @@ verify_app_name "$APP" ### `post-stop` - Description: Can be used to run commands after an application is manually stopped -- Invoked by: `dokku ps:stop` +- Invoked by: `dokku ps:stop` and `dokku ps:stopall` - Arguments: `$APP` - Example: diff --git a/docs/getting-started/uninstalling.md b/docs/getting-started/uninstalling.md index d5c8bc379..dffe3f12a 100644 --- a/docs/getting-started/uninstalling.md +++ b/docs/getting-started/uninstalling.md @@ -36,7 +36,7 @@ All applications should be stopped, and all docker containers and images deleted ```shell # stop all applications -dokku --quiet apps | xargs dokku ps:stop +dokku ps:stopall # cleanup containers and images dokku cleanup diff --git a/docs/getting-started/upgrading.md b/docs/getting-started/upgrading.md index bc123f94c..35ac6afa9 100644 --- a/docs/getting-started/upgrading.md +++ b/docs/getting-started/upgrading.md @@ -39,9 +39,11 @@ If Dokku was installed via `apt-get install dokku` or `bootstrap.sh` (most commo sudo apt-get update # stop each running app -# for 0.8.1 and newer versions, use +# for 0.11.4 and newer versions, use +dokku ps:stopall +# for versions between 0.8.1 and 0.11.3, use dokku --quiet apps:list | xargs -L1 dokku ps:stop -# for older versions, use +# for versions versions older than 0.8.1, use dokku --quiet apps | xargs -L1 dokku ps:stop # update dokku and it's dependencies diff --git a/plugins/ps/commands b/plugins/ps/commands index a17a2ef55..ea471f27a 100755 --- a/plugins/ps/commands +++ b/plugins/ps/commands @@ -11,6 +11,7 @@ case "$1" in ps:scale = [=...], Get/Set how many instances of a given process to run ps:start , Start app container(s) ps:stop , Stop app container(s) + ps:stopall, Stop all app container(s) ps:rebuild , Rebuild an app from source ps:rebuildall, Rebuild all apps from source ps:report [] [], Displays a process report for one or more apps diff --git a/plugins/ps/subcommands/stopall b/plugins/ps/subcommands/stopall new file mode 100755 index 000000000..e867fbaf9 --- /dev/null +++ b/plugins/ps/subcommands/stopall @@ -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_stopall_cmd() { + declare desc="stops all apps via command line" + local cmd="ps:stopall" + local GNU_PARALLEL + + if which parallel > /dev/null 2>&1; then + 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: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 "$@"