From 0d64d42218de712bf66720779ca129dc8bb4c993 Mon Sep 17 00:00:00 2001 From: Vitaly Domnikov Date: Mon, 11 Jul 2016 16:17:00 -0700 Subject: [PATCH 1/3] add mongo:admin command --- README.md | 3 ++- commands | 5 +++++ subcommands/admin | 22 ++++++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 subcommands/admin diff --git a/README.md b/README.md index dfc4ed8..399a0d4 100644 --- a/README.md +++ b/README.md @@ -17,13 +17,14 @@ dokku plugin:install https://github.com/dokku/dokku-mongo.git mongo ## commands ``` +mongo:admin Connect via telnet to a mongo service as admin user mongo:clone Create container then copy data from into mongo:connect Connect via telnet to a mongo service mongo:create Create a mongo service with environment variables mongo:destroy Delete the service and stop its container if there are no links left mongo:export > Export a dump of the mongo service database mongo:expose [port] Expose a mongo service on custom port if provided (random port otherwise) -mongo:import < Import a dump into the mongo service database +mongo:import < Import a dump into the mongo service database mongo:info Print the connection information mongo:link Link the mongo service to the app mongo:list List all mongo services diff --git a/commands b/commands index df51308..afdc397 100755 --- a/commands +++ b/commands @@ -19,6 +19,10 @@ case "$1" in "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/subcommands/connect" "$@" ;; + $PLUGIN_COMMAND_PREFIX:admin) + "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/subcommands/admin" "$@" + ;; + $PLUGIN_COMMAND_PREFIX:create) "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/subcommands/create" "$@" ;; @@ -84,6 +88,7 @@ case "$1" in # shellcheck disable=SC2034 declare desc="return $PLUGIN_COMMAND_PREFIX plugin help content" cat<, Connect via mongo to a $PLUGIN_SERVICE service as admin user $PLUGIN_COMMAND_PREFIX:clone , Create container then copy data from into $PLUGIN_COMMAND_PREFIX:connect , Connect via mongo to a $PLUGIN_SERVICE service $PLUGIN_COMMAND_PREFIX:create , Create a $PLUGIN_SERVICE service diff --git a/subcommands/admin b/subcommands/admin new file mode 100644 index 0000000..54316ec --- /dev/null +++ b/subcommands/admin @@ -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" + +mongo-admin-cmd() { + declare desc="connect via mongo to a $PLUGIN_SERVICE service as admin user" + local cmd="$PLUGIN_COMMAND_PREFIX:admin" 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")" + PASSWORD="$(cat "$SERVICE_ROOT/ROOTPASSWORD")" + has_tty && SERVICE_TTY_OPTS="-t" + + docker exec -i $SERVICE_TTY_OPTS "$SERVICE_NAME" mongo -u admin -p "$PASSWORD" --authenticationDatabase admin "$SERVICE" +} + +mongo-admin-cmd "$@" From c148691ea71a21474d37d211206306fd374158bf Mon Sep 17 00:00:00 2001 From: Vitaly Domnikov Date: Mon, 11 Jul 2016 16:51:10 -0700 Subject: [PATCH 2/3] rename admin command --- README.md | 2 +- commands | 4 ++-- subcommands/{admin => connect-admin} | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) rename subcommands/{admin => connect-admin} (93%) diff --git a/README.md b/README.md index 399a0d4..5b927a2 100644 --- a/README.md +++ b/README.md @@ -17,9 +17,9 @@ dokku plugin:install https://github.com/dokku/dokku-mongo.git mongo ## commands ``` -mongo:admin Connect via telnet to a mongo service as admin user mongo:clone Create container then copy data from into mongo:connect Connect via telnet to a mongo service +mongo:connect-admin Connect via telnet to a mongo service as admin user mongo:create Create a mongo service with environment variables mongo:destroy Delete the service and stop its container if there are no links left mongo:export > Export a dump of the mongo service database diff --git a/commands b/commands index afdc397..7d972ad 100755 --- a/commands +++ b/commands @@ -19,8 +19,8 @@ case "$1" in "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/subcommands/connect" "$@" ;; - $PLUGIN_COMMAND_PREFIX:admin) - "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/subcommands/admin" "$@" + $PLUGIN_COMMAND_PREFIX:connect-admin) + "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/subcommands/connect-admin" "$@" ;; $PLUGIN_COMMAND_PREFIX:create) diff --git a/subcommands/admin b/subcommands/connect-admin similarity index 93% rename from subcommands/admin rename to subcommands/connect-admin index 54316ec..ac4ac13 100644 --- a/subcommands/admin +++ b/subcommands/connect-admin @@ -4,7 +4,7 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_BASE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" -mongo-admin-cmd() { +mongo-connect-admin-cmd() { declare desc="connect via mongo to a $PLUGIN_SERVICE service as admin user" local cmd="$PLUGIN_COMMAND_PREFIX:admin" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1 declare SERVICE="$1" @@ -19,4 +19,4 @@ mongo-admin-cmd() { docker exec -i $SERVICE_TTY_OPTS "$SERVICE_NAME" mongo -u admin -p "$PASSWORD" --authenticationDatabase admin "$SERVICE" } -mongo-admin-cmd "$@" +mongo-connect-admin-cmd "$@" From 9098f2e9cc9abd16947c5a04c9d742e1653ab174 Mon Sep 17 00:00:00 2001 From: Vitaly Domnikov Date: Mon, 11 Jul 2016 16:52:58 -0700 Subject: [PATCH 3/3] rename admin command --- commands | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands b/commands index 7d972ad..073d9f6 100755 --- a/commands +++ b/commands @@ -88,9 +88,9 @@ case "$1" in # shellcheck disable=SC2034 declare desc="return $PLUGIN_COMMAND_PREFIX plugin help content" cat<, Connect via mongo to a $PLUGIN_SERVICE service as admin user $PLUGIN_COMMAND_PREFIX:clone , Create container then copy data from into $PLUGIN_COMMAND_PREFIX:connect , Connect via mongo to a $PLUGIN_SERVICE service + $PLUGIN_COMMAND_PREFIX:connect-admin , Connect via mongo to a $PLUGIN_SERVICE service as admin user $PLUGIN_COMMAND_PREFIX:create , Create a $PLUGIN_SERVICE service $PLUGIN_COMMAND_PREFIX:destroy , Delete the $PLUGIN_SERVICE service and stop its container if there are no links left $PLUGIN_COMMAND_PREFIX:export , Export a dump of the $PLUGIN_SERVICE service database