Move all commands into subcommand structure

This commit is contained in:
Jose Diaz-Gonzalez
2016-05-15 21:44:56 -04:00
parent f1731bac00
commit fce29c7fc4
18 changed files with 360 additions and 173 deletions

35
subcommands/create Executable file
View File

@@ -0,0 +1,35 @@
#!/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"
mysql-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"
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"
fi
mkdir -p "$SERVICE_ROOT" || dokku_log_fail "Unable to create service directory"
mkdir -p "$SERVICE_ROOT/data" || dokku_log_fail "Unable to create service data directory"
mkdir -p "$SERVICE_ROOT/config" || dokku_log_fail "Unable to create service config directory"
echo -e "[mysqld]\nperformance_schema = 0" > "$SERVICE_ROOT/config/disable_performance_schema.cnf"
rootpassword=$(openssl rand -hex 8)
password=$(openssl rand -hex 8)
echo "$rootpassword" > "$SERVICE_ROOT/ROOTPASSWORD"
echo "$password" > "$SERVICE_ROOT/PASSWORD"
chmod 640 "$SERVICE_ROOT/ROOTPASSWORD" "$SERVICE_ROOT/PASSWORD"
touch "$LINKS_FILE"
if [[ -n $MYSQL_CUSTOM_ENV ]]; then
echo "$MYSQL_CUSTOM_ENV" | tr ';' "\n" > "$SERVICE_ROOT/ENV"
else
echo "" > "$SERVICE_ROOT/ENV"
fi
service_create_container "$SERVICE"
}
mysql-create-cmd "$@"