From c0028f122bfb6d471237ab4032104ce2d2b86c3e Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Wed, 14 Jan 2015 15:19:58 -0800 Subject: [PATCH 1/7] initial pass at a ps plugin --- plugins/ps/commands | 82 +++++++++++++++++++++++++++++++++++++++++++++ tests/unit/ps.bats | 55 ++++++++++++++++++++++++++++++ 2 files changed, 137 insertions(+) create mode 100755 plugins/ps/commands create mode 100644 tests/unit/ps.bats diff --git a/plugins/ps/commands b/plugins/ps/commands new file mode 100755 index 000000000..26ac34d15 --- /dev/null +++ b/plugins/ps/commands @@ -0,0 +1,82 @@ +#!/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 1 + + 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 1 + + 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 1 + + 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 1 + + release_and_deploy $APP + ;; + + help | ps:help) + cat && cat< List containers for app + ps:start Start app container(s) + ps:stop Stop app container(s) + ps:restart Restart app container(s) +EOF + ;; + + *) + exit $DOKKU_NOT_IMPLEMENTED_EXIT + ;; + +esac diff --git a/tests/unit/ps.bats b/tests/unit/ps.bats new file mode 100644 index 000000000..58d6e787f --- /dev/null +++ b/tests/unit/ps.bats @@ -0,0 +1,55 @@ +#!/usr/bin/env bats + +load test_helper + +setup() { + deploy_app +} + +teardown() { + destroy_app +} + +@test "ps" { + 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 +} From 61e154899b2ed94205ef3e4cd0a99ae1396c6bc8 Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Wed, 14 Jan 2015 15:25:53 -0800 Subject: [PATCH 2/7] use ps:restart for config and domains plugins --- plugins/config/commands | 15 +-------------- plugins/domains/commands | 15 +-------------- 2 files changed, 2 insertions(+), 28 deletions(-) diff --git a/plugins/config/commands b/plugins/config/commands index bb46313e2..f6d73e017 100755 --- a/plugins/config/commands +++ b/plugins/config/commands @@ -35,26 +35,13 @@ config_styled_hash () { done <<< "$vars" } -config_restart_app() { - 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 "-----> Deploy complete!" - fi -} - config_write() { ENV_TEMP="$1" echo -e "$ENV_TEMP" | sed '/^$/d' | sort > $ENV_FILE_TEMP if ! cmp -s $ENV_FILE $ENV_FILE_TEMP; then cp -f $ENV_FILE_TEMP $ENV_FILE chmod 600 $ENV_FILE - config_restart_app $APP + dokku ps:restart $APP fi rm -f $ENV_FILE_TEMP } diff --git a/plugins/domains/commands b/plugins/domains/commands index e3a9825f6..97f8569cb 100755 --- a/plugins/domains/commands +++ b/plugins/domains/commands @@ -16,19 +16,6 @@ RE_IPV6="${RE_IPV6}fe08:(:[0-9a-fA-F]{1,4}){2,2}%[0-9a-zA-Z]{1,}|" # TEST: f RE_IPV6="${RE_IPV6}::(ffff(:0{1,4}){0,1}:){0,1}${RE_IPV4}|" # TEST: ::255.255.255.255 ::ffff:255.255.255.255 ::ffff:0:255.255.255.255 (IPv4-mapped IPv6 addresses and IPv4-translated addresses) RE_IPV6="${RE_IPV6}([0-9a-fA-F]{1,4}:){1,4}:${RE_IPV4}" # TEST: 2001:db8:3:4::192.0.2.33 64:ff9b::192.0.2.33 -domains_restart_app() { - 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 "-----> Deploy complete!" - fi -} - case "$1" in domains) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 @@ -92,7 +79,7 @@ case "$1" in dokku domains:setup $APP echo "$3" >> "$DOKKU_ROOT/$APP/VHOST" # we need to restart the app to make sure we're binding to the appropriate network interface - domains_restart_app $APP + dokku ps:restart $APP pluginhook post-domains-update $APP echo "-----> Added $3 to $APP" From 376e1d3411e48d81821aa9ddf87cd42628bf034a Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Wed, 14 Jan 2015 16:23:02 -0800 Subject: [PATCH 3/7] ps docs --- docs/process-management.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 docs/process-management.md diff --git a/docs/process-management.md b/docs/process-management.md new file mode 100644 index 000000000..b832e33fe --- /dev/null +++ b/docs/process-management.md @@ -0,0 +1,10 @@ +# Process/Container management + +Dokku supports rudimentary process (really container) management via the `ps` plugin. + +``` +ps List processes running in app container(s) +ps:restart Restart app container(s) +ps:start Start app container(s) +ps:stop Stop app container(s) +``` From 17d78856e06d2503fbf02f628279589c2200bd70 Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Wed, 14 Jan 2015 16:24:09 -0800 Subject: [PATCH 4/7] skip one ps test as circleci does not yet support `docker exec` --- tests/unit/ps.bats | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/ps.bats b/tests/unit/ps.bats index 58d6e787f..a6ba7ca75 100644 --- a/tests/unit/ps.bats +++ b/tests/unit/ps.bats @@ -11,6 +11,7 @@ teardown() { } @test "ps" { + 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 From 94908894117632d9688a31d2b2a91324a8ea853b Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Wed, 14 Jan 2015 16:25:13 -0800 Subject: [PATCH 5/7] allow ps to be used by plugins that support pre container actions --- plugins/ps/commands | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/ps/commands b/plugins/ps/commands index 26ac34d15..ca3ac5072 100755 --- a/plugins/ps/commands +++ b/plugins/ps/commands @@ -22,7 +22,7 @@ case "$1" in [[ ! -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 1 + [[ -z "$CONTAINER_ID" ]] && echo "App $APP has not been deployed" && exit 0 docker exec -ti "$CONTAINER_ID" /bin/bash -c "ps auxwww" ;; @@ -32,7 +32,7 @@ case "$1" in [[ ! -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 1 + [[ -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 @@ -46,7 +46,7 @@ case "$1" in [[ ! -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 1 + [[ -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 ..." @@ -61,14 +61,14 @@ case "$1" in [[ ! -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 1 + [[ -z "$CONTAINER_ID" ]] && echo "App $APP has not been deployed" && exit 0 release_and_deploy $APP ;; help | ps:help) cat && cat< List containers for app + ps List processes running in app container(s) ps:start Start app container(s) ps:stop Stop app container(s) ps:restart Restart app container(s) From e760e1cc9297dc5945815b068d62c12ba3eb24eb Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Wed, 14 Jan 2015 16:37:18 -0800 Subject: [PATCH 6/7] implement ps:restartall. closes #82 #218 --- docs/process-management.md | 3 ++- docs/upgrading.md | 2 +- dokku | 8 -------- plugins/00_dokku-standard/install | 4 ++-- plugins/ps/commands | 8 ++++++++ 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/docs/process-management.md b/docs/process-management.md index b832e33fe..0da24ae37 100644 --- a/docs/process-management.md +++ b/docs/process-management.md @@ -4,7 +4,8 @@ Dokku supports rudimentary process (really container) management via the `ps` pl ``` ps List processes running in app container(s) -ps:restart Restart app container(s) ps:start Start app container(s) ps:stop Stop app container(s) +ps:restart Restart app container(s) +ps:restartall Restart all deployed app containers ``` diff --git a/docs/upgrading.md b/docs/upgrading.md index 919d4bd5e..6af7ee298 100644 --- a/docs/upgrading.md +++ b/docs/upgrading.md @@ -60,7 +60,7 @@ There is an upgrade [script](https://gist.github.com/plietar/7201430), which is 1. run the script as root 2. `git pull` to get the latest version of dokku 3. make install -4. `dokku deploy:all` +4. `dokku ps:restartall` TDB. diff --git a/dokku b/dokku index 9f9819851..1afae5002 100755 --- a/dokku +++ b/dokku @@ -157,14 +157,6 @@ case "$1" in pluginhook update ;; - # temporary hack for https://github.com/progrium/dokku/issues/82 - deploy:all) - for app in $DOKKU_ROOT/*/CONTAINER; do - APP=$(basename "$(dirname $app)"); - dokku deploy $APP - done - ;; - help|'') echo "Usage: dokku COMMAND [command-specific-options]" echo "" diff --git a/plugins/00_dokku-standard/install b/plugins/00_dokku-standard/install index 91e93d2d8..02d743a18 100755 --- a/plugins/00_dokku-standard/install +++ b/plugins/00_dokku-standard/install @@ -20,7 +20,7 @@ start on (started docker) script sleep 2 # give docker some time - sudo -i -u dokku /usr/local/bin/dokku deploy:all + sudo -i -u dokku /usr/local/bin/dokku ps:restartall end script EOF ;; @@ -34,7 +34,7 @@ After=docker.target [Service] Type=simple User=dokku -ExecStart=/usr/local/bin/dokku deploy:all +ExecStart=/usr/local/bin/dokku ps:restartall [Install] WantedBy=multi-user.target diff --git a/plugins/ps/commands b/plugins/ps/commands index ca3ac5072..d0ae01076 100755 --- a/plugins/ps/commands +++ b/plugins/ps/commands @@ -66,12 +66,20 @@ case "$1" in 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< List processes running in app container(s) ps:start Start app container(s) ps:stop Stop app container(s) ps:restart Restart app container(s) + ps:restartall Restart all deployed app containers EOF ;; From 40e628778ba0756ca692e1d7f3f40e94486039ee Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Thu, 15 Jan 2015 10:47:21 -0800 Subject: [PATCH 7/7] revive deploy:all with deprecation warning --- docs/process-management.md | 2 ++ dokku | 6 ++++++ tests/unit/ps.bats | 5 ++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/docs/process-management.md b/docs/process-management.md index 0da24ae37..619ec8f60 100644 --- a/docs/process-management.md +++ b/docs/process-management.md @@ -9,3 +9,5 @@ ps:stop Stop app container(s) ps:restart 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. diff --git a/dokku b/dokku index 1afae5002..4ccca789a 100755 --- a/dokku +++ b/dokku @@ -157,6 +157,12 @@ case "$1" in pluginhook update ;; + # DEPRECATED as of v0.3.14 + deploy:all) + echo "*DEPRECATED* in v0.3.14: deploy:all will be removed in future versions" + dokku ps:restartall + ;; + help|'') echo "Usage: dokku COMMAND [command-specific-options]" echo "" diff --git a/tests/unit/ps.bats b/tests/unit/ps.bats index a6ba7ca75..53efb0b35 100644 --- a/tests/unit/ps.bats +++ b/tests/unit/ps.bats @@ -11,7 +11,10 @@ teardown() { } @test "ps" { - skip "circleci does not support docker exec at the moment" + # 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