Skip to content
Permalink
master
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time
executable file 140 lines (130 sloc) 4.68 KB
#!/bin/bash
#
# Command Line Interface to start all services associated with the Tutorial
#
# For this tutorial the commands are merely a convenience script to run docker or docker-compose
#
# Each services script can be run using either docker-compose (the external tool with the hyphen -)
# or docker compose (the newer version directly bundled with Docker with a space )
#
# if you start up with the following command:
#
# ./services start legacy
#
# This will force the script to use docker-compose which may be more reliable in
# some cases (or if an older version of Docker is being used)
set -e
dockerCmd="docker compose"
if (( $# == 2 )); then
dockerCmd="docker-compose"
fi
if (( $# < 1 )); then echo "Illegal number of parameters"
echo "usage: services [create|orion|scorpio|stellio|stop]"
exit 1
fi
waitForOrion () {
echo -e "\n⏳ Waiting for \033[1;34mOrion-LD\033[0m to be available\n"
while ! [ `docker inspect --format='{{.State.Health.Status}}' fiware-orion` == "healthy" ]
do
echo -e "Context Broker HTTP state: " `curl -s -o /dev/null -w %{http_code} 'http://localhost:1026/version'` " (waiting for 200)"
sleep 1
done
}
waitForScorpio () {
echo -e "\n⏳ Waiting for \033[1;34mScorpio\033[0m to respond\n"
waitSeconds=30
while [ `docker run --network fiware_default --rm curlimages/curl -s -o /dev/null -w %{http_code} 'http://scorpio:9090/scorpio/v1/info/'` -eq 000 ]
do
echo -e "Context Broker HTTP state: " `curl -s -o /dev/null -w %{http_code} 'http://localhost:9090/scorpio/v1/info/'` " (waiting for 500)"
echo -e "Waiting for ${waitSeconds} seconds ..."
sleep ${waitSeconds}
done
echo -e "\n⏳ Waiting for all \033[1;34mScorpio\033[0m services to be fully available\n"
while [ `docker run --network fiware_default --rm curlimages/curl -s -o /dev/null -w %{http_code} 'http://scorpio:9090/scorpio/v1/info/'` -eq 500 ]
do
echo -e "Context Broker HTTP state: " `curl -s -o /dev/null -w %{http_code} 'http://localhost:9090/scorpio/v1/info/'` " (waiting for 200)"
waitSeconds=$((waitSeconds+5))
echo -e "Waiting for ${waitSeconds} seconds ..."
sleep ${waitSeconds}
done
}
waitForMongo () {
echo -e "\n⏳ Waiting for \033[1mMongoDB\033[0m to be available\n"
while ! [ `docker inspect --format='{{.State.Health.Status}}' db-mongo` == "healthy" ]
do
sleep 1
done
}
stoppingContainers () {
echo "Stopping running containers"
${dockerCmd} -f docker-compose/orion-ld.yml down -v --remove-orphans
${dockerCmd} -f docker-compose/scorpio-aaio.yml down -v --remove-orphans
}
addDatabaseIndex () {
printf "Create \033[1mMongoDB\033[0m database indexes ..."
docker exec db-mongo mongo --eval '
conn = new Mongo();db.createCollection("orion");
db = conn.getDB("orion");
db.createCollection("entities");
db.entities.createIndex({"_id.servicePath": 1, "_id.id": 1, "_id.type": 1}, {unique: true});
db.entities.createIndex({"_id.type": 1});
db.entities.createIndex({"_id.id": 1});' > /dev/null
echo -e " \033[1;32mdone\033[0m"
}
displayServices () {
echo ""
docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" --filter name=$1-*
echo ""
}
command="$1"
case "${command}" in
"help")
echo "usage: services [create|orion|scorpio|stellio|stop]"
;;
"start")
export $(cat .env | grep "#" -v)
./services orion $2
;;
"orion")
stoppingContainers
echo -e "Starting containers: \033[1;34mOrion-LD\033[0m and a \033[1;30mMongoDB\033[0m database."
echo -e "- \033[1;34mOrion-LD\033[0m is the context broker"
echo ""
${dockerCmd} -f docker-compose/orion-ld.yml up -d --remove-orphans
waitForMongo
addDatabaseIndex
displayServices
waitForOrion
;;
"scorpio")
stoppingContainers
echo -e "Starting containers: \033[1;34mScorpio\033[0m, \033[1mKafka\033[0m, \033[1mZookeeper\033[0m and a \033[1mPostgres\033[0m database."
echo -e "- \033[1;34mScorpio\033[0m is the context broker\n"
${dockerCmd} -f docker-compose/scorpio-aaio.yml up -d --remove-orphans
displayServices scorpio
waitForScorpio
;;
"stellio")
stoppingContainers
echo -e "Starting containers: \033[1;34mScorpio\033[0m, \033[1mKafka\033[0m, \033[1mZookeeper\033[0m and a \033[1mPostgres\033[0m database."
echo -e "- \033[1;34mStellio\033[0m is the context broker\n"
${dockerCmd} -f docker-compose/stellio.yml up -d --remove-orphans
;;
"stop")
export $(cat .env | grep "#" -v)
stoppingContainers
;;
"create")
export $(cat .env | grep "#" -v)
echo "Pulling Docker images"
docker pull curlimages/curl
${dockerCmd} -f docker-compose/scorpio-aaio.yml pull
${dockerCmd} -f docker-compose/orion-ld.yml pull
${dockerCmd} -f docker-compose/stellio.yml pull
;;
*)
echo "Command not Found."
echo "usage: services [create|orion|scorpio|stop]"
exit 127;
;;
esac