diff --git a/common-functions b/common-functions index 513e741..a53bc4c 100755 --- a/common-functions +++ b/common-functions @@ -411,6 +411,14 @@ service_enter() { docker exec $DOKKU_RUN_OPTS $ID $EXEC_CMD "${@:-/bin/bash}" } +service_exists() { + declare desc="returns 0 or 1 depending on whether service exists or not" + declare SERVICE="$1" + [[ -z "$SERVICE" ]] && return 1 + [[ -d "$PLUGIN_DATA_ROOT/$SERVICE" ]] && return 0 + return 1 +} + service_exposed_ports() { declare desc="list exposed ports for a service" declare SERVICE="$1" diff --git a/subcommands/clone b/subcommands/clone index 3c5ff0b..a7e2f64 100755 --- a/subcommands/clone +++ b/subcommands/clone @@ -27,6 +27,9 @@ service-clone-cmd() { [[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a valid name for the service" [[ -z "$NEW_SERVICE" ]] && dokku_log_fail "Please specify a name for the new service" verify_service_name "$SERVICE" + if service_exists "$NEW_SERVICE"; then + dokku_log_fail "Invalid service name $NEW_SERVICE. Verify the service name is not already in use." + fi local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE" local ID="$(cat "$SERVICE_ROOT/ID")"