Skip to content

Commit cafa0d6

Browse files
committed
Use healthcheck on start-up
1 parent 12510e6 commit cafa0d6

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

docker-compose.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ services:
3434
command: -dbhost mongo-db -logLevel DEBUG
3535
healthcheck:
3636
test: curl --fail -s http://orion:${ORION_PORT}/version || exit 1
37+
interval: 5s
3738

3839
# IoT-Agent is configured for the UltraLight Protocol
3940
#
@@ -127,7 +128,9 @@ services:
127128
healthcheck:
128129
test: |
129130
host=`hostname --ip-address || echo '127.0.0.1'`;
130-
mongo --quiet $host/test --eval 'quit(db.runCommand({ ping: 1 }).ok ? 0 : 2)' && echo 0 || echo 1
131+
mongo --quiet $host/test --eval 'quit(db.runCommand({ ping: 1 }).ok ? 0 : 2)' && echo 0 || echo 1
132+
interval: 5s
133+
131134

132135
# Other services
133136
mosquitto:

services

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,19 @@ addDatabaseIndex () {
6767
echo -e " \033[1;32mdone\033[0m"
6868
}
6969

70+
waitForMongo () {
71+
echo -e "\n⏳ Waiting for \033[1mMongoDB\033[0m to be available\n"
72+
while ! [ `docker inspect --format='{{.State.Health.Status}}' db-mongo` == "healthy" ]
73+
do
74+
sleep 1
75+
done
76+
}
77+
7078
waitForOrion () {
7179
echo -e "\n⏳ Waiting for \033[1;34mOrion\033[0m to be available\n"
72-
while [ `docker run --network fiware_default --rm curlimages/curl -s -o /dev/null -w %{http_code} 'http://orion:1026/version'` -eq 000 ]
73-
do
80+
81+
while ! [ `docker inspect --format='{{.State.Health.Status}}' fiware-orion` == "healthy" ]
82+
do
7483
echo -e "Context Broker HTTP state: " `curl -s -o /dev/null -w %{http_code} 'http://localhost:1026/version'` " (waiting for 200)"
7584
sleep 1
7685
done
@@ -100,6 +109,7 @@ case "${command}" in
100109
echo -e "- \033[1mMosquitto\033[0m acts as an MQTT Message Broker"
101110
echo ""
102111
docker-compose --log-level ERROR -p fiware up -d --remove-orphans
112+
waitForMongo
103113
addDatabaseIndex
104114
waitForOrion
105115
loadData

0 commit comments

Comments
 (0)