-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathstop.sh
executable file
·116 lines (97 loc) · 2.71 KB
/
stop.sh
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
#!/bin/bash
usage () {
/bin/echo "Usage: $0 [-c|w]"
/bin/echo " -c remove containers and downloaded dump files and mysql database"
/bin/echo " -w remove containers and mysql database, preserve downloaded dump files"
exit 2
}
clean_up () {
echo " "
echo "Removing docker containers"
docker-compose $compose_files down
# remove the dump files if -c option
if [ $cleanup -eq 1 ]; then
if [ -f $data_dir/$mysql_file ] ; then
echo " "
echo "Removing mysql dump file"
rm "$data_dir/$mysql_file"
fi
# download may sometimes fail and create a directory
if [ -d $data_dir/$mysql_file ] ; then
echo " "
echo "Removing mysql dump file"
rmdir "$data_dir/$mysql_file"
fi
for blazegraph_file in $blazegraph_models; do
if [ -f $data_dir/$blazegraph_file ] ; then
echo " "
echo "Removing blazegraph import file $blazegraph_file"
rm "$data_dir/$blazegraph_file"
fi
# download may sometimes fail and create a directory
if [ -d $data_dir/$blazegraph_file ] ; then
echo " "
echo "Removing blazegraph import file $blazegraph_file"
rmdir "$data_dir/$blazegraph_file"
fi
done
fi
if [ -f .env ] ; then
echo " "
echo "Removing the docker .env file"
rm .env
fi
if [ -f conf/viz.config ] ; then
echo " "
echo "Removing the remote viz configuration file"
rm conf/viz.config
fi
if [ -f docker-compose.d/viz.yml ] ; then
echo " "
echo "Removing the remote viz compose file"
rm docker-compose.d/viz.yml
fi
for dbdir in $database_dirs; do
if [ -d $dbdir ] ; then
echo " "
if [ -O $dbdir ] ; then
echo "Removing $dbdir database files"
rm -r $dbdir
else
echo "Error: unable to remove $dbdir, please run the following command."
echo "sudo rm -r $dbdir"
fi
fi
done
}
blazegraph_models="EPRI_DPV_J1.xml IEEE123.xml R2_12_47_2.xml IEEE8500.xml ieee8500.xml"
mysql_file="gridappsd_mysql_dump.sql"
data_dir="dumps"
cleanup=0
database_dirs="gridappsdmysql gridappsd"
compose_files=$( ls -1 docker-compose.d/*yml 2>/dev/null | sed -e 's/^/-f /g' | tr '\n' ' ' )
compose_files="-f docker-compose.yml $compose_files"
echo "Compose files: $compose_files"
# parse options
while getopts cw option ; do
case $option in
c) # Cleanup downloads and containers and dump files
cleanup=1
;;
w) # Cleanup downloads and containers
cleanup=2
;;
*) # Print Usage
usage
;;
esac
done
shift `expr $OPTIND - 1`
echo " "
echo "Shutting down the docker containers"
docker-compose $compose_files stop
if [ $cleanup -gt 0 ]; then
clean_up
fi
echo " "
exit 0