Skip to content

Commit

Permalink
feat: add command to handle deploy killing
Browse files Browse the repository at this point in the history
  • Loading branch information
josegonzalez committed Sep 24, 2019
1 parent 53ea75a commit 4e0ccc6
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docs/deployment/process-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
```
ps <app> # List processes running in app container(s)
ps:inspect <app> # Displays a sanitized version of docker inspect for an app
ps:kill-deploy <app> # Kill app deploy
ps:rebuild <app> # Rebuild an app from source
ps:rebuildall # Rebuild all apps from source
ps:report [<app>] [<flag>] # Displays a process report for one or more apps
Expand Down Expand Up @@ -45,6 +46,20 @@ dokku ps:inspect node-js-app

This command will gather all the running container IDs for your application and call `docker inspect`, sanitizing the output data so it can be copy-pasted elsewhere safely.

### Killing app deploys

> New as of 0.19.0
It can be useful to kill a deploy if that deploy does not appear to be progressing, is impacting other apps through system resource utilization, or if a successful deploy will result in app errors. To do so, the `ps:kill-deploy` command can be used:

```shell
dokku ps:kill-deploy node-js-app
```

This command will send a `QUIT` signal to the Process Group ID of the process handling the deploy, and should terminate all processes within that process tree. Finally, it will unlock the deploy so that a new deploy may be immediately invoked.

> Warning: This may also result in invalid app state depending upon when the app deploy was killed.
### Rebuilding applications

There are some Dokku commands which will not automatically rebuild an application's environment, or which can be told to skip a rebuild. For instance, you may wish to run multiple `config:set` commands without a restart so as to speed up configuration. In these cases, you can ultimately trigger an application rebuild using `ps:rebuild`
Expand Down
1 change: 1 addition & 0 deletions plugins/ps/commands
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ case "$1" in
cat <<help_content
ps <app>, List processes running in app container(s)
ps:inspect <app>, Displays a sanitized version of docker inspect for an app
ps:kill-deploy <app>, Kill app deploy
ps:scale <app> <proc>=<count> [<proc>=<count>...], Get/Set how many instances of a given process to run
ps:start <app>, Start app container(s)
ps:startall, Starts all apps via command line
Expand Down
37 changes: 37 additions & 0 deletions plugins/ps/subcommands/kill-deploy
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_AVAILABLE_PATH/ps/functions"

ps_kill_deploy_cmd() {
declare desc="kill app deploy"
declare cmd="ps:kill-deploy"
[[ "$1" == "$cmd" ]] && shift 1
declare APP="$1"
verify_app_name "$APP"

local APP_DEPLOY_LOCK_FILE PROCESS_ID PROCESS_GROUP_ID
APP_DEPLOY_LOCK_FILE="$DOKKU_ROOT/$APP/.deploy.lock"
if [[ ! -f "$APP_DEPLOY_LOCK_FILE" ]]; then
dokku_log_info1 "No matching app deploy found"
return
fi

PROCESS_ID="$(cat "$APP_DEPLOY_LOCK_FILE")"
if [[ -z "$PROCESS_ID" ]]; then
dokku_log_info1 "No matching app deploy found"
return
fi

PROCESS_GROUP_ID="$(ps -o pgid= "$PROCESS_ID" || true)"
if [[ -z "$PROCESS_ID" ]]; then
dokku_log_info1 "No matching app deploy found"
return
fi

dokku_log_info1 "Killing app deploy"
kill -quit -- "-${PROCESS_GROUP_ID}" && rm -f "$DOKKU_ROOT/$APP/.deploy.lock"
}

ps_kill_deploy_cmd "$@"

0 comments on commit 4e0ccc6

Please sign in to comment.