diff --git a/README.md b/README.md index 236dd9b..5e1173d 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ mongo:linked # check if the mongo service mongo:links # list all apps linked to the mongo service mongo:list # list all mongo services mongo:logs [-t|--tail] # print the most recent log(s) for this service +mongo:pause # pause a running mongo service mongo:promote # promote service as MONGO_URL in mongo:restart # graceful shutdown and restart of the mongo service container mongo:start # start a previously stopped mongo service @@ -371,12 +372,25 @@ dokku mongo:start lollipop dokku mongo:stop ``` -Stop the service and the running container: +Stop the service and removes the running container: ```shell dokku mongo:stop lollipop ``` +### pause a running mongo service + +```shell +# usage +dokku mongo:pause +``` + +Pause the running container for the service: + +```shell +dokku mongo:pause lollipop +``` + ### graceful shutdown and restart of the mongo service container ```shell diff --git a/bin/generate b/bin/generate index 2e19392..dad42b4 100755 --- a/bin/generate +++ b/bin/generate @@ -148,6 +148,7 @@ def usage_lifecycle(service, variable, alias, image, scheme, ports, options, uni "promote", "start", "stop", + "pause", "restart", "upgrade", ] diff --git a/common-functions b/common-functions index d2630be..63f8bf5 100755 --- a/common-functions +++ b/common-functions @@ -443,7 +443,7 @@ service_container_rm() { local SERVICE_NAME="$(get_service_name "$SERVICE")" local ID - service_stop "$SERVICE" + service_pause "$SERVICE" ID=$(docker ps -aq --no-trunc --filter "name=^/$SERVICE_NAME$" --format '{{ .ID }}') || true # this may be 'true' in tests... if [[ -z "$ID" ]] || [[ "$ID" == "true" ]]; then @@ -896,19 +896,19 @@ service_status() { echo "missing" && return 0 } -service_stop() { - declare desc="stop a running service" +service_pause() { + declare desc="pause a running service" declare SERVICE="$1" local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE" local SERVICE_NAME="$(get_service_name "$SERVICE")" local ID=$(docker ps -aq --no-trunc --filter "name=^/$SERVICE_NAME$" --format '{{ .ID }}') || true - [[ -z $ID ]] && dokku_log_warn "Service is already stopped" && return 0 + [[ -z $ID ]] && dokku_log_warn "Service is already paused" && return 0 if [[ -n $ID ]]; then - dokku_log_info2_quiet "Stopping container" + dokku_log_info2_quiet "Pausing container" docker stop "$SERVICE_NAME" >/dev/null service_port_pause "$SERVICE" - dokku_log_verbose_quiet "Container stopped" + dokku_log_verbose_quiet "Container paused" else dokku_log_verbose_quiet "No container exists for $SERVICE" fi diff --git a/subcommands/pause b/subcommands/pause new file mode 100755 index 0000000..acf43be --- /dev/null +++ b/subcommands/pause @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config" +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x +source "$PLUGIN_BASE_PATH/common/functions" +source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" + +service-pause-cmd() { + #E pause the running container for the service + #E dokku $PLUGIN_COMMAND_PREFIX:pause lollipop + #A service, service to run command against + declare desc="pause a running $PLUGIN_SERVICE service" + local cmd="$PLUGIN_COMMAND_PREFIX:pause" argv=("$@") + [[ ${argv[0]} == "$cmd" ]] && shift 1 + declare SERVICE="$1" + + [[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a valid name for the service" + verify_service_name "$SERVICE" + service_pause "$SERVICE" +} + +service-pause-cmd "$@" diff --git a/subcommands/restart b/subcommands/restart index df9a051..c7d11a0 100755 --- a/subcommands/restart +++ b/subcommands/restart @@ -16,7 +16,7 @@ service-restart-cmd() { [[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a valid name for the service" verify_service_name "$SERVICE" - service_stop "$SERVICE" + service_pause "$SERVICE" service_start "$SERVICE" dokku_log_info1 "Please call dokku ps:restart on all linked apps" } diff --git a/subcommands/stop b/subcommands/stop index 0ac3a17..b20c32d 100755 --- a/subcommands/stop +++ b/subcommands/stop @@ -6,7 +6,7 @@ source "$PLUGIN_BASE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" service-stop-cmd() { - #E stop the service and the running container + #E stop the service and removes the running container #E dokku $PLUGIN_COMMAND_PREFIX:stop lollipop #A service, service to run command against declare desc="stop a running $PLUGIN_SERVICE service" @@ -16,7 +16,7 @@ service-stop-cmd() { [[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a valid name for the service" verify_service_name "$SERVICE" - service_stop "$SERVICE" + service_container_rm "$SERVICE" } service-stop-cmd "$@" diff --git a/tests/service_pause.bats b/tests/service_pause.bats new file mode 100755 index 0000000..a2a2a69 --- /dev/null +++ b/tests/service_pause.bats @@ -0,0 +1,25 @@ +#!/usr/bin/env bats +load test_helper + +setup() { + dokku "$PLUGIN_COMMAND_PREFIX:create" l +} + +teardown() { + dokku --force "$PLUGIN_COMMAND_PREFIX:destroy" l +} + +@test "($PLUGIN_COMMAND_PREFIX:pause) error when there are no arguments" { + run dokku "$PLUGIN_COMMAND_PREFIX:pause" + assert_contains "${lines[*]}" "Please specify a valid name for the service" +} + +@test "($PLUGIN_COMMAND_PREFIX:pause) error when service does not exist" { + run dokku "$PLUGIN_COMMAND_PREFIX:pause" not_existing_service + assert_contains "${lines[*]}" "service not_existing_service does not exist" +} + +@test "($PLUGIN_COMMAND_PREFIX:pause) success" { + run dokku "$PLUGIN_COMMAND_PREFIX:pause" l + assert_success +}