Skip to content
Permalink
master
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time
#!/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|https|start|stop]"
exit 1
fi
startContainers () {
echo ""
export IDM_HTTPS_ENABLED="$1"
${dockerCmd} up -d --remove-orphans
echo ""
}
displayServices () {
echo ""
docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" --filter name=fiware-*
echo ""
}
stoppingContainers () {
echo "Stopping running containers"
${dockerCmd} down -v --remove-orphans
}
waitForKeyrock () {
echo -e "⏳ Waiting for \033[1;31mKeyrock\033[0m to be available\n"
while [ `curl -s -o /dev/null -w %{http_code} 'http://localhost:3005/version'` -eq 000 ]
do
echo -e "Keyrock HTTP state: " `curl -s -o /dev/null -w %{http_code} 'http://localhost:3005/version'` " (waiting for 200)"
sleep 5
done
echo -e " \033[1;32mdone\033[0m"
}
waitForSecureKeyrock () {
echo -e "⏳ Waiting for \033[1;31mKeyrock\033[0m to be available\n"
while [ `curl -k -s -o /dev/null -w %{http_code} 'https://localhost:3443/version'` -eq 000 ]
do
echo -e "Keyrock HTTP state: " `curl -k -s -o /dev/null -w %{http_code} 'https://localhost:3443/version'` " (waiting for 200)"
sleep 5
done
echo -e " \033[1;32mdone\033[0m"
}
command="$1"
case "${command}" in
"help")
echo "usage: services [create|https|start|stop]"
;;
"start")
export $(cat .env | grep "#" -v)
stoppingContainers
echo -e "Starting containers: \033[1;31mKeyrock\033[0m and a \033[1mMySQL\033[0m database."
echo -e "- \033[1;31mKeyrock\033[0m is an Identity Management Front-End under HTTP"
startContainers false
waitForKeyrock
displayServices
echo -e "Now open \033[4mhttp://localhost:3005/idm\033[0m"
;;
"https")
stoppingContainers
echo -e "Starting containers: \033[1;31mKeyrock\033[0m and a \033[1mMySQL\033[0m database."
echo -e "- \033[1;31mKeyrock\033[0m is an Identity Management Front-End under HTTPS"
startContainers true
waitForSecureKeyrock
displayServices
echo -e "Now open \033[4mhttps://localhost:3443/idm\033[0m"
;;
"stop")
export $(cat .env | grep "#" -v)
stoppingContainers
;;
"create")
export $(cat .env | grep "#" -v)
echo "Pulling Docker images"
docker pull curlimages/curl
${dockerCmd} pull
;;
*)
echo "Command not Found."
echo "usage: services [create|start|stop]"
exit 127;
;;
esac