Skip to content

Commit 99ef552

Browse files
authored
Merge pull request #27 from linuxserver/dbwait
Enhance db wait startup check
2 parents d571bd1 + 68cb83c commit 99ef552

File tree

1 file changed

+13
-3
lines changed
  • root/etc/s6-overlay/s6-rc.d/init-unifi-network-application-config

1 file changed

+13
-3
lines changed

root/etc/s6-overlay/s6-rc.d/init-unifi-network-application-config/run

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,20 @@ if [[ ! -e /config/data/system.properties ]]; then
2323
if [[ -z "${MONGO_HOST}" ]]; then
2424
echo "*** No MONGO_HOST set, cannot configure database settings. ***"
2525
sleep infinity
26-
elif ! nc -w1 "${MONGO_HOST}" ${MONGO_PORT} >/dev/null 2>&1; then
27-
echo "*** Defined MONGO_HOST is not reachable, cannot proceed. ***"
28-
sleep infinity
2926
else
27+
echo "*** Waiting for MONGO_HOST ${MONGO_HOST} to be reachable. ***"
28+
DBCOUNT=0
29+
while true; do
30+
if nc -w1 "${MONGO_HOST}" "${MONGO_PORT}" >/dev/null 2>&1; then
31+
break
32+
fi
33+
DBCOUNT=$((DBCOUNT+1))
34+
if [[ ${DBCOUNT} -gt 6 ]]; then
35+
echo "*** Defined MONGO_HOST ${MONGO_HOST} is not reachable, cannot proceed. ***"
36+
sleep infinity
37+
fi
38+
sleep 5
39+
done
3040
sed -i "s/~MONGO_USER~/${MONGO_USER}/" /defaults/system.properties
3141
sed -i "s/~MONGO_HOST~/${MONGO_HOST}/" /defaults/system.properties
3242
sed -i "s/~MONGO_PORT~/${MONGO_PORT}/" /defaults/system.properties

0 commit comments

Comments
 (0)