forked from claret-srl/ROMANTIG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
services
executable file
·212 lines (197 loc) · 6.3 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
#!/bin/bash
#
# Command Line Interface to start all services
#
set -e
setRedisCrateHostMemory () {
sudo sysctl -w vm.max_map_count=262144 # CrateDB
sudo sysctl vm.overcommit_memory=1 # Redis
echo ""
}
setEnviroment () {
export $(cat .env | grep "#" -v)
echo ""
}
# provisionDevices () {
# docker run --rm \
# -v $(pwd)/provision-devices.sh:/provision-devices.sh \
# --network fiware_default \
# -e ORION="${ORION}" \
# -e ORION_PORT="${ORION_PORT}" \
# -e QUANTUMLEAP="${QUANTUMLEAP}" \
# -e QUANTUMLEAP_PORT="${QUANTUMLEAP_PORT}" \
# -e ROSEAP_OEE="${ROSEAP_OEE}" \
# -e ROSEAP_OEE_PORT="${ROSEAP_OEE_PORT}" \
# -e FIWARE_SERVICE="${FIWARE_SERVICE}" \
# -e FIWARE_SERVICEPATH="${FIWARE_SERVICEPATH}" \
# -e DEVICE_ID="${DEVICE_ID}" \
# -e DEVICE_TYPE="${DEVICE_TYPE}" \
# -e OCB_ID_PROCESS="${OCB_ID_PROCESS}" \
# --entrypoint /bin/ash curlimages/curl provision-devices.sh
# }
waitForService () {
echo -e -n "⏳ Waiting for $1 to be available:"
while ! [ $TEST ]
do
if [ $# = 2 ]
then
TEST=$[`curl -s -o /dev/null -w %{http_code} "http://localhost:$2/version"` == 200]
else
TEST=$[`docker inspect --format="{{.State.Health.Status}}" $1` == "healthy"]
fi
sleep 1
done
echo -e "\t \033[1;32m Available \033[0m"
}
# WaitingDocker () {
# waitForService ${MONGO}
# waitForService ${ORION}
# waitForService ${IOTA} ${IOTA_NORTH_PORT}
# waitForService ${CRATE}
# waitForService ${QUANTUMLEAP}
# # provisionDevices
# echo ""
# }
startingServices () {
echo -e "Starting Services:"
echo -e "- FIWARE Orion Context Broker configured for NGSI-v2."
echo -e "- FIWARE QuantumLeap subscribed to context changes and persisting them into a Crate-DB database."
echo -e "- Engineering IoT-Agent for OPC-UA, receive northbound measurements in OPC-UA format and convert them to NGSI-v2 requests for the context broker to alter the state of the context entities."
echo -e "- Mongo-DB is the Orion Context Broker and IoT-Agent database to hold context data information such as data entities, subscriptions and registrations."
echo -e "- Crate-DB as a data sink to hold time-based historical context data and HTTP endpoint to interpret time-based data queries."
echo -e "- Grafana is a time series analytics tool will visualize data from CrateDB."
echo -e "- Claret ${ROSEAP_OEE} is a ROSE-AP module to calculate OEE data from CrateDB."
echo ""
ARG=""
if [[ $1 = 'demo' ]]
then
ARG='--profile demo '
fi
${dockerCmd} $ARG up -d
# ${dockerCmd} up -d --remove-orphans
# echo ""
# echo "Removing orphans volumes:"
# docker volume rm $(docker volume ls -q --filter dangling=true) || echo "No volumes to remove."
echo ""
}
stoppingServices () {
SERVICES=$(docker ps --filter "label=org.label=${ORG}" -aq)
if [[ -n $SERVICES ]]
then
echo "Stopping Services:"
echo ""
docker rm -f $SERVICES || true
fi
echo ""
}
deletingVolumesNetwork () {
VOLUMES=$(docker volume ls -qf dangling=true)
if [[ -n $VOLUMES ]]
then
echo "Removing all the Volumes of Docker:"
sudo docker volume rm $VOLUMES || true
fi
NETWORKS=$(docker network ls --filter "label=org.label=${ORG}" -q)
if [[ -n $NETWORKS ]]
then
echo "Removing all Networks of Docker:"
docker network rm $NETWORKS || true
fi
echo ""
}
displayServices () {
docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" --filter "label=org.label=${ORG}"
(gp ports list 2> /dev/null) || true
echo ""
}
setEnviroment
usage="usage: ./services <flag>
-h | --help Show this usage message.
-b | --build Builds the Docker Images for the ${ROSEAP_OEE}. Add demo, to build also the OPC-UA demo server.
-p | --pull Pulls images from Docker Hub. Running the pull command, without building the local images before, will result in an error.
up | --up Startup the services in a Docker Container (require 'sudo' to apply settings to the host). Add demo, to sturtup also the OPC-UA demo server.
down | --down Shoutdown the running services of the Docker Container.
-rm | --remove Remove the Docker Volumes and the Docker Networks. This will cause the loss of data stored in the databases.
-d | --debug Convenient script to Shoutdown, Builds and Startup the services. Add demo, to debug also the OPC-UA demo server."
dockerCmd="docker compose"
if (( $# == 2 ))
then
dockerCmd="docker-compose"
fi
if (( $# < 1 ))
then
echo "Illegal number of parameters."
echo "$usage"
echo ""
exit 1
fi
command="$1"
case "${command}" in
"-h"|"--help")
echo "$usage"
echo ""
;;
"-b"|"--build")
if [[ $2 = 'demo' ]]
then
ARG=${DEMO_SERVER}
else
ARG=${ROSEAP_OEE}
fi
echo "Building $ARG Docker images..."
echo ""
cd $ARG
docker image rm -f $ARG
docker build -t $ARG .
docker scan $ARG
cd ..
echo -e "\t \033[1;32m Done \033[0m\n"
;;
"-p"|"--pull")
./services --build
./services --build demo
echo "Pulling Docker images..."
docker pull curlimages/curl
${dockerCmd} pull
;;
"up"|"--up")
setRedisCrateHostMemory
stoppingServices
startingServices $2
displayServices
# WaitingDocker
# provisionDevices
;;
"down"|"--down")
stoppingServices
;;
"-rm"|"--remove")
read -p "This operation will ERASE ALL the Docker Volumes and ALL THE DATA stored in the database, continue (y/n)? " choice
case "$choice" in
y|Y|[yY][eE][sS] )
stoppingServices
echo "Deleting Volumens and Networks..."
deletingVolumesNetwork
;;
n|N|[nN][oO] )
echo "Continer removal skipped."
;;
* )
echo "Invalid selection."
echo "Continer removal skipped."
;;
esac
;;
"-d"|"--debug")
./services --down
./services --build
./services --build $2
sudo ./services --up $2
;;
*)
echo "Command not Found."
echo "$usage"
echo ""
exit 127;
;;
esac