diff --git a/subcommands/clone b/subcommands/clone index aa9546f..45e945e 100755 --- a/subcommands/clone +++ b/subcommands/clone @@ -5,11 +5,14 @@ source "$PLUGIN_BASE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" postgres-clone-cmd() { - [[ -z $2 ]] && dokku_log_fail "Please specify a name for the service" - [[ -z $3 ]] && dokku_log_fail "Please specify a name for the new service" - verify_service_name "$2" - SERVICE="$2" - NEW_SERVICE="$3" + declare desc="create container then copy data from into " + local cmd="$PLUGIN_COMMAND_PREFIX:clone" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1 + declare SERVICE="$1" NEW_SERVICE="$2" + + [[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service" + [[ -z "$NEW_SERVICE" ]] && dokku_log_fail "Please specify a name for the new service" + + verify_service_name "$SERVICE" dokku "$PLUGIN_COMMAND_PREFIX:create" "$NEW_SERVICE" dokku_log_info1 "Copying data from $SERVICE to $NEW_SERVICE" dokku "$PLUGIN_COMMAND_PREFIX:export" "$SERVICE" | dokku "$PLUGIN_COMMAND_PREFIX:import" "$NEW_SERVICE" > /dev/null 2>&1 || true diff --git a/subcommands/connect b/subcommands/connect index bf2c081..63a9856 100755 --- a/subcommands/connect +++ b/subcommands/connect @@ -5,9 +5,13 @@ source "$PLUGIN_BASE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" postgres-connect-cmd() { - [[ -z $2 ]] && dokku_log_fail "Please specify a name for the service" - verify_service_name "$2" - SERVICE="$2"; SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE" + declare desc="connect via psql to a $PLUGIN_SERVICE service" + local cmd="$PLUGIN_COMMAND_PREFIX:connect" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1 + declare SERVICE="$1" + + [[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service" + verify_service_name "$SERVICE" + SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE" DATABASE_NAME="$(get_database_name "$SERVICE")" SERVICE_NAME="$(get_service_name "$SERVICE")" has_tty && SERVICE_TTY_OPTS="-t" diff --git a/subcommands/create b/subcommands/create index eba15e6..cebeef4 100755 --- a/subcommands/create +++ b/subcommands/create @@ -5,9 +5,13 @@ source "$PLUGIN_BASE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" postgres-create-cmd() { - [[ -z $2 ]] && dokku_log_fail "Please specify a name for the service" - [[ ! -d "$PLUGIN_DATA_ROOT/$2" ]] || dokku_log_fail "$PLUGIN_SERVICE service $2 already exists" - SERVICE="$2"; SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"; LINKS_FILE="$SERVICE_ROOT/LINKS" + declare desc="create a $PLUGIN_SERVICE service" + local cmd="$PLUGIN_COMMAND_PREFIX:create" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1 + declare SERVICE="$1" + + [[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service" + [[ ! -d "$PLUGIN_DATA_ROOT/$SERVICE" ]] || dokku_log_fail "$PLUGIN_SERVICE service $2 already exists" + SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"; LINKS_FILE="$SERVICE_ROOT/LINKS" if ! docker images | grep -e "^$PLUGIN_IMAGE " | grep -q " $PLUGIN_IMAGE_VERSION " ; then docker pull "$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION" || dokku_log_fail "$PLUGIN_SERVICE image $PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION pull failed" diff --git a/subcommands/destroy b/subcommands/destroy index 21eb71f..0d40dfc 100755 --- a/subcommands/destroy +++ b/subcommands/destroy @@ -5,14 +5,18 @@ source "$PLUGIN_BASE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" postgres-destroy-cmd() { - [[ -z $2 ]] && dokku_log_fail "Please specify a name for the service" - verify_service_name "$2" - SERVICE="$2"; SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"; LINKS_FILE="$SERVICE_ROOT/LINKS" + declare desc="delete the $PLUGIN_SERVICE service and stop its container if there are no links left" + local cmd="$PLUGIN_COMMAND_PREFIX:destroy" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1 + declare SERVICE="$1" FORCE_DESTROY="$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_NAME="$(get_service_name "$SERVICE")" [[ -s "$LINKS_FILE" ]] && dokku_log_fail "Cannot delete linked service" - [[ "$3" == "force" ]] && DOKKU_APPS_FORCE_DELETE=1 + [[ "$FORCE_DESTROY" == "force" ]] && DOKKU_APPS_FORCE_DELETE=1 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." @@ -28,6 +32,7 @@ postgres-destroy-cmd() { 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 diff --git a/subcommands/export b/subcommands/export index 81e83b3..3a2ea06 100755 --- a/subcommands/export +++ b/subcommands/export @@ -5,9 +5,13 @@ source "$PLUGIN_BASE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" postgres-export-cmd() { - [[ -z $2 ]] && dokku_log_fail "Please specify a name for the service" - verify_service_name "$2" - SERVICE="$2"; SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE" + declare desc="export a dump of the $PLUGIN_SERVICE service database" + local cmd="$PLUGIN_COMMAND_PREFIX:export" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1 + declare SERVICE="$1" + + [[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service" + verify_service_name "$SERVICE" + SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE" SERVICE_NAME="$(get_service_name "$SERVICE")" DATABASE_NAME="$(get_database_name "$SERVICE")" PASSWORD=$(cat "$SERVICE_ROOT/PASSWORD") diff --git a/subcommands/expose b/subcommands/expose index 5e5b5b3..fe2566d 100755 --- a/subcommands/expose +++ b/subcommands/expose @@ -5,9 +5,13 @@ source "$PLUGIN_BASE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" postgres-expose-cmd() { - [[ -z $2 ]] && dokku_log_fail "Please specify a name for the service" - verify_service_name "$2" - service_port_expose "$2" "${@:3}" + declare desc="expose a $PLUGIN_SERVICE service on custom port if provided (random port otherwise)" + local cmd="$PLUGIN_COMMAND_PREFIX:expose" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1 + declare SERVICE="$1" + + [[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service" + verify_service_name "$SERVICE" + service_port_expose "$SERVICE" "${@:2}" } postgres-expose-cmd "$@" diff --git a/subcommands/import b/subcommands/import index 6143adc..1e08f76 100755 --- a/subcommands/import +++ b/subcommands/import @@ -5,9 +5,13 @@ source "$PLUGIN_BASE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" postgres-import-cmd() { - [[ -z $2 ]] && dokku_log_fail "Please specify a name for the service" - verify_service_name "$2" - SERVICE="$2"; SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE" + declare desc="import a dump into the $PLUGIN_SERVICE service database" + local cmd="$PLUGIN_COMMAND_PREFIX:import" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1 + declare SERVICE="$1" + + [[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service" + verify_service_name "$SERVICE" + SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE" SERVICE_NAME="$(get_service_name "$SERVICE")" DATABASE_NAME="$(get_database_name "$SERVICE")" PASSWORD=$(cat "$SERVICE_ROOT/PASSWORD") diff --git a/subcommands/info b/subcommands/info index 87cdffa..42ee99b 100755 --- a/subcommands/info +++ b/subcommands/info @@ -5,9 +5,13 @@ source "$PLUGIN_BASE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" postgres-info-cmd() { - [[ -z $2 ]] && dokku_log_fail "Please specify a name for the service" - verify_service_name "$2" - service_info "$2" + declare desc="print the connection information" + local cmd="$PLUGIN_COMMAND_PREFIX:info" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1 + declare SERVICE="$1" + + [[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service" + verify_service_name "$SERVICE" + service_info "$SERVICE" } postgres-info-cmd "$@" diff --git a/subcommands/link b/subcommands/link index 17e0baf..f1b6cd9 100755 --- a/subcommands/link +++ b/subcommands/link @@ -5,11 +5,16 @@ source "$PLUGIN_BASE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" postgres-link-cmd() { - [[ -z $2 ]] && dokku_log_fail "Please specify a name for the service" - [[ -z $3 ]] && dokku_log_fail "Please specify an app to run the command on" - verify_app_name "$3" - verify_service_name "$2" - service_link "$2" "$3" + declare desc="link the $PLUGIN_SERVICE service to the app" + local cmd="$PLUGIN_COMMAND_PREFIX:link" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1 + declare SERVICE="$1" APP="$2" + APP=${APP:="$DOKKU_APP_NAME"} + + [[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service" + [[ -z "$APP" ]] && dokku_log_fail "Please specify an app to run the command on" + verify_app_name "$APP" + verify_service_name "$SERVICE" + service_link "$SERVICE" "$APP" } postgres-link-cmd "$@" diff --git a/subcommands/list b/subcommands/list index f1f0158..8f77993 100755 --- a/subcommands/list +++ b/subcommands/list @@ -5,6 +5,9 @@ source "$PLUGIN_BASE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" postgres-list-cmd() { + declare desc="list all $PLUGIN_SERVICE services" + local cmd="$PLUGIN_COMMAND_PREFIX:list" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1 + service_list } diff --git a/subcommands/logs b/subcommands/logs index d45e663..7c746a3 100755 --- a/subcommands/logs +++ b/subcommands/logs @@ -5,9 +5,13 @@ source "$PLUGIN_BASE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" postgres-logs-cmd() { - [[ -z $2 ]] && dokku_log_fail "Please specify a name for the service" - verify_service_name "$2" - service_logs "$2" "$3" + declare desc="print the most recent log(s) for this service" + local cmd="$PLUGIN_COMMAND_PREFIX:logs" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1 + declare SERVICE="$1" TAIL="$2" + + [[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service" + verify_service_name "$SERVICE" + service_logs "$SERVICE" "$TAIL" } postgres-logs-cmd "$@" diff --git a/subcommands/promote b/subcommands/promote index 9686f03..cdb791f 100755 --- a/subcommands/promote +++ b/subcommands/promote @@ -5,11 +5,16 @@ source "$PLUGIN_BASE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" postgres-promote-cmd() { - [[ -z $2 ]] && dokku_log_fail "Please specify a name for the service" - [[ -z $3 ]] && dokku_log_fail "Please specify an app to run the command on" - verify_service_name "$2" - verify_app_name "$3" - promote "$2" "$3" + declare desc="promote service as ${PLUGIN_DEFAULT_ALIAS}_URL in " + local cmd="$PLUGIN_COMMAND_PREFIX:promote" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1 + declare SERVICE="$1" APP="$2" + APP=${APP:="$DOKKU_APP_NAME"} + + [[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service" + [[ -z "$APP" ]] && dokku_log_fail "Please specify an app to run the command on" + verify_service_name "$SERVICE" + verify_app_name "$APP" + promote "$SERVICE" "$APP" } postgres-promote-cmd "$@" diff --git a/subcommands/restart b/subcommands/restart index e6d5d32..7b9c711 100755 --- a/subcommands/restart +++ b/subcommands/restart @@ -5,10 +5,14 @@ source "$PLUGIN_BASE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" postgres-restart-cmd() { - [[ -z $2 ]] && dokku_log_fail "Please specify a name for the service" - verify_service_name "$2" - service_stop "$2" - service_start "$2" + declare desc="graceful shutdown and restart of the $PLUGIN_SERVICE service container" + local cmd="$PLUGIN_COMMAND_PREFIX:restart" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1 + declare SERVICE="$1" + + [[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service" + verify_service_name "$SERVICE" + service_stop "$SERVICE" + service_start "$SERVICE" dokku_log_info1 "Please call dokku ps:restart on all linked apps" } diff --git a/subcommands/start b/subcommands/start index fd62941..230725d 100755 --- a/subcommands/start +++ b/subcommands/start @@ -5,9 +5,13 @@ source "$PLUGIN_BASE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" postgres-start-cmd() { - [[ -z $2 ]] && dokku_log_fail "Please specify a name for the service" - verify_service_name "$2" - service_start "$2" + declare desc="start a previously stopped $PLUGIN_SERVICE service" + local cmd="$PLUGIN_COMMAND_PREFIX:start" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1 + declare SERVICE="$1" + + [[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service" + verify_service_name "$SERVICE" + service_start "$SERVICE" } postgres-start-cmd "$@" diff --git a/subcommands/stop b/subcommands/stop index ef7d5ef..e6e6e98 100755 --- a/subcommands/stop +++ b/subcommands/stop @@ -5,9 +5,13 @@ source "$PLUGIN_BASE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" postgres-stop-cmd() { - [[ -z $2 ]] && dokku_log_fail "Please specify a name for the service" - verify_service_name "$2" - service_stop "$2" + declare desc="stop a running $PLUGIN_SERVICE service" + local cmd="$PLUGIN_COMMAND_PREFIX:stop" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1 + declare SERVICE="$1" + + [[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service" + verify_service_name "$SERVICE" + service_stop "$SERVICE" } postgres-stop-cmd "$@" diff --git a/subcommands/unexpose b/subcommands/unexpose index 965c249..da058b5 100755 --- a/subcommands/unexpose +++ b/subcommands/unexpose @@ -5,9 +5,13 @@ source "$PLUGIN_BASE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" postgres-unexpose-cmd() { - [[ -z $2 ]] && dokku_log_fail "Please specify a name for the service" - verify_service_name "$2" - service_port_unexpose "$2" + declare desc="unexpose a previously exposed $PLUGIN_SERVICE service" + local cmd="$PLUGIN_COMMAND_PREFIX:unexpose" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1 + declare SERVICE="$1" + + [[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service" + verify_service_name "$SERVICE" + service_port_unexpose "$SERVICE" } postgres-unexpose-cmd "$@" diff --git a/subcommands/unlink b/subcommands/unlink index bd6ca28..5fe75a7 100755 --- a/subcommands/unlink +++ b/subcommands/unlink @@ -5,11 +5,16 @@ source "$PLUGIN_BASE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" postgres-unlink-cmd() { - [[ -z $2 ]] && dokku_log_fail "Please specify a name for the service" - [[ -z $3 ]] && dokku_log_fail "Please specify an app to run the command on" - verify_app_name "$3" - verify_service_name "$2" - service_unlink "$2" "$3" + declare desc="unlink the $PLUGIN_SERVICE service from the app" + local cmd="$PLUGIN_COMMAND_PREFIX:unlink" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1 + declare SERVICE="$1" APP="$2" + APP=${APP:="$DOKKU_APP_NAME"} + + [[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service" + [[ -z "$APP" ]] && dokku_log_fail "Please specify an app to run the command on" + verify_app_name "$APP" + verify_service_name "$SERVICE" + service_unlink "$SERVICE" "$APP" } postgres-unlink-cmd "$@"