|
|
@ -10,29 +10,35 @@ DBNAME=$(relation-get dbname) || { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
dbs=$(mongo:db:ls) || exit 1 |
|
|
|
if matching_db=$(e "$dbs" | egrep "[a-zA-Z0-9.-_]*_${DBNAME}"); then |
|
|
|
if e "$dbs" | grep "^${DBNAME}$"; then |
|
|
|
err "Error: unexpected database '$matching_db'" \ |
|
|
|
"found along with database named '${DBNAME}'." |
|
|
|
exit 1 |
|
|
|
fi |
|
|
|
## Let's take for granted that only current source service is |
|
|
|
## concerned by the database. We need to restart source service |
|
|
|
## container only if already running. |
|
|
|
container_ids=($(get_running_containers_for_service "$MASTER_BASE_SERVICE_NAME")) |
|
|
|
for container_id in "${container_ids[@]}"; do |
|
|
|
mongo_url=$(docker:container:env_get "$container_id" MONGO_URL) || return 1 |
|
|
|
if [[ "$mongo_url" == */"${matching_db}"* ]]; then |
|
|
|
info "Attempting to stop current containers of service $MASTER_BASE_SERVICE_NAME" |
|
|
|
docker stop -t 5 "$container_id" |
|
|
|
ensure_db_docker_running |
|
|
|
|
|
|
|
if dbs=$(mongo:db:ls); then |
|
|
|
if matching_db=$(e "$dbs" | egrep "[a-zA-Z0-9.-_]*_${DBNAME}"); then |
|
|
|
if e "$dbs" | grep "^${DBNAME}$"; then |
|
|
|
err "Error: unexpected database '$matching_db'" \ |
|
|
|
"found along with database named '${DBNAME}'." |
|
|
|
exit 1 |
|
|
|
fi |
|
|
|
done |
|
|
|
|
|
|
|
mongo:db:rename "$matching_db" "${DBNAME}" |
|
|
|
|
|
|
|
## we DO NOT want to start the stopped container again as they are not |
|
|
|
## properly configured |
|
|
|
## Let's take for granted that only current source service is |
|
|
|
## concerned by the database. We need to restart source service |
|
|
|
## container only if already running. |
|
|
|
container_ids=($(get_running_containers_for_service "$MASTER_BASE_SERVICE_NAME")) |
|
|
|
for container_id in "${container_ids[@]}"; do |
|
|
|
mongo_url=$(docker:container:env_get "$container_id" MONGO_URL) || return 1 |
|
|
|
if [[ "$mongo_url" == */"${matching_db}"* ]]; then |
|
|
|
info "Attempting to stop current containers of service $MASTER_BASE_SERVICE_NAME" |
|
|
|
docker stop -t 5 "$container_id" |
|
|
|
fi |
|
|
|
done |
|
|
|
|
|
|
|
mongo:db:rename "$matching_db" "${DBNAME}" |
|
|
|
|
|
|
|
## we DO NOT want to start the stopped container again as they are not |
|
|
|
## properly configured |
|
|
|
fi |
|
|
|
else |
|
|
|
err "Failed to query for database list" |
|
|
|
exit 14 |
|
|
|
fi |
|
|
|
|
|
|
|
## ReplicaSet initialization |
|
|
|