forked from 0k/0k-charms
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.2 KiB
56 lines
1.2 KiB
# -*- mode: shell-script -*-
|
|
|
|
include pretty
|
|
|
|
export DB_NAME="$SERVICE_NAME" ## general type of database (ie: postgres/mysql...)
|
|
export DB_DATADIR=/var/lib/mongodb
|
|
|
|
export DATA_DIR=$SERVICE_DATASTORE$DB_DATADIR
|
|
|
|
|
|
is_db_locked() {
|
|
is_volume_used "$DATASTORE/${SERVICE_NAME}"
|
|
}
|
|
|
|
|
|
_set_server_db_params() {
|
|
server_docker_opts+=("-v" "${SERVICE_CONFIGSTORE}/etc/mongod.conf:/etc/mongod.conf"
|
|
"--add-host" "${SERVICE_NAME}:127.0.0.1")
|
|
}
|
|
|
|
_set_db_params() {
|
|
local docker_ip="$1" docker_network="$2"
|
|
|
|
db_docker_opts+=("--network" "$docker_network")
|
|
|
|
db_cmd_opts+=("--host" "$docker_ip")
|
|
check_command="db.serverStatus().ok"
|
|
}
|
|
|
|
ddb() { dcmd mongo --quiet "$@"; }
|
|
|
|
|
|
mongo:db:ls() {
|
|
local out
|
|
if ! out=$(ddb < <(echo "JSON.stringify(db.adminCommand( { listDatabases: 1 } ))")); then
|
|
err "Could not query list of databases."
|
|
return 1
|
|
fi
|
|
e "$out" | jq -r '.databases[] | .name'
|
|
}
|
|
|
|
|
|
mongo:db:rename() {
|
|
local src="$1" dst="$2" out
|
|
if ! out=$(ddb <<EOF
|
|
db.copyDatabase("$src","$dst");
|
|
use $src;
|
|
db.dropDatabase();
|
|
EOF
|
|
); then
|
|
err "Could not rename database '$src' to '$dst'."
|
|
err "$out"
|
|
return 1
|
|
fi
|
|
debug "$out"
|
|
}
|