-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·350 lines (309 loc) · 9.06 KB
/
Copy pathrun.sh
File metadata and controls
executable file
·350 lines (309 loc) · 9.06 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
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
#!/bin/bash
# Source common utilities
source "$(dirname "$0")/utils.sh"
init_docker_compose
usage () {
/bin/echo "Usage: $0 [-c conf_dir] [-d] [-n] [-p] [-r [ip address]] [-s] [-t tag]"
/bin/echo " -c dir mount local directory at /conf in gridappsd container"
/bin/echo " -d debug"
/bin/echo " -n no auto-start, drop into container shell"
/bin/echo " -p pull updated containers"
/bin/echo " -r use remote ip address for viz, will use external ip if no address is supplied"
/bin/echo " -s services only mode (no gridappsd container, for local development)"
/bin/echo " -t tag specify gridappsd docker tag"
exit 2
}
create_env () {
if [ -f '.env' ]; then
prevtag=`grep GRIDAPPSD_TAG .env | sed 's/GRIDAPPSD_TAG=://'`
currtag=`echo $GRIDAPPSD_TAG | sed 's/://'`
if [ "$prevtag" != "$currtag" ]; then
echo " "
echo "Error changing tag from $prevtag to $currtag"
echo "Please run the stop.sh script with the -c option to remove "
echo "your existing containers before changing tags"
echo " ./stop.sh -c"
echo " "
echo "Exiting "
echo " "
#echo "Please remove previous versions by runing ./stop.sh -c"
exit 1
fi
else
echo " "
echo "Create the docker env file with the tag variables"
# Create the docker env file with the tag variables
cat > .env << EOF
# This file is auto generated, please change the tag with the run.sh -t option
GRIDAPPSD_TAG=$GRIDAPPSD_TAG
EOF
fi
}
configure_viz () {
echo " "
echo "Configuring remote viz $remote_ip"
url_viz="http://${remote_ip}:8080/"
if [[ $remote_ip =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
cat > conf/viz.config << EOF
{
"version": "remote$GRIDAPPSD_TAG",
"host": "$remote_ip:61614"
}
EOF
cat > docker-compose.d/viz.yml << EOF
version: '2'
services:
viz:
volumes:
- ./conf/viz.config:/gridappsd/viz/assets/config.json
EOF
else
echo "Error getting remote ip address"
exit 1
fi
}
debug_msg() {
msg=$1
if [ $debug == 1 ]; then
now=`date`
echo "DEBUG : $now : $msg"
fi
}
pull_containers() {
echo " "
echo "Pulling updated containers"
$DOCKER_COMPOSE_CMD $compose_files pull --ignore-pull-failures
}
http_status_container() {
cnt=$1
echo " "
echo "Getting $cnt status"
if [ "$cnt" == "blazegraph" ]; then
url=$url_blazegraph
elif [ "$cnt" == "viz" ]; then
url=$url_viz
fi
debug_msg "$cnt $url"
status="0"
count=0
maxcount=60
while [ $status -ne "200" -a $count -lt $maxcount ]
do
status=$(curl -s --head -w %{http_code} "$url" -o /dev/null)
debug_msg "curl status: $status"
sleep 1
count=`expr $count + 1`
done
debug_msg "tried $url $count times, max is $maxcount"
if [ $count -ge $maxcount ]; then
echo "Error contacting $url ($status)"
echo "Exiting "
echo " "
exit 1
fi
}
url_viz="http://localhost:8080/"
url_blazegraph="http://localhost:8889/bigdata/namespace/kb/"
mysql_file="$MYSQL_FILE"
data_dir="$DATA_DIR"
debug=0
exists=0
remote_ip=''
no_autostart=0
services_only=0
conf_dir=''
# set the default tag for the gridappsd and viz containers
GRIDAPPSD_TAG=':v2023.07.0'
# Clean up transient overrides from previous runs
rm -f docker-compose.d/conf-override.yml docker-compose.d/no-autostart.yml
# parse options
while getopts c:dnprst: option ; do
case $option in
c) # Custom conf directory mounted at /conf
conf_dir="$OPTARG"
;;
d) # enable debug output
debug=1
;;
n) # no auto-start, drop into container shell
no_autostart=1
;;
p) # pull updated containers
pull_containers
exit 0
;;
r) # Remote ip address
eval nextopt=\${$OPTIND}
if [[ -n $nextopt && $nextopt != -* ]]; then
OPTIND=$((OPTIND +1))
remote_ip="$nextopt"
else
remote_ip=$( curl -s ifconfig.me )
fi
;;
s) # Services only mode (no gridappsd container)
services_only=1
;;
t) # Pass gridappsd tag to docker-compose
GRIDAPPSD_TAG=":$OPTARG"
;;
*) # Print Usage
usage
;;
esac
done
shift `expr $OPTIND - 1`
[ -f '.env' ] && exists=1
create_env
#[ ! -z "$remote_ip" ] && configure_viz
# Set compose files based on mode
if [ $services_only -eq 1 ]; then
compose_files="-f docker-compose-services.yml"
else
compose_files=$(get_compose_files)
fi
# If -n flag is used, create override to disable auto-start
if [ $no_autostart -eq 1 ]; then
cat > docker-compose.d/no-autostart.yml << EOF
services:
gridappsd:
stdin_open: true
tty: true
environment:
- AUTOSTART=0
EOF
compose_files="$compose_files -f docker-compose.d/no-autostart.yml"
fi
# If -c flag is used, create override to mount custom conf directory at /conf
if [ -n "$conf_dir" ]; then
if [ ! -d "$conf_dir" ]; then
echo "Error: conf directory '$conf_dir' does not exist"
exit 1
fi
cat > docker-compose.d/conf-override.yml << EOF
services:
gridappsd:
volumes:
- ./${conf_dir}:/conf
EOF
compose_files="$compose_files -f docker-compose.d/conf-override.yml"
fi
echo "Compose files: $compose_files"
# Mysql
[ ! -d "$data_dir" ] && mkdir "$data_dir"
if [ ! -f "$data_dir/$mysql_file" ]; then
echo " "
echo "Downloading mysql data"
debug_msg "curl -s -o \"$data_dir/$mysql_file\" \"https://raw.githubusercontent.com/GRIDAPPSD/Bootstrap/master/$mysql_file\""
curl -s -o "$data_dir/$mysql_file" "https://raw.githubusercontent.com/GRIDAPPSD/Bootstrap/master/$mysql_file"
if [ -f $data_dir/$mysql_file ]; then
sed -i'.bak' -e "s/'gridappsd'@'localhost'/'gridappsd'@'%'/g" $data_dir/$mysql_file
# clean up
rm $data_dir/${mysql_file}.bak
else
echo "Error downloading $data_dir/$mysql_file"
echo "Exiting "
echo " "
exit 1
fi
fi
echo " "
echo "Getting blazegraph status"
status=$(curl -s --head -w %{http_code} "$url_blazegraph" -o /dev/null)
debug_msg "blazegraph curl status: $status"
pull_containers
echo " "
echo "Removing stale containers from previous runs"
$DOCKER_COMPOSE_CMD $compose_files down --remove-orphans 2>/dev/null
# Force remove containers by name in case they were orphaned from a different project
$DOCKER_COMPOSE_CMD $compose_files config 2>/dev/null | grep 'container_name:' | awk '{print $2}' | while read -r name; do
docker rm -f "$name" 2>/dev/null
done
echo " "
echo "Starting the docker containers"
echo " "
echo " "
$DOCKER_COMPOSE_CMD $compose_files up -d
container_status=$?
if [ $container_status -ne 0 ]; then
echo " "
echo "Error starting containers"
echo "Exiting "
echo " "
exit 1
fi
http_status_container 'blazegraph'
# sleep just a little longer to make sure blazegraph is ready to receive data.
sleep 3
bz_load_status=0
echo " "
echo "Checking blazegraph data"
echo " "
# Check if blazegraph data is already loaded
rangeCount=`curl -s -G -H 'Accept: application/xml' "${url_blazegraph}sparql" --data-urlencode ESTCARD | sed 's/.*rangeCount=\"\([0-9]*\)\".*/\1/'`
echo "Blazegrpah data available ($rangeCount)"
#http_status_container 'viz'
# echo " "
# echo "Opening web browser to the viz container $url_viz"
# if [ `uname` == "Linux" ]; then
# xdg-open $url_viz
# elif [ `uname` == "Darwin" ]; then
# open $url_viz
# else
# echo " "
# echo "Please open a browser to $url_viz"
# fi
echo " "
echo "Containers are running"
#echo "$url_viz"
# Handle different modes
if [ $services_only -eq 1 ]; then
echo " "
echo "Services-only mode: Supporting services are running."
echo " "
echo "Available endpoints:"
echo " Blazegraph: http://localhost:8889/bigdata/"
echo " MySQL: localhost:3306"
echo " Redis: localhost:6379"
echo " InfluxDB: http://localhost:8086"
echo " Proven: http://localhost:18080"
echo " "
echo "You can now start GridAPPS-D locally with embedded ActiveMQ."
echo " "
echo "To stop services:"
echo " ./stop.sh -s"
echo " "
elif [ $no_autostart -eq 1 ] && tty -s ; then
# Only drop into container shell if -n flag was used
# Try to get container ID from docker-compose ps, fall back to container name
gridappsd_container_id=$($DOCKER_COMPOSE_CMD $compose_files ps -q gridappsd 2>/dev/null)
if [ -z "$gridappsd_container_id" ]; then
# Fall back to using the container name directly
gridappsd_container="gridappsd"
else
gridappsd_container=$(docker inspect --format="{{.Name}}" "$gridappsd_container_id" | sed 's:^/::')
fi
echo " "
echo "Connecting to the gridappsd container"
echo "docker exec -it $gridappsd_container /bin/bash"
echo " "
docker exec -it $gridappsd_container /bin/bash
else
echo " "
echo "GridAPPS-D is starting automatically."
echo " "
echo "Available endpoints:"
echo " Web UI: http://localhost:8080/"
echo " Blazegraph: http://localhost:8889/bigdata/"
echo " STOMP: tcp://localhost:61613"
echo " WebSocket: ws://localhost:61614"
echo " OpenWire: tcp://localhost:61616"
echo " "
echo "To connect to the container:"
echo " docker exec -it gridappsd /bin/bash"
echo " "
echo "To view logs:"
echo " docker logs -f gridappsd"
echo " "
fi
exit 0