-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathservices
executable file
·233 lines (212 loc) · 8.31 KB
/
services
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#!/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|southport|northport]"
exit 1
fi
loadData () {
docker run --rm -v $(pwd)/import-data:/import-data \
--network fiware_default \
-e ORION_PORT="${ORION_PORT}" \
-e TUTORIAL_APP_PORT="${TUTORIAL_APP_PORT}" \
--entrypoint /bin/ash quay.io/curl/curl /import-data
waitForIoTAgent
docker run --rm -v $(pwd)/provision-devices:/provision-devices \
--network fiware_default \
-e ORION_PORT="${ORION_PORT}" \
-e TUTORIAL_APP_PORT="${TUTORIAL_APP_PORT}" \
-e TUTORIAL_DUMMY_DEVICE_PORT="${TUTORIAL_DUMMY_DEVICE_PORT}" \
-e IOTA_NORTH_PORT="${IOTA_NORTH_PORT}" \
--entrypoint /bin/ash quay.io/curl/curl /provision-devices
echo ""
}
waitForKeyrock () {
printf "⏳ Waiting for \033[1;31mKeyrock\033[0m to be available\n"
while ! [ `docker inspect --format='{{.State.Health.Status}}' fiware-keyrock` == "healthy" ]
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"
}
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
}
waitForOrion () {
echo -e "\n⏳ Waiting for \033[1;34mOrion\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
}
waitForIoTAgent () {
echo -e "\n⏳ Waiting for \033[1;36mIoT-Agent\033[0m to be available\n"
while ! [ `docker inspect --format='{{.State.Health.Status}}' fiware-iot-agent` == "healthy" ]
do
echo -e "IoT Agent HTTP state: " `curl -s -o /dev/null -w %{http_code} 'http://localhost:4041/version'` " (waiting for 200)"
sleep 1
done
}
displayServices () {
echo ""
docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" --filter name=fiware-*
(gp ports list 2> /dev/null) || true
echo ""
}
addDatabaseIndex () {
printf "Adding appropriate \033[1mMongoDB\033[0m indexes for \033[1;34mOrion\033[0m ..."
docker exec db-mongo mongosh --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
docker exec db-mongo mongosh --eval '
conn = new Mongo();db.createCollection("orion-openiot");
db = conn.getDB("orion-openiot");
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"
}
startContainers () {
echo ""
export IDM_HTTPS_ENABLED="$1"
${dockerCmd} -f docker-compose/$2 up -d --remove-orphans
echo ""
}
stoppingContainers () {
export $(cat .env | grep "#" -v)
echo "Stopping running containers"
${dockerCmd} -f docker-compose/southport-wilma.yml down -v --remove-orphans
}
command="$1"
case "${command}" in
"help")
echo "usage: services [create|orion|orion-wilma|orion-kong|northport]"
;;
"orion")
stoppingContainers
echo -e "Starting containers: \033[1;34mOrion\033[0m, \033[1;36mIoT-Agent\033[0m, \033[1;31mKeyrock\033[0m, \033[1;31mWilma\033[0m, \033[1mTutorial\033[0m and \033[1mMongoDB\033[0m and \033[1mMySQL\033[0m databases."
echo -e "- \033[1;34mOrion\033[0m is the context broker"
echo -e "- \033[1;36mIoT-Agent\033[0m is configured for the UltraLight Protocol"
echo -e "- \033[1mTutorial\033[0m acts as a series of dummy IoT Sensors over HTTP"
echo -e "- \033[1;31mKeyrock\033[0m is an Identity Management Front-End"
echo -e "- \033[1;31mWilma\033[0m is a PEP Proxy around \033[1;34mOrion\033[0m"
startContainers false orion-wilma.yml
waitForKeyrock
export ORION_URL="http://orion:1026"
waitForMongo
addDatabaseIndex
waitForOrion
loadData
displayServices
echo -e "Now open \033[4mhttp://localhost:3000\033[0m"
;;
"orion-kong")
stoppingContainers
echo -e "Starting containers: \033[1;34mOrion\033[0m, \033[1;36mIoT-Agent\033[0m, \033[1;31mKeyrock\033[0m, \033[1;31mKong\033[0m, \033[1mTutorial\033[0m and \033[1mMongoDB\033[0m and \033[1mMySQL\033[0m databases."
echo -e "- \033[1;34mOrion\033[0m is the context broker"
echo -e "- \033[1;36mIoT-Agent\033[0m is configured for the UltraLight Protocol"
echo -e "- \033[1mTutorial\033[0m acts as a series of dummy IoT Sensors over HTTP"
echo -e "- \033[1;31mKeyrock\033[0m is an Identity Management Front-End"
echo -e "- \033[1;31mKong\033[0m is a PEP Proxy around \033[1;34mOrion\033[0m"
startContainers false orion-kong.yml
waitForKeyrock
export ORION_URL="http://orion:1026"
waitForMongo
addDatabaseIndex
waitForOrion
loadData
displayServices
echo -e "Now open \033[4mhttp://localhost:3000\033[0m"
;;
"southport")
stoppingContainers
echo -e "Starting containers: \033[1;34mOrion\033[0m, \033[1;36mIoT-Agent\033[0m, \033[1;31mKeyrock\033[0m, \033[1;31mWilma\033[0m, \033[1mTutorial\033[0m and \033[1mMongoDB\033[0m and \033[1mMySQL\033[0m databases."
echo -e "- \033[1;34mOrion\033[0m is the context broker"
echo -e "- \033[1;36mIoT-Agent\033[0m is configured for the UltraLight Protocol"
echo -e "- \033[1mTutorial\033[0m acts as a series of dummy IoT Sensors over HTTP"
echo -e "- \033[1;31mKeyrock\033[0m is an Identity Management Front-End"
echo -e "- 2 instances of \033[1;31mWilma\033[0m as a PEP Proxy around \033[1;34mOrion\033[0m and between the Devices and \033[1;36mIoT-Agent\033[0m Southport"
startContainers false southport-wilma.yml
waitForKeyrock
waitForMongo
addDatabaseIndex
waitForOrion
loadData
displayServices
echo -e "Now open \033[4mhttp://localhost:3000\033[0m"
;;
"northport")
stoppingContainers
echo -e "Starting containers: \033[1;34mOrion\033[0m, \033[1;36mIoT-Agent\033[0m, \033[1;31mKeyrock\033[0m, \033[1;31mWilma\033[0m, \033[1mTutorial\033[0m and \033[1mMongoDB\033[0m and \033[1mMySQL\033[0m databases."
echo -e "- \033[1;34mOrion\033[0m is the context broker"
echo -e "- \033[1;36mIoT-Agent\033[0m is configured for the UltraLight Protocol"
echo -e "- \033[1mTutorial\033[0m acts as a series of dummy IoT Sensors over HTTP"
echo -e "- \033[1;31mKeyrock\033[0m is an Identity Management Front-End"
echo -e "- \033[1;31mWilma\033[0m as a PEP Proxy between \033[1;34mOrion\033[0m and the \033[1;36mIoT-Agent\033[0m"
startContainers false northport-wilma.yml
waitForKeyrock
export ORION_URL="http://orion-proxy:1027"
waitForMongo
addDatabaseIndex
docker run --rm -v $(pwd)/import-data:/import-data \
--network fiware_default \
--entrypoint /bin/ash quay.io/curl/curl /import-data
waitForIoTAgent
docker run --rm -v $(pwd)/provision-groups:/provision-groups \
--network fiware_default \
--entrypoint /bin/ash quay.io/curl/curl /provision-groups
echo
displayServices
echo -e "Now open \033[4mhttp://localhost:3000\033[0m"
;;
"stop")
stoppingContainers
;;
"start")
./services orion $2
;;
"orion-wilma")
./services orion $2
;;
"create")
export $(cat .env | grep "#" -v)
echo "Pulling Docker images"
docker pull -q quay.io/curl/curl
${dockerCmd} -f docker-compose/orion-wilma.yml pull
${dockerCmd} -f docker-compose/orion-kong.yml pull
;;
*)
echo "Command not Found."
echo "usage: services [create|orion-wilma|orion-kong|southport|northport|stop]"
exit 127;
;;
esac