feat: add :pause subcommand and make :stop subcommand actually remove the container
This commit is contained in:
16
README.md
16
README.md
@@ -41,6 +41,7 @@ mysql:linked <service> <app> # check if the mysql service
|
||||
mysql:links <service> # list all apps linked to the mysql service
|
||||
mysql:list # list all mysql services
|
||||
mysql:logs <service> [-t|--tail] <tail-num-optional> # print the most recent log(s) for this service
|
||||
mysql:pause <service> # pause a running mysql service
|
||||
mysql:promote <service> <app> # promote service <service> as DATABASE_URL in <app>
|
||||
mysql:restart <service> # graceful shutdown and restart of the mysql service container
|
||||
mysql:start <service> # start a previously stopped mysql service
|
||||
@@ -370,12 +371,25 @@ dokku mysql:start lollipop
|
||||
dokku mysql:stop <service>
|
||||
```
|
||||
|
||||
Stop the service and the running container:
|
||||
Stop the service and removes the running container:
|
||||
|
||||
```shell
|
||||
dokku mysql:stop lollipop
|
||||
```
|
||||
|
||||
### pause a running mysql service
|
||||
|
||||
```shell
|
||||
# usage
|
||||
dokku mysql:pause <service>
|
||||
```
|
||||
|
||||
Pause the running container for the service:
|
||||
|
||||
```shell
|
||||
dokku mysql:pause lollipop
|
||||
```
|
||||
|
||||
### graceful shutdown and restart of the mysql service container
|
||||
|
||||
```shell
|
||||
|
||||
@@ -148,6 +148,7 @@ def usage_lifecycle(service, variable, alias, image, scheme, ports, options, uni
|
||||
"promote",
|
||||
"start",
|
||||
"stop",
|
||||
"pause",
|
||||
"restart",
|
||||
"upgrade",
|
||||
]
|
||||
|
||||
@@ -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
|
||||
|
||||
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"
|
||||
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"
|
||||
}
|
||||
|
||||
@@ -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 "$@"
|
||||
|
||||
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