We run Dokku, and therefore dokku redis, in its own Docker container. In order to make this work we map a path from the host into the container as `/var/lib/dokku/services/redis`. Unfortunately the path on the host is user-configurable, and generally _won't_ be the same as the path in the container. This means that when we run `docker` commands (e.g. to spin up Redis containers), the directory used for bind mounts (the `-v` option) needs to be different. This commit allows us to do this, but keeps the existing behaviour (the redis root for Docker binds is the same as the redis root for other uses) by default.
61 lines
2.3 KiB
Bash
Executable File
61 lines
2.3 KiB
Bash
Executable File
#!/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-destroy-cmd() {
|
|
#E destroy the service, it's data, and the running container
|
|
#E dokku $PLUGIN_COMMAND_PREFIX:destroy lolipop
|
|
#A service, service to run command against
|
|
#F -f|--force, force destroy without asking for confirmation
|
|
declare desc="delete the $PLUGIN_SERVICE service/data/container if there are no links left"
|
|
local cmd="$PLUGIN_COMMAND_PREFIX:destroy" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
|
|
declare SERVICE="$1" FORCE_FLAG="$2"
|
|
|
|
[[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service"
|
|
verify_service_name "$SERVICE"
|
|
SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"; LINKS_FILE="$SERVICE_ROOT/LINKS"
|
|
SERVICE_HOST_ROOT="$PLUGIN_DATA_HOST_ROOT/$SERVICE"
|
|
SERVICE_NAME="$(get_service_name "$SERVICE")"
|
|
|
|
[[ -s "$LINKS_FILE" ]] && dokku_log_fail "Cannot delete linked service"
|
|
|
|
if [[ "$FORCE_FLAG" == "force" ]] || [[ "$FORCE_FLAG" == "-f" ]] || [[ "$FORCE_FLAG" == "--force" ]]; then
|
|
DOKKU_APPS_FORCE_DELETE=1
|
|
fi
|
|
if [[ -z "$DOKKU_APPS_FORCE_DELETE" ]]; then
|
|
dokku_log_warn "WARNING: Potentially Destructive Action"
|
|
dokku_log_warn "This command will destroy $SERVICE $PLUGIN_SERVICE service."
|
|
dokku_log_warn "To proceed, type \"$SERVICE\""
|
|
echo ""
|
|
|
|
read -rp "> " service_name
|
|
if [[ "$service_name" != "$SERVICE" ]]; then
|
|
dokku_log_warn "Confirmation did not match $SERVICE. Aborted."
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
dokku_log_info1 "Deleting $SERVICE"
|
|
if [[ -n $(docker ps -aq -f name="$SERVICE_NAME") ]]; then
|
|
dokku_log_verbose_quiet "Deleting container data"
|
|
service_stop "$SERVICE"
|
|
sleep 1
|
|
|
|
dokku_log_verbose_quiet "Removing container"
|
|
docker rm -v "$SERVICE_NAME" > /dev/null
|
|
sleep 1
|
|
else
|
|
dokku_log_verbose_quiet "No container exists for $SERVICE"
|
|
fi
|
|
|
|
dokku_log_verbose_quiet "Removing data"
|
|
docker run --rm -v "$SERVICE_HOST_ROOT/data:/data" -v "$SERVICE_HOST_ROOT/config:/config" "$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION" chmod 777 -R /config /data
|
|
rm -rf "$SERVICE_ROOT"
|
|
|
|
dokku_log_info2 "$PLUGIN_SERVICE container deleted: $SERVICE"
|
|
}
|
|
|
|
service-destroy-cmd "$@"
|