Browse Source

fix: db connection, wait if receiving "the database system is starting up".

hostresources
Valentin Lab 6 years ago
parent
commit
5b6aca0072
  1. 32
      bin/compose-core

32
bin/compose-core

@ -807,7 +807,7 @@ export -f wait_for_tcp_port
## Warning: requires a ``ddb`` matching current database to be checked
wait_for_docker_ip() {
local name=$1 DOCKER_IP= DOCKER_NETWORK= docker_ips= docker_ip=
local name=$1 DOCKER_IP= DOCKER_NETWORK= docker_ips= docker_ip= elapsed timeout=10
docker_ip=$(wait_docker_ip "$name" 5) || return 1
IFS=: read DOCKER_NETWORK DOCKER_IP <<<"$docker_ip"
if ! str_is_ipv4 "$DOCKER_IP"; then
@ -823,12 +823,32 @@ wait_for_docker_ip() {
done < <(image_exposed_ports_0 "$container_id")
## Checking direct connection
if ! echo "SELECT 1;" | ddb >/dev/null; then
err "${RED}db connection error${NORMAL}:"\
timeout=10
start=$SECONDS
while true; do
if err=$(echo "SELECT 1;" | ddb 2>&1 >/dev/null); then
break
fi
if ! [[ "$err" == *"the database system is starting up" ]]; then
err "${RED}db connection error${NORMAL}:" \
"Could not connect to db on $DOCKER_IP container's IP."
echo " Note: IP up, TCP ports is(are) open" >&2
if [ "$err" ]; then
echo " Error:" >&2
printf "%s\n" "$err" | prefix " ${RED}!${NORMAL} " >&2
fi
return 18
fi
debug "Got starting up error '$err'."
elapsed=$((SECONDS - start))
if ((elapsed > timeout)); then
err "${RED}db connection error${NORMAL}:"\
"Could not connect to db on $DOCKER_IP" \
"container's IP. (IP up, TCP ports is(are) open)"
return 18
fi
"container's IP. (IP up, TCP ports is(are) open, sql answer after ${timeout}s)"
return 1
fi
sleep 0.2
done
echo "${DOCKER_NETWORK}:${DOCKER_IP}"
return 0
}

Loading…
Cancel
Save