Conform to function declaration standards

- declare desc variable
- declare all positional arguments
- set the cmd
- properly handle DOKKU_APP_NAME
This commit is contained in:
Jose Diaz-Gonzalez
2016-05-16 00:04:39 -04:00
parent 85f0110356
commit 9216488fb3
17 changed files with 128 additions and 58 deletions

View File

@@ -5,11 +5,14 @@ source "$PLUGIN_BASE_PATH/common/functions"
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions"
postgres-clone-cmd() { postgres-clone-cmd() {
[[ -z $2 ]] && dokku_log_fail "Please specify a name for the service" declare desc="create container <new-name> then copy data from <name> into <new-name>"
[[ -z $3 ]] && dokku_log_fail "Please specify a name for the new service" local cmd="$PLUGIN_COMMAND_PREFIX:clone" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
verify_service_name "$2" declare SERVICE="$1" NEW_SERVICE="$2"
SERVICE="$2"
NEW_SERVICE="$3" [[ -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 "$PLUGIN_COMMAND_PREFIX:create" "$NEW_SERVICE"
dokku_log_info1 "Copying data from $SERVICE to $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 dokku "$PLUGIN_COMMAND_PREFIX:export" "$SERVICE" | dokku "$PLUGIN_COMMAND_PREFIX:import" "$NEW_SERVICE" > /dev/null 2>&1 || true

View File

@@ -5,9 +5,13 @@ source "$PLUGIN_BASE_PATH/common/functions"
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions"
postgres-connect-cmd() { postgres-connect-cmd() {
[[ -z $2 ]] && dokku_log_fail "Please specify a name for the service" declare desc="connect via psql to a $PLUGIN_SERVICE service"
verify_service_name "$2" local cmd="$PLUGIN_COMMAND_PREFIX:connect" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
SERVICE="$2"; SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE" 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")" DATABASE_NAME="$(get_database_name "$SERVICE")"
SERVICE_NAME="$(get_service_name "$SERVICE")" SERVICE_NAME="$(get_service_name "$SERVICE")"
has_tty && SERVICE_TTY_OPTS="-t" has_tty && SERVICE_TTY_OPTS="-t"

View File

@@ -5,9 +5,13 @@ source "$PLUGIN_BASE_PATH/common/functions"
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions"
postgres-create-cmd() { postgres-create-cmd() {
[[ -z $2 ]] && dokku_log_fail "Please specify a name for the service" declare desc="create a $PLUGIN_SERVICE service"
[[ ! -d "$PLUGIN_DATA_ROOT/$2" ]] || dokku_log_fail "$PLUGIN_SERVICE service $2 already exists" local cmd="$PLUGIN_COMMAND_PREFIX:create" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
SERVICE="$2"; SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"; LINKS_FILE="$SERVICE_ROOT/LINKS" 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 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" docker pull "$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION" || dokku_log_fail "$PLUGIN_SERVICE image $PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION pull failed"

View File

@@ -5,14 +5,18 @@ source "$PLUGIN_BASE_PATH/common/functions"
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions"
postgres-destroy-cmd() { postgres-destroy-cmd() {
[[ -z $2 ]] && dokku_log_fail "Please specify a name for the service" declare desc="delete the $PLUGIN_SERVICE service and stop its container if there are no links left"
verify_service_name "$2" local cmd="$PLUGIN_COMMAND_PREFIX:destroy" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
SERVICE="$2"; SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"; LINKS_FILE="$SERVICE_ROOT/LINKS" 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")" SERVICE_NAME="$(get_service_name "$SERVICE")"
[[ -s "$LINKS_FILE" ]] && dokku_log_fail "Cannot delete linked 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 if [[ -z "$DOKKU_APPS_FORCE_DELETE" ]]; then
dokku_log_warn "WARNING: Potentially Destructive Action" dokku_log_warn "WARNING: Potentially Destructive Action"
dokku_log_warn "This command will destroy $SERVICE $PLUGIN_SERVICE service." dokku_log_warn "This command will destroy $SERVICE $PLUGIN_SERVICE service."
@@ -28,6 +32,7 @@ postgres-destroy-cmd() {
dokku_log_info1 "Deleting $SERVICE" dokku_log_info1 "Deleting $SERVICE"
if [[ -n $(docker ps -aq -f name="$SERVICE_NAME") ]]; then if [[ -n $(docker ps -aq -f name="$SERVICE_NAME") ]]; then
dokku_log_verbose_quiet "Deleting container data"
service_stop "$SERVICE" service_stop "$SERVICE"
sleep 1 sleep 1

View File

@@ -5,9 +5,13 @@ source "$PLUGIN_BASE_PATH/common/functions"
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions"
postgres-export-cmd() { postgres-export-cmd() {
[[ -z $2 ]] && dokku_log_fail "Please specify a name for the service" declare desc="export a dump of the $PLUGIN_SERVICE service database"
verify_service_name "$2" local cmd="$PLUGIN_COMMAND_PREFIX:export" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
SERVICE="$2"; SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE" 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")" SERVICE_NAME="$(get_service_name "$SERVICE")"
DATABASE_NAME="$(get_database_name "$SERVICE")" DATABASE_NAME="$(get_database_name "$SERVICE")"
PASSWORD=$(cat "$SERVICE_ROOT/PASSWORD") PASSWORD=$(cat "$SERVICE_ROOT/PASSWORD")

View File

@@ -5,9 +5,13 @@ source "$PLUGIN_BASE_PATH/common/functions"
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions"
postgres-expose-cmd() { postgres-expose-cmd() {
[[ -z $2 ]] && dokku_log_fail "Please specify a name for the service" declare desc="expose a $PLUGIN_SERVICE service on custom port if provided (random port otherwise)"
verify_service_name "$2" local cmd="$PLUGIN_COMMAND_PREFIX:expose" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
service_port_expose "$2" "${@:3}" 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 "$@" postgres-expose-cmd "$@"

View File

@@ -5,9 +5,13 @@ source "$PLUGIN_BASE_PATH/common/functions"
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions"
postgres-import-cmd() { postgres-import-cmd() {
[[ -z $2 ]] && dokku_log_fail "Please specify a name for the service" declare desc="import a dump into the $PLUGIN_SERVICE service database"
verify_service_name "$2" local cmd="$PLUGIN_COMMAND_PREFIX:import" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
SERVICE="$2"; SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE" 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")" SERVICE_NAME="$(get_service_name "$SERVICE")"
DATABASE_NAME="$(get_database_name "$SERVICE")" DATABASE_NAME="$(get_database_name "$SERVICE")"
PASSWORD=$(cat "$SERVICE_ROOT/PASSWORD") PASSWORD=$(cat "$SERVICE_ROOT/PASSWORD")

View File

@@ -5,9 +5,13 @@ source "$PLUGIN_BASE_PATH/common/functions"
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions"
postgres-info-cmd() { postgres-info-cmd() {
[[ -z $2 ]] && dokku_log_fail "Please specify a name for the service" declare desc="print the connection information"
verify_service_name "$2" local cmd="$PLUGIN_COMMAND_PREFIX:info" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
service_info "$2" 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 "$@" postgres-info-cmd "$@"

View File

@@ -5,11 +5,16 @@ source "$PLUGIN_BASE_PATH/common/functions"
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions"
postgres-link-cmd() { postgres-link-cmd() {
[[ -z $2 ]] && dokku_log_fail "Please specify a name for the service" declare desc="link the $PLUGIN_SERVICE service to the app"
[[ -z $3 ]] && dokku_log_fail "Please specify an app to run the command on" local cmd="$PLUGIN_COMMAND_PREFIX:link" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
verify_app_name "$3" declare SERVICE="$1" APP="$2"
verify_service_name "$2" APP=${APP:="$DOKKU_APP_NAME"}
service_link "$2" "$3"
[[ -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 "$@" postgres-link-cmd "$@"

View File

@@ -5,6 +5,9 @@ source "$PLUGIN_BASE_PATH/common/functions"
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions"
postgres-list-cmd() { postgres-list-cmd() {
declare desc="list all $PLUGIN_SERVICE services"
local cmd="$PLUGIN_COMMAND_PREFIX:list" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
service_list service_list
} }

View File

@@ -5,9 +5,13 @@ source "$PLUGIN_BASE_PATH/common/functions"
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions"
postgres-logs-cmd() { postgres-logs-cmd() {
[[ -z $2 ]] && dokku_log_fail "Please specify a name for the service" declare desc="print the most recent log(s) for this service"
verify_service_name "$2" local cmd="$PLUGIN_COMMAND_PREFIX:logs" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
service_logs "$2" "$3" 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 "$@" postgres-logs-cmd "$@"

View File

@@ -5,11 +5,16 @@ source "$PLUGIN_BASE_PATH/common/functions"
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions"
postgres-promote-cmd() { postgres-promote-cmd() {
[[ -z $2 ]] && dokku_log_fail "Please specify a name for the service" declare desc="promote service <name> as ${PLUGIN_DEFAULT_ALIAS}_URL in <app>"
[[ -z $3 ]] && dokku_log_fail "Please specify an app to run the command on" local cmd="$PLUGIN_COMMAND_PREFIX:promote" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
verify_service_name "$2" declare SERVICE="$1" APP="$2"
verify_app_name "$3" APP=${APP:="$DOKKU_APP_NAME"}
promote "$2" "$3"
[[ -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 "$@" postgres-promote-cmd "$@"

View File

@@ -5,10 +5,14 @@ source "$PLUGIN_BASE_PATH/common/functions"
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions"
postgres-restart-cmd() { postgres-restart-cmd() {
[[ -z $2 ]] && dokku_log_fail "Please specify a name for the service" declare desc="graceful shutdown and restart of the $PLUGIN_SERVICE service container"
verify_service_name "$2" local cmd="$PLUGIN_COMMAND_PREFIX:restart" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
service_stop "$2" declare SERVICE="$1"
service_start "$2"
[[ -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" dokku_log_info1 "Please call dokku ps:restart on all linked apps"
} }

View File

@@ -5,9 +5,13 @@ source "$PLUGIN_BASE_PATH/common/functions"
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions"
postgres-start-cmd() { postgres-start-cmd() {
[[ -z $2 ]] && dokku_log_fail "Please specify a name for the service" declare desc="start a previously stopped $PLUGIN_SERVICE service"
verify_service_name "$2" local cmd="$PLUGIN_COMMAND_PREFIX:start" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
service_start "$2" 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 "$@" postgres-start-cmd "$@"

View File

@@ -5,9 +5,13 @@ source "$PLUGIN_BASE_PATH/common/functions"
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions"
postgres-stop-cmd() { postgres-stop-cmd() {
[[ -z $2 ]] && dokku_log_fail "Please specify a name for the service" declare desc="stop a running $PLUGIN_SERVICE service"
verify_service_name "$2" local cmd="$PLUGIN_COMMAND_PREFIX:stop" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
service_stop "$2" 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 "$@" postgres-stop-cmd "$@"

View File

@@ -5,9 +5,13 @@ source "$PLUGIN_BASE_PATH/common/functions"
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions"
postgres-unexpose-cmd() { postgres-unexpose-cmd() {
[[ -z $2 ]] && dokku_log_fail "Please specify a name for the service" declare desc="unexpose a previously exposed $PLUGIN_SERVICE service"
verify_service_name "$2" local cmd="$PLUGIN_COMMAND_PREFIX:unexpose" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
service_port_unexpose "$2" 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 "$@" postgres-unexpose-cmd "$@"

View File

@@ -5,11 +5,16 @@ source "$PLUGIN_BASE_PATH/common/functions"
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions"
postgres-unlink-cmd() { postgres-unlink-cmd() {
[[ -z $2 ]] && dokku_log_fail "Please specify a name for the service" declare desc="unlink the $PLUGIN_SERVICE service from the app"
[[ -z $3 ]] && dokku_log_fail "Please specify an app to run the command on" local cmd="$PLUGIN_COMMAND_PREFIX:unlink" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
verify_app_name "$3" declare SERVICE="$1" APP="$2"
verify_service_name "$2" APP=${APP:="$DOKKU_APP_NAME"}
service_unlink "$2" "$3"
[[ -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 "$@" postgres-unlink-cmd "$@"