forked from jason-fox/csv-to-json
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservices
More file actions
executable file
·110 lines (98 loc) · 2.65 KB
/
services
File metadata and controls
executable file
·110 lines (98 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/bin/bash
#
# Command Line Interface to start all services associated with the Getting-Started Tutorial
#
# For this tutorial the commands are merely a convenience script to run docker-compose
#
set -e
ORION="http://orion:1026/version"
CONTEXT="http://csv-agent:3000/data-models/ngsi-context.jsonld"
if (( $# != 1 )); then
echo "Illegal number of parameters"
echo "usage: services [create|start|stop]"
exit 1
fi
pause(){
printf " "
count="$1"
[ "$count" -gt 59 ] && printf "Waiting one minute " || printf " Waiting a few seconds ";
while [ "$count" -gt 0 ]
do
printf "."
sleep 3
count=$((count - 3))
done
echo ""
}
getHeartbeat(){
eval "response=$(docker run --network fiware_default --rm curlimages/curl -s -o /dev/null -w "%{http_code}" "$1")"
}
waitForOrion () {
echo -e "\n⏳ Waiting for \033[1;34mOrion-LD\033[0m to be available\n"
getHeartbeat "${ORION}"
while [ "${response}" -eq 000 ]
do
echo -e "\nContext Broker HTTP state: ${response} (waiting for 200)"
pause 6
getHeartbeat "${ORION}"
done
}
waitForContext () {
echo -e "\n⏳ Waiting for \033[1m@context\033[0m to be available\n"
getHeartbeat "${CONTEXT}"
while [ "${response}" -eq 000 ]
do
echo -e "\n@context HTTP state: ${response} (waiting for 200)"
pause 3
getHeartbeat "${CONTEXT}"
done
}
stoppingContainers () {
echo "Stopping containers"
docker-compose --log-level ERROR -p fiware 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|stop]"
;;
"start")
stoppingContainers
echo -e "Starting three containers \033[1;34mOrion-LD\033[0m, \033[1;30mCSV-Agent\033[0m and a \033[1;30mMongoDB\033[0m database."
echo -e "- \033[1;34mOrion-LD\033[0m is the context broker"
echo ""
docker-compose --log-level ERROR -p fiware up -d --remove-orphans
addDatabaseIndex
displayServices
waitForOrion
waitForContext
;;
"stop")
stoppingContainers
;;
"create")
echo "Pulling Docker images"
docker-compose --log-level ERROR pull
;;
*)
echo "Command not Found."
echo "usage: services [create|start|stop]"
exit 127;
;;
esac