-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #897 from progrium/mh-ps-plugin
initial pass at a ps plugin
- Loading branch information
Showing
8 changed files
with
170 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Process/Container management | ||
|
||
Dokku supports rudimentary process (really container) management via the `ps` plugin. | ||
|
||
``` | ||
ps <app> List processes running in app container(s) | ||
ps:start <app> Start app container(s) | ||
ps:stop <app> Stop app container(s) | ||
ps:restart <app> Restart app container(s) | ||
ps:restartall Restart all deployed app containers | ||
``` | ||
|
||
*NOTE*: As of v0.3.14, `dokku deploy:all` in now deprecated by `ps:restartall` and will be removed in a future version. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#!/usr/bin/env bash | ||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x | ||
|
||
release_and_deploy() { | ||
local APP="$1"; | ||
|
||
if [[ -f "$DOKKU_ROOT/$APP/CONTAINER" ]]; then | ||
echo "-----> Releasing $APP ..." | ||
dokku release $APP | ||
echo "-----> Release complete!" | ||
echo "-----> Deploying $APP ..." | ||
dokku deploy $APP | ||
echo "=====> Application deployed:" | ||
dokku urls $APP | sed "s/^/ /" | ||
echo | ||
fi | ||
} | ||
|
||
case "$1" in | ||
ps) | ||
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 | ||
[[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1 | ||
|
||
APP="$2"; [[ -f "$DOKKU_ROOT/$APP/CONTAINER" ]] && CONTAINER_ID=$(< "$DOKKU_ROOT/$APP/CONTAINER") | ||
[[ -z "$CONTAINER_ID" ]] && echo "App $APP has not been deployed" && exit 0 | ||
|
||
docker exec -ti "$CONTAINER_ID" /bin/bash -c "ps auxwww" | ||
;; | ||
|
||
ps:start) | ||
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 | ||
[[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1 | ||
|
||
APP="$2"; [[ -f "$DOKKU_ROOT/$APP/CONTAINER" ]] && CONTAINER_ID=$(< "$DOKKU_ROOT/$APP/CONTAINER") | ||
[[ -z "$CONTAINER_ID" ]] && echo "App $APP has not been deployed" && exit 0 | ||
|
||
if [[ "$(docker ps -q --no-trunc| grep -q $CONTAINER_ID; echo $?)" != "0" ]]; then | ||
release_and_deploy $APP | ||
else | ||
echo "App $APP already running" | ||
fi | ||
;; | ||
|
||
ps:stop) | ||
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 | ||
[[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1 | ||
|
||
APP="$2"; [[ -f "$DOKKU_ROOT/$APP/CONTAINER" ]] && CONTAINER_ID=$(< "$DOKKU_ROOT/$APP/CONTAINER") | ||
[[ -z "$CONTAINER_ID" ]] && echo "App $APP has not been deployed" && exit 0 | ||
|
||
if [[ "$(docker ps -q --no-trunc| grep -q $CONTAINER_ID; echo $?)" = "0" ]]; then | ||
echo "Stopping $APP ..." | ||
docker stop $CONTAINER_ID > /dev/null | ||
else | ||
echo "App $APP already stopped" | ||
fi | ||
;; | ||
|
||
ps:restart) | ||
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 | ||
[[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1 | ||
|
||
APP="$2"; [[ -f "$DOKKU_ROOT/$APP/CONTAINER" ]] && CONTAINER_ID=$(< "$DOKKU_ROOT/$APP/CONTAINER") | ||
[[ -z "$CONTAINER_ID" ]] && echo "App $APP has not been deployed" && exit 0 | ||
|
||
release_and_deploy $APP | ||
;; | ||
|
||
ps:restartall) | ||
for app in $DOKKU_ROOT/*/CONTAINER; do | ||
APP=$(basename "$(dirname $app)"); | ||
dokku ps:restart $APP | ||
done | ||
;; | ||
|
||
help | ps:help) | ||
cat && cat<<EOF | ||
ps <app> List processes running in app container(s) | ||
ps:start <app> Start app container(s) | ||
ps:stop <app> Stop app container(s) | ||
ps:restart <app> Restart app container(s) | ||
ps:restartall Restart all deployed app containers | ||
EOF | ||
;; | ||
|
||
*) | ||
exit $DOKKU_NOT_IMPLEMENTED_EXIT | ||
;; | ||
|
||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env bats | ||
|
||
load test_helper | ||
|
||
setup() { | ||
deploy_app | ||
} | ||
|
||
teardown() { | ||
destroy_app | ||
} | ||
|
||
@test "ps" { | ||
# CI support: 'Ah. I just spoke with our Docker expert -- | ||
# looks like docker exec is built to work with docker-under-libcontainer, | ||
# but we're using docker-under-lxc. I don't have an estimated time for the fix, sorry | ||
skip "circleci does not support docker exec at the moment." | ||
run bash -c "dokku ps $TEST_APP | grep -q \"node web.js\"" | ||
echo "output: "$output | ||
echo "status: "$status | ||
assert_success | ||
} | ||
|
||
@test "ps:start" { | ||
run bash -c "dokku ps:stop $TEST_APP" | ||
echo "output: "$output | ||
echo "status: "$status | ||
assert_success | ||
run bash -c "dokku ps:start $TEST_APP" | ||
echo "output: "$output | ||
echo "status: "$status | ||
assert_success | ||
run bash -c "docker ps -q --no-trunc | grep -q $(< $DOKKU_ROOT/$TEST_APP/CONTAINER)" | ||
echo "output: "$output | ||
echo "status: "$status | ||
assert_success | ||
} | ||
|
||
@test "ps:stop" { | ||
run bash -c "dokku ps:stop $TEST_APP" | ||
echo "output: "$output | ||
echo "status: "$status | ||
assert_success | ||
run bash -c "docker ps -q --no-trunc | grep -q $(< $DOKKU_ROOT/$TEST_APP/CONTAINER)" | ||
echo "output: "$output | ||
echo "status: "$status | ||
assert_failure | ||
} | ||
|
||
@test "ps:restart" { | ||
run bash -c "dokku ps:restart $TEST_APP" | ||
echo "output: "$output | ||
echo "status: "$status | ||
assert_success | ||
run bash -c "docker ps -q --no-trunc | grep -q $(< $DOKKU_ROOT/$TEST_APP/CONTAINER)" | ||
echo "output: "$output | ||
echo "status: "$status | ||
assert_success | ||
} |