[IMP] Smart way to wait about postgreSQL initialization for restore()
This commit is contained in:
parent
acf07de49a
commit
553174219c
@ -283,7 +283,10 @@ restore() {
|
|||||||
$docker_cmd stop ${POSTGRES_DOCKER_NAME} && $docker_cmd rm ${POSTGRES_DOCKER_NAME} || error_and_quit "Failed to stop and delete postgreSQL Docker container: ${POSTGRES_DOCKER_NAME}"
|
$docker_cmd stop ${POSTGRES_DOCKER_NAME} && $docker_cmd rm ${POSTGRES_DOCKER_NAME} || error_and_quit "Failed to stop and delete postgreSQL Docker container: ${POSTGRES_DOCKER_NAME}"
|
||||||
sudo rm -rf ${DB_DIR} || error_and_quit "Failed to delete this directory: ${DB_DIR}"
|
sudo rm -rf ${DB_DIR} || error_and_quit "Failed to delete this directory: ${DB_DIR}"
|
||||||
$docker_cmd run -d -p ${POSTGRES_PORT}:5432 -v "${DB_DIR}:/var/lib/postgresql/data" --name "${POSTGRES_DOCKER_NAME}" "postgres:${POSTGRES_VERSION}" || error_and_quit "Launching database docker container failed."
|
$docker_cmd run -d -p ${POSTGRES_PORT}:5432 -v "${DB_DIR}:/var/lib/postgresql/data" --name "${POSTGRES_DOCKER_NAME}" "postgres:${POSTGRES_VERSION}" || error_and_quit "Launching database docker container failed."
|
||||||
sleep 6 # to wait about docker container runs totally
|
# Wait postgres was initialized
|
||||||
|
until $docker_cmd run --rm --link ${POSTGRES_DOCKER_NAME}:postgres postgres:${POSTGRES_VERSION} pg_isready -U postgres -h postgres; do
|
||||||
|
sleep 2
|
||||||
|
done
|
||||||
RESTORE_COMMAND="$docker_cmd run -it --rm --link ${POSTGRES_DOCKER_NAME}:db -v ${DUMP_DIR}:/backup -e PGHOST=`$docker_cmd inspect -f \"{{ .NetworkSettings.IPAddress }}\" ${POSTGRES_DOCKER_NAME}` -e PGUSER=postgres postgres:${POSTGRES_VERSION} pg_restore -d postgres /backup/${DUMP_FILE}"
|
RESTORE_COMMAND="$docker_cmd run -it --rm --link ${POSTGRES_DOCKER_NAME}:db -v ${DUMP_DIR}:/backup -e PGHOST=`$docker_cmd inspect -f \"{{ .NetworkSettings.IPAddress }}\" ${POSTGRES_DOCKER_NAME}` -e PGUSER=postgres postgres:${POSTGRES_VERSION} pg_restore -d postgres /backup/${DUMP_FILE}"
|
||||||
exec $RESTORE_COMMAND || error_and_quit "Failed to launch this command: ${CMD}"
|
exec $RESTORE_COMMAND || error_and_quit "Failed to launch this command: ${CMD}"
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user