forked from TableflippersAnonymous/v1x1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvcc
More file actions
executable file
·226 lines (203 loc) · 4.39 KB
/
vcc
File metadata and controls
executable file
·226 lines (203 loc) · 4.39 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
#!/usr/bin/env bash
getBoolAnswer() {
while true; do
read -p "$@ [y/n] " -n1
printf "\n" >&2
REPLY=$(echo $REPLY|tr [A-Z] [a-z])
if [ $REPLY == "y" -o $REPLY == "n" ]; then
echo $REPLY
return
fi
done
}
function yaml2json() {
ruby -ryaml -rjson -e 'puts JSON.pretty_generate(YAML.load(ARGF))' $*
}
function start() {
echo "Starting services..."
docker-compose up -d $@
}
function stop() {
echo "Stopping services..."
docker-compose stop $@
docker-compose rm -f $@
}
function clean() {
for module in $@; do
targets="v1x1-$module "
done
docker rmi $targets
}
function cleanAll() {
docker-compose down
clean $MODULES
}
function buildOne() {
local target=v1x1-modules/v1x1-modules-$2/v1x1-modules-$2-$1
V1X1_MAKE_TARGET="-pl v1x1-common,$target" V1X1_MAKE_ENV=dev make mvn-clean mvn-package
return $?
}
function buildAll() {
V1X1_MAKE_ENV=dev make mvn-clean mvn-package
return $?
}
function followLogs() {
docker-compose logs -f $@
}
function usage() {
echo "Usage: $0 <help|subcmd> [args]"
}
function help() {
cat <<EOM
$(usage)
Control the v1x1 dev environment
start [service[,service2...]] - start a service. Default: all of them
status - alias to docker-compose ps
logs [service[,service2...]] - follow logs for a service. Default: all of them
restart [service[,service2...]] - runs stop, then start
stop [service][,service2...]] - stop a service. Default: all of them
build [service [type]] - build a service; type is core/channel/global. Default: channel
cqlsh - gives you a cql prompt on your Cassandra container
rediscli - gives you a redis-cli prompt on your Redis container
encode [string] - encodes strings into a C* blob
help - new command, what dis
EOM
}
function checkCoreServices() {
if [ $(docker-compose ps|egrep 'v1x1_(cass|zoo|redis)_1'|wc -l) = 3 ]; then
echo "online"
else
echo "offline"
fi
}
function cmdBuild() {
if [ $# -eq 0 ]; then
if [ "$(getBoolAnswer "Stop and rebuild the entire dev environment?")" == "n" ]; then
echo "Aborting..."
exit 2
fi
cleanAll
buildAll
if [ $? -gt 0 ]; then
echo "Build failed :["
exit 1
fi
if [ "$(getBoolAnswer "Start new dev environment?")" == "y" ]; then
cmdStart
else
echo "Okay! Bye!"
fi
else
if [ $# -eq 1 ]; then
TYPE=channel
else
TYPE=$2
fi
stop $1
clean v1x1-common $1
buildOne $1 $TYPE
if [ $? -gt 0 ]; then
echo "Build failed :["
exit 1
fi
start $1
fi
}
function cmdStart() {
if [ $# -eq 0 ]; then
if [ "$(checkCoreServices)" == "offline" ]; then
start cass redis zoo
echo "Waiting for core services to start..."
sleep 45
fi
echo "Core services online..."
fi
start $@
}
function cmdStop() {
if [ $# -eq 0 ]; then
if [ "$(getBoolAnswer "Stop the entire dev environment?")" == "n" ]; then
echo "Aborting..."
exit 2
fi
fi
stop $@
}
if [ $# -lt 1 ]; then
usage
exit 1
fi
function cmdLogs() {
followLogs $@
}
function cmdCqlsh() {
local ID=$(docker ps -qf name=v1x1_cass_1 2> /dev/null)
if [ "x$ID" == "x" ]; then
echo "Cassandra container doesn't seem to be running"
else
docker exec -it v1x1_cass_1 cqlsh -k v1x1
exit $?
fi
}
function cmdRediscli() {
local ID=$(docker ps -qf name=v1x1_redis_1 2> /dev/null)
if [ "x$ID" == "x" ]; then
echo "Redis container doesn't seem to be running"
else
docker exec -it v1x1_redis_1 redis-cli
exit $?
fi
}
function cmdEncode() {
echo -n "0x"
echo -n "$@" | xxd -ps | xargs | sed -r 's/ //g'
}
echo "Finding services..."
while read module; do
MODULES="$MODULES $module"
done < <(yaml2json docker-compose.yml|jq -r '.services|keys|.[]' )
CMD=$(echo -n $1|tr [A-Z] [a-z])
shift 1
if [ $# -eq 0 ]; then
ARGS=$MODULES
else
ARGS=$@
fi
export COMPOSE_HTTP_TIMEOUT=120
case $CMD in
start)
cmdStart $@
;;
stop)
cmdStop $@
;;
restart)
cmdStop $@
cmdStart $@
;;
status)
docker-compose ps
;;
build)
cmdBuild $@
;;
cqlsh)
cmdCqlsh $@
;;
rediscli)
cmdRediscli $@
;;
logs)
cmdLogs $@
;;
encode)
cmdEncode $@
;;
help)
help
;;
*)
usage
;;
esac
exit 0