-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathinfispector.sh
executable file
·196 lines (176 loc) · 4.29 KB
/
infispector.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
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
#!/bin/bash
cleanUp() {
pkill -f druid -e
pkill -f kafka -e
pkill -f zookeeper -e
pkill -f grunt -e
}
#colors
NC='\033[0m'
WHITE='\033[1;37m'
GREEN='\033[0;32m'
RED='\033[0;31m'
if [ "$#" -eq "0" ] || [ $1 == "help" ]
then
printf "
_____ __ _ _
|_ _| / _|(_) | |
| | _ __ | |_ _ ___ _ __ ___ ___ | |_ ___ _ __
| | | '_ \ | _|| |/ __|| '_ \ / _ \ / __|| __| / _ \ | '__|
_| |_ | | | || | | |\__ \| |_) || __/| (__ | |_ | (_) || |
|_____||_| |_||_| |_||___/| .__/ \___| \___| \__| \___/ |_|
| |
|_|
commands:
${GREEN}infispector${NC} or ${GREEN}infispector help${NC} - prints this help
${GREEN}infispector prepare${NC} - starts dependecies (zookeeper, kafka, druid)
${GREEN}infispector start${NC} - starts application
${GREEN}infispector stop${NC} - stops infispector
${GREEN}infispector nodes${NC} - starts 4 instances
${GREEN}infispector nodes ${RED}NUMBER${NC} - starts specified ${RED}NUMBER${NC} of instances
"
exit 0
fi
#paths
DRUID_LOCATION=`find /home -type d -name druid-0.8.3 2> /dev/null`
KAFKA_LOCATION=`find /home -type d -name kafka_2.10-0.8.2.0 2> /dev/null`
INFISPECTOR_LOCATION=`find /home -type d -iname infispector 2> /dev/null | awk '{ print length, $0 }' | sort -n -s | head -n1 | cut -f 2 -d ' '`
DEFAULT="4"
NUMBER_CHECK='^[0-9]+$'
cnt="0"
TIMEOUT="0"
if [ -z $DRUID_LOCATION ]
then
printf "Druid not found. Druid must be in /home/* directory\n" >&2
exit 1
fi
if [ -z $KAFKA_LOCATION ]
then
printf "Kafka not found. Kafka must be in /home/* directory\n" >&2
exit 1
fi
if [ -z $INFISPECTOR_LOCATION ]
then
printf "Infispector not found. Infispector must be in /home/* directory\n" >&2
exit 1
fi
if [ $EUID -eq 0 ]
then
printf "Please, run this as a ${WHITE}normal${NC} user, not root.\n" >$2
exit 1
fi
if [ "$#" -gt "2" ] || { [ "$#" -eq "2" ] && [ "$1" != "nodes" ]; }
#if [ \( "$#" -gt "2" \) -o \( "$g" "$#" -eq "2" -a "$1" -ne "nodes" \) ]
then
printf "Invalid number of arguments!\n" >$2
exit 1
fi
if [ $1 == "prepare" ]
then
cd $KAFKA_LOCATION
printf "Starting zookeeper ...."
bin/zookeeper-server-start.sh config/zookeeper.properties > /dev/null &
sleep 1
if [ $? -ne 0 ]
then
printf " ${RED}FAIL${NC}\n"
cleanUp
exit 1
else
printf " ${GREEN}OK${NC}\n"
fi
printf "Starting kafka ...."
bin/kafka-server-start.sh config/server.properties > /dev/null &
sleep 1
if [ $? -ne 0 ]
then
printf " ${RED}FAIL${NC}\n"
cleanUp
exit 1
else
printf " ${GREEN}OK${NC}\n"
fi
cd $DRUID_LOCATION
printf "Starting druid ...."
java -Xmx512m -Duser.timezone=UTC -Dfile.encoding=UTF-8 -Ddruid.realtime.specFile=$INFISPECTOR_LOCATION/kafka_druid_infrastructure/infispectorDruid.spec -classpath "config/_common:config/realtime:lib/*" io.druid.cli.Main server realtime > log.txt 2> log_err.txt &
if echo $INFISPECTOR_LOCATION | grep travis > /dev/null
then
sleep 10
fi
sleep 2
while true
do
if cat log.txt | grep "Firehose acquired!" > /dev/null
then
break
fi
if [ $TIMEOUT -eq "20" ]
then
printf " ${RED}FAIL${NC}\n"
cleanUp
exit 1
fi
TIMEOUT=$[$TIMEOUT + 1]
sleep 1
done
printf " ${GREEN}OK${NC}\n"
printf "Infispector is ready to be started!\n"
exit 0
fi
if [ $1 == "start" ]
then
cd $INFISPECTOR_LOCATION
grunt
exit 0
fi
if [ $1 == "stop" ]
then
cleanUp
exit 0
fi
if [ $1 == "nodes" ]
then
cd $INFISPECTOR_LOCATION/infinispan_example_app
if ! [[ -z "$2" ]]
then
if ! [[ $2 =~ $NUMBER_CHECK ]]
then
printf "Second argument must be a number\n" >&2
exit 1
fi
DEFAULT=$2
if [ $DEFAULT -ge "10" ]
then
while true;
do
read -p "Are you sure you want to start ${DEFAULT} instances? [y/n] " yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit 0;;
*) echo "Please answer y or n.";;
esac
done
fi
fi
printf "Starting $DEFAULT nodes ...."
while [ $cnt -ne $DEFAULT ]
do
if [ $cnt -eq $[$DEFAULT - 1] ]
then
mvn exec:exec > /dev/null
else
nohup mvn exec:exec > /dev/null 2> /dev/null &
fi
cnt=$[$cnt + 1]
done
if [ $? -eq 0 ]
then
printf " ${GREEN}OK${NC}\n"
exit 0
else
printf " ${RED}FAIL${NC}\n"
exit 1
fi
fi
printf "Invalid argument!\n" >&2
exit 1