feat: add :pause subcommand and make :stop subcommand actually remove the container
This commit is contained in:
16
README.md
16
README.md
@@ -42,6 +42,7 @@ mongo:linked <service> <app> # check if the mongo service
|
|||||||
mongo:links <service> # list all apps linked to the mongo service
|
mongo:links <service> # list all apps linked to the mongo service
|
||||||
mongo:list # list all mongo services
|
mongo:list # list all mongo services
|
||||||
mongo:logs <service> [-t|--tail] <tail-num-optional> # print the most recent log(s) for this service
|
mongo:logs <service> [-t|--tail] <tail-num-optional> # print the most recent log(s) for this service
|
||||||
|
mongo:pause <service> # pause a running mongo service
|
||||||
mongo:promote <service> <app> # promote service <service> as MONGO_URL in <app>
|
mongo:promote <service> <app> # promote service <service> as MONGO_URL in <app>
|
||||||
mongo:restart <service> # graceful shutdown and restart of the mongo service container
|
mongo:restart <service> # graceful shutdown and restart of the mongo service container
|
||||||
mongo:start <service> # start a previously stopped mongo service
|
mongo:start <service> # start a previously stopped mongo service
|
||||||
@@ -371,12 +372,25 @@ dokku mongo:start lollipop
|
|||||||
dokku mongo:stop <service>
|
dokku mongo:stop <service>
|
||||||
```
|
```
|
||||||
|
|
||||||
Stop the service and the running container:
|
Stop the service and removes the running container:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
dokku mongo:stop lollipop
|
dokku mongo:stop lollipop
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### pause a running mongo service
|
||||||
|
|
||||||
|
```shell
|
||||||
|
# usage
|
||||||
|
dokku mongo:pause <service>
|
||||||
|
```
|
||||||
|
|
||||||
|
Pause the running container for the service:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
dokku mongo:pause lollipop
|
||||||
|
```
|
||||||
|
|
||||||
### graceful shutdown and restart of the mongo service container
|
### graceful shutdown and restart of the mongo service container
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
|
|||||||
@@ -148,6 +148,7 @@ def usage_lifecycle(service, variable, alias, image, scheme, ports, options, uni
|
|||||||
"promote",
|
"promote",
|
||||||
"start",
|
"start",
|
||||||
"stop",
|
"stop",
|
||||||
|
"pause",
|
||||||
"restart",
|
"restart",
|
||||||
"upgrade",
|
"upgrade",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -443,7 +443,7 @@ service_container_rm() {
|
|||||||
local SERVICE_NAME="$(get_service_name "$SERVICE")"
|
local SERVICE_NAME="$(get_service_name "$SERVICE")"
|
||||||
local ID
|
local ID
|
||||||
|
|
||||||
service_stop "$SERVICE"
|
service_pause "$SERVICE"
|
||||||
ID=$(docker ps -aq --no-trunc --filter "name=^/$SERVICE_NAME$" --format '{{ .ID }}') || true
|
ID=$(docker ps -aq --no-trunc --filter "name=^/$SERVICE_NAME$" --format '{{ .ID }}') || true
|
||||||
# this may be 'true' in tests...
|
# this may be 'true' in tests...
|
||||||
if [[ -z "$ID" ]] || [[ "$ID" == "true" ]]; then
|
if [[ -z "$ID" ]] || [[ "$ID" == "true" ]]; then
|
||||||
@@ -896,19 +896,19 @@ service_status() {
|
|||||||
echo "missing" && return 0
|
echo "missing" && return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
service_stop() {
|
service_pause() {
|
||||||
declare desc="stop a running service"
|
declare desc="pause a running service"
|
||||||
declare SERVICE="$1"
|
declare SERVICE="$1"
|
||||||
local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"
|
local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"
|
||||||
local SERVICE_NAME="$(get_service_name "$SERVICE")"
|
local SERVICE_NAME="$(get_service_name "$SERVICE")"
|
||||||
local ID=$(docker ps -aq --no-trunc --filter "name=^/$SERVICE_NAME$" --format '{{ .ID }}') || true
|
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
|
if [[ -n $ID ]]; then
|
||||||
dokku_log_info2_quiet "Stopping container"
|
dokku_log_info2_quiet "Pausing container"
|
||||||
docker stop "$SERVICE_NAME" >/dev/null
|
docker stop "$SERVICE_NAME" >/dev/null
|
||||||
service_port_pause "$SERVICE"
|
service_port_pause "$SERVICE"
|
||||||
dokku_log_verbose_quiet "Container stopped"
|
dokku_log_verbose_quiet "Container paused"
|
||||||
else
|
else
|
||||||
dokku_log_verbose_quiet "No container exists for $SERVICE"
|
dokku_log_verbose_quiet "No container exists for $SERVICE"
|
||||||
fi
|
fi
|
||||||
|
|||||||
22
subcommands/pause
Executable file
22
subcommands/pause
Executable file
@@ -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 "$@"
|
||||||
@@ -16,7 +16,7 @@ service-restart-cmd() {
|
|||||||
|
|
||||||
[[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a valid name for the service"
|
[[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a valid name for the service"
|
||||||
verify_service_name "$SERVICE"
|
verify_service_name "$SERVICE"
|
||||||
service_stop "$SERVICE"
|
service_pause "$SERVICE"
|
||||||
service_start "$SERVICE"
|
service_start "$SERVICE"
|
||||||
dokku_log_info1 "Please call dokku ps:restart on all linked apps"
|
dokku_log_info1 "Please call dokku ps:restart on all linked apps"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ source "$PLUGIN_BASE_PATH/common/functions"
|
|||||||
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions"
|
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions"
|
||||||
|
|
||||||
service-stop-cmd() {
|
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
|
#E dokku $PLUGIN_COMMAND_PREFIX:stop lollipop
|
||||||
#A service, service to run command against
|
#A service, service to run command against
|
||||||
declare desc="stop a running $PLUGIN_SERVICE service"
|
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"
|
[[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a valid name for the service"
|
||||||
verify_service_name "$SERVICE"
|
verify_service_name "$SERVICE"
|
||||||
service_stop "$SERVICE"
|
service_container_rm "$SERVICE"
|
||||||
}
|
}
|
||||||
|
|
||||||
service-stop-cmd "$@"
|
service-stop-cmd "$@"
|
||||||
|
|||||||
25
tests/service_pause.bats
Executable file
25
tests/service_pause.bats
Executable file
@@ -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
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user