|
@ -439,7 +439,7 @@ _clean_docker() { |
|
|
docker stop "$container_id" |
|
|
docker stop "$container_id" |
|
|
docker rm "$_DB_NAME" |
|
|
docker rm "$_DB_NAME" |
|
|
docker network rm "${_DB_NAME}" |
|
|
docker network rm "${_DB_NAME}" |
|
|
rm -vf "/tmp/${_DB_NAME}.state" |
|
|
|
|
|
|
|
|
rm -vf "$state_tmpdir/${_DB_NAME}.state" |
|
|
) |
|
|
) |
|
|
} |
|
|
} |
|
|
export -f _clean_docker |
|
|
export -f _clean_docker |
|
@ -507,7 +507,7 @@ ensure_db_docker_running () { |
|
|
local _STATE_FILE |
|
|
local _STATE_FILE |
|
|
|
|
|
|
|
|
_DB_NAME="db_${DB_NAME}_${_PID}" |
|
|
_DB_NAME="db_${DB_NAME}_${_PID}" |
|
|
_STATE_FILE=/tmp/${_DB_NAME}.state |
|
|
|
|
|
|
|
|
_STATE_FILE="$state_tmpdir/${_DB_NAME}.state" |
|
|
if [ -e "$_STATE_FILE" ]; then |
|
|
if [ -e "$_STATE_FILE" ]; then |
|
|
IFS=: read DOCKER_NETWORK DOCKER_IP <<<"$(cat "$_STATE_FILE")" |
|
|
IFS=: read DOCKER_NETWORK DOCKER_IP <<<"$(cat "$_STATE_FILE")" |
|
|
|
|
|
|
|
@ -517,7 +517,7 @@ ensure_db_docker_running () { |
|
|
return 0 |
|
|
return 0 |
|
|
fi |
|
|
fi |
|
|
|
|
|
|
|
|
if [ -e "/tmp/${_DB_NAME}.working" ]; then |
|
|
|
|
|
|
|
|
if [ -e "$state_tmpdir/${_DB_NAME}.working" ]; then |
|
|
## avoid recursive calls. |
|
|
## avoid recursive calls. |
|
|
if [ -z "$DOCKER_IP" ]; then |
|
|
if [ -z "$DOCKER_IP" ]; then |
|
|
err "Currently figuring up DOCKER_IP, please set it yourself before this call if needed." |
|
|
err "Currently figuring up DOCKER_IP, please set it yourself before this call if needed." |
|
@ -528,7 +528,7 @@ ensure_db_docker_running () { |
|
|
return 0 |
|
|
return 0 |
|
|
fi |
|
|
fi |
|
|
|
|
|
|
|
|
touch "/tmp/${_DB_NAME}.working" |
|
|
|
|
|
|
|
|
touch "$state_tmpdir/${_DB_NAME}.working" |
|
|
|
|
|
|
|
|
docker rm "$_DB_NAME" 2>/dev/null || true |
|
|
docker rm "$_DB_NAME" 2>/dev/null || true |
|
|
|
|
|
|
|
@ -568,7 +568,7 @@ ensure_db_docker_running () { |
|
|
if ! network_id=$(docker network create "$_DB_NAME"); then |
|
|
if ! network_id=$(docker network create "$_DB_NAME"); then |
|
|
err "'docker network create' failed !" |
|
|
err "'docker network create' failed !" |
|
|
_clean_docker "$_DB_NAME" "$container_id" |
|
|
_clean_docker "$_DB_NAME" "$container_id" |
|
|
rm "/tmp/${_DB_NAME}.working" |
|
|
|
|
|
|
|
|
rm "$state_tmpdir/${_DB_NAME}.working" |
|
|
return 1 |
|
|
return 1 |
|
|
fi |
|
|
fi |
|
|
debug docker run -d \ |
|
|
debug docker run -d \ |
|
@ -587,7 +587,7 @@ ensure_db_docker_running () { |
|
|
); then |
|
|
); then |
|
|
err "'docker run' failed !" |
|
|
err "'docker run' failed !" |
|
|
_clean_docker "$_DB_NAME" "$container_id" |
|
|
_clean_docker "$_DB_NAME" "$container_id" |
|
|
rm "/tmp/${_DB_NAME}.working" |
|
|
|
|
|
|
|
|
rm "$state_tmpdir/${_DB_NAME}.working" |
|
|
return 1 |
|
|
return 1 |
|
|
fi |
|
|
fi |
|
|
trap_add EXIT,ERR "_clean_docker \"$_DB_NAME\" \"$container_id\"" |
|
|
trap_add EXIT,ERR "_clean_docker \"$_DB_NAME\" \"$container_id\"" |
|
@ -597,14 +597,14 @@ ensure_db_docker_running () { |
|
|
IFS=: read DOCKER_NETWORK DOCKER_IP <<<"$docker_ip" |
|
|
IFS=: read DOCKER_NETWORK DOCKER_IP <<<"$docker_ip" |
|
|
echo "$docker_ip" > "$_STATE_FILE" |
|
|
echo "$docker_ip" > "$_STATE_FILE" |
|
|
debug "written '$_STATE_FILE'" |
|
|
debug "written '$_STATE_FILE'" |
|
|
rm "/tmp/${_DB_NAME}.working" |
|
|
|
|
|
|
|
|
rm "$state_tmpdir/${_DB_NAME}.working" |
|
|
_set_db_params "$DOCKER_IP" "$DOCKER_NETWORK" |
|
|
_set_db_params "$DOCKER_IP" "$DOCKER_NETWORK" |
|
|
return 0 |
|
|
return 0 |
|
|
else |
|
|
else |
|
|
errlvl="$?" |
|
|
errlvl="$?" |
|
|
err "Db not found (errlvl: $errlvl). Tail of docker logs follows:" |
|
|
err "Db not found (errlvl: $errlvl). Tail of docker logs follows:" |
|
|
docker logs --tail=5 "$container_id" 2>&1 | prefix " | " >&2 |
|
|
docker logs --tail=5 "$container_id" 2>&1 | prefix " | " >&2 |
|
|
rm "/tmp/${_DB_NAME}.working" |
|
|
|
|
|
|
|
|
rm "$state_tmpdir/${_DB_NAME}.working" |
|
|
return "$errlvl" |
|
|
return "$errlvl" |
|
|
fi |
|
|
fi |
|
|
} |
|
|
} |
|
|