-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
kylin.sh
executable file
·427 lines (373 loc) · 15.1 KB
/
kylin.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
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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
#!/bin/bash
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# set verbose=true to print more logs during start up
source ${KYLIN_HOME:-"$(cd -P -- "$(dirname -- "$0")" && pwd -P)/../"}/bin/header.sh $@
if [ "$verbose" = true ]; then
shift
fi
mkdir -p ${KYLIN_HOME}/logs
mkdir -p ${KYLIN_HOME}/ext
source ${dir}/set-java-home.sh
function retrieveDependency() {
source ${dir}/find-hive-dependency.sh
source ${dir}/find-hbase-dependency.sh
source ${dir}/find-hadoop-conf-dir.sh
source ${dir}/find-kafka-dependency.sh
source ${dir}/find-spark-dependency.sh
source ${dir}/find-flink-dependency.sh
#retrive $KYLIN_EXTRA_START_OPTS
if [ -f "${dir}/setenv.sh" ]; then
echo "WARNING: ${dir}/setenv.sh is deprecated and ignored, please remove it and use ${KYLIN_HOME}/conf/setenv.sh instead"
source ${dir}/setenv.sh
fi
if [ -f "${KYLIN_HOME}/conf/setenv.sh" ]; then
source ${KYLIN_HOME}/conf/setenv.sh
fi
export HBASE_CLASSPATH_PREFIX=${KYLIN_HOME}/conf:${KYLIN_HOME}/lib/*:${KYLIN_HOME}/ext/*:${HBASE_CLASSPATH_PREFIX}
export HBASE_CLASSPATH=${HBASE_CLASSPATH}:${hive_dependency}:${kafka_dependency}:${spark_dependency}:${flink_dependency}
verbose "HBASE_CLASSPATH: ${HBASE_CLASSPATH}"
}
function retrieveStartCommand() {
if [ -f "${KYLIN_HOME}/pid" ]
then
PID=`cat $KYLIN_HOME/pid`
if ps -p $PID > /dev/null
then
quit "Kylin is running, stop it first"
fi
fi
lockfile=$KYLIN_HOME/LOCK
if [ ! -e $lockfile ]; then
trap "rm -f $lockfile; exit" INT TERM EXIT
touch $lockfile
else
quit "Kylin is starting, wait for it"
fi
source ${dir}/check-env.sh
tomcat_root=${dir}/../tomcat
export tomcat_root
#The location of all hadoop/hbase configurations are difficult to get.
#Plus, some of the system properties are secretly set in hadoop/hbase shell command.
#For example, in hdp 2.2, there is a system property called hdp.version,
#which we cannot get until running hbase or hadoop shell command.
#
#To save all these troubles, we use hbase runjar to start tomcat.
#In this way we no longer need to explicitly configure hadoop/hbase related classpath for tomcat,
#hbase command will do all the dirty tasks for us:
spring_profile=`bash ${dir}/get-properties.sh kylin.security.profile`
if [ -z "$spring_profile" ]
then
quit 'Please set kylin.security.profile in kylin.properties, options are: testing, ldap, saml.'
else
verbose "kylin.security.profile is set to $spring_profile"
fi
# the number of Spring active profiles can be greater than 1. Additional profiles
# can be added by setting kylin.security.additional-profiles
additional_security_profiles=`bash ${dir}/get-properties.sh kylin.security.additional-profiles`
if [[ "x${additional_security_profiles}" != "x" ]]; then
spring_profile="${spring_profile},${additional_security_profiles}"
fi
retrieveDependency
#additionally add tomcat libs to HBASE_CLASSPATH_PREFIX
export HBASE_CLASSPATH_PREFIX=${tomcat_root}/bin/bootstrap.jar:${tomcat_root}/bin/tomcat-juli.jar:${tomcat_root}/lib/*:${HBASE_CLASSPATH_PREFIX}
kylin_rest_address=`hostname -f`":"`grep "<Connector port=" ${tomcat_root}/conf/server.xml |grep protocol=\"HTTP/1.1\" | cut -d '=' -f 2 | cut -d \" -f 2`
kylin_rest_address_arr=(${kylin_rest_address//;/ })
nc -z -w 5 ${kylin_rest_address_arr[0]} ${kylin_rest_address_arr[1]} 1>/dev/null 2>&1; nc_result=$?
if [ $nc_result -eq 0 ]; then
quit "Port ${kylin_rest_address} is not available, could not start Kylin."
fi
${KYLIN_HOME}/bin/check-migration-acl.sh || { exit 1; }
#debug if encounter NoClassDefError
verbose "kylin classpath is: $(hbase classpath)"
security_ldap_truststore=`bash ${dir}/get-properties.sh kylin.security.ldap.connection-truststore`
if [ -f "${security_ldap_truststore}" ]; then
KYLIN_EXTRA_START_OPTS="$KYLIN_EXTRA_START_OPTS -Djavax.net.ssl.trustStore=$security_ldap_truststore"
fi
# KYLIN_EXTRA_START_OPTS is for customized settings, checkout bin/setenv.sh
start_command="hbase ${KYLIN_EXTRA_START_OPTS} \
-Djava.util.logging.config.file=${tomcat_root}/conf/logging.properties \
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager \
-Dlog4j.configuration=file:${KYLIN_HOME}/conf/kylin-server-log4j.properties \
-Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true \
-Dorg.apache.catalina.connector.CoyoteAdapter.ALLOW_BACKSLASH=true \
-Djava.endorsed.dirs=${tomcat_root}/endorsed \
-Dcatalina.base=${tomcat_root} \
-Dcatalina.home=${tomcat_root} \
-Djava.io.tmpdir=${tomcat_root}/temp \
-Dkylin.hive.dependency=${hive_dependency} \
-Dkylin.hbase.dependency=${hbase_dependency} \
-Dkylin.kafka.dependency=${kafka_dependency} \
-Dkylin.spark.dependency=${spark_dependency} \
-Dkylin.flink.dependency=${flink_dependency} \
-Dkylin.hadoop.conf.dir=${kylin_hadoop_conf_dir} \
-Dkylin.server.host-address=${kylin_rest_address} \
-Dkylin.source.hive.warehouse-dir=${hive_warehouse_dir} \
-Dspring.profiles.active=${spring_profile} \
org.apache.hadoop.util.RunJar ${tomcat_root}/bin/bootstrap.jar org.apache.catalina.startup.Bootstrap start"
}
function retrieveStopCommand() {
if [ -f "${KYLIN_HOME}/pid" ]
then
PID=`cat $KYLIN_HOME/pid`
WAIT_TIME=2
LOOP_COUNTER=10
if ps -p $PID > /dev/null
then
echo "Stopping Kylin: $PID"
kill $PID
for ((i=0; i<$LOOP_COUNTER; i++))
do
# wait to process stopped
sleep $WAIT_TIME
if ps -p $PID > /dev/null ; then
echo "Stopping in progress. Will check after $WAIT_TIME secs again..."
continue;
else
break;
fi
done
# if process is still around, use kill -9
if ps -p $PID > /dev/null
then
echo "Initial kill failed, getting serious now..."
kill -9 $PID
sleep 1 #give kill -9 sometime to "kill"
if ps -p $PID > /dev/null
then
quit "Warning, even kill -9 failed, giving up! Sorry..."
fi
fi
# process is killed , remove pid file
rm -rf ${KYLIN_HOME}/pid
echo "Kylin with pid ${PID} has been stopped."
return 0
else
echo "Kylin with pid ${PID} is not running"
return 1
fi
else
return 1
fi
}
if [ "$2" == "--reload-dependency" ]
then
reload_dependency=1
fi
# start command
if [ "$1" == "start" ]
then
retrieveStartCommand
${start_command} >> ${KYLIN_HOME}/logs/kylin.out 2>&1 & echo $! > ${KYLIN_HOME}/pid &
rm -f $lockfile
echo ""
echo "A new Kylin instance is started by $USER. To stop it, run 'kylin.sh stop'"
echo "Check the log at ${KYLIN_HOME}/logs/kylin.log"
echo "Web UI is at http://${kylin_rest_address_arr}/kylin"
exit 0
# run command
elif [ "$1" == "run" ]
then
retrieveStartCommand
${start_command}
rm -f $lockfile
# stop command
elif [ "$1" == "stop" ]
then
retrieveStopCommand
if [[ $? == 0 ]]
then
exit 0
else
quit "Kylin is not running"
fi
# restart command
elif [ "$1" == "restart" ]
then
echo "Restarting kylin..."
echo "--> Stopping kylin first if it's running..."
retrieveStopCommand
if [[ $? != 0 ]]
then
echo "Kylin is not running, now start it"
fi
echo "--> Start kylin..."
retrieveStartCommand
${start_command} >> ${KYLIN_HOME}/logs/kylin.out 2>&1 & echo $! > ${KYLIN_HOME}/pid &
rm -f $lockfile
echo ""
echo "A new Kylin instance is started by $USER. To stop it, run 'kylin.sh stop'"
echo "Check the log at ${KYLIN_HOME}/logs/kylin.log"
echo "Web UI is at http://${kylin_rest_address_arr}/kylin"
exit 0
# streaming command
elif [ "$1" == "streaming" ]
then
if [ $# -lt 2 ]
then
echo "Invalid input args $@"
exit -1
fi
if [ "$2" == "start" ]
then
if [ -f "${KYLIN_HOME}/streaming_receiver_pid" ]
then
PID=`cat $KYLIN_HOME/streaming_receiver_pid`
if ps -p $PID > /dev/null
then
echo "Kylin streaming receiver is running, stop it first"
exit 1
fi
fi
#retrive $hbase_dependency
source ${dir}/find-hbase-dependency.sh
#retrive $KYLIN_EXTRA_START_OPTS
if [ -f "${KYLIN_HOME}/conf/setenv.sh" ]
then source ${KYLIN_HOME}/conf/setenv.sh
fi
mkdir -p ${KYLIN_HOME}/ext
HBASE_CLASSPATH=`hbase classpath`
#echo "hbase class path:"$HBASE_CLASSPATH
STREAM_CLASSPATH=${KYLIN_HOME}/lib/streaming/*:${KYLIN_HOME}/ext/*:${HBASE_CLASSPATH}
# KYLIN_EXTRA_START_OPTS is for customized settings, checkout bin/setenv.sh
${JAVA_HOME}/bin/java -cp $STREAM_CLASSPATH ${KYLIN_EXTRA_START_OPTS} \
-Dlog4j.configuration=file:${KYLIN_HOME}/conf/stream-receiver-log4j.properties\
-DKYLIN_HOME=${KYLIN_HOME}\
-Dkylin.hbase.dependency=${hbase_dependency} \
org.apache.kylin.stream.server.StreamingReceiver $@ > ${KYLIN_HOME}/logs/streaming_receiver.out 2>&1 & echo $! > ${KYLIN_HOME}/streaming_receiver_pid &
exit 0
elif [ "$2" == "run" ]
then
if [ -f "${KYLIN_HOME}/streaming_receiver_pid" ]
then
PID=`cat $KYLIN_HOME/streaming_receiver_pid`
if ps -p $PID > /dev/null
then
echo "Kylin is running, stop it first"
exit 1
fi
fi
#retrive $hbase_dependency
source ${dir}/find-hbase-dependency.sh
#retrive $KYLIN_EXTRA_START_OPTS
if [ -f "${KYLIN_HOME}/conf/setenv.sh" ]
then source ${KYLIN_HOME}/conf/setenv.sh
fi
mkdir -p ${KYLIN_HOME}/ext
HBASE_CLASSPATH=`hbase classpath`
#echo "hbase class path:"$HBASE_CLASSPATH
STREAM_CLASSPATH=${KYLIN_HOME}/lib/streaming/*:${KYLIN_HOME}/ext/*:${HBASE_CLASSPATH}
# KYLIN_EXTRA_START_OPTS is for customized settings, checkout bin/setenv.sh
${JAVA_HOME}/bin/java -cp $STREAM_CLASSPATH ${KYLIN_EXTRA_START_OPTS} \
-Dlog4j.configuration=file:${KYLIN_HOME}/conf/stream-receiver-log4j.properties\
-DKYLIN_HOME=${KYLIN_HOME}\
-Dkylin.hbase.dependency=${hbase_dependency} \
org.apache.kylin.stream.server.StreamingReceiver $@
exit 0
elif [ "$2" == "stop" ]
then
if [ ! -f "${KYLIN_HOME}/streaming_receiver_pid" ]
then
echo "Streaming receiver is not running, please check"
exit 1
fi
PID=`cat ${KYLIN_HOME}/streaming_receiver_pid`
if [ "$PID" = "" ]
then
echo "Streaming receiver is not running, please check"
exit 1
else
echo "Stopping streaming receiver: $PID"
WAIT_TIME=2
LOOP_COUNTER=20
if ps -p $PID > /dev/null
then
kill $PID
for ((i=0; i<$LOOP_COUNTER; i++))
do
# wait to process stopped
sleep $WAIT_TIME
if ps -p $PID > /dev/null ; then
echo "Stopping in progress. Will check after $WAIT_TIME secs again..."
continue;
else
break;
fi
done
# if process is still around, use kill -9
if ps -p $PID > /dev/null
then
echo "Initial kill failed, getting serious now..."
kill -9 $PID
sleep 1 #give kill -9 sometime to "kill"
if ps -p $PID > /dev/null
then
quit "Warning, even kill -9 failed, giving up! Sorry..."
fi
fi
# process is killed , remove pid file
rm -rf ${KYLIN_HOME}/streaming_receiver_pid
echo "Kylin streaming receiver with pid ${PID} has been stopped."
exit 0
else
quit "Kylin streaming receiver with pid ${PID} is not running"
fi
fi
elif [[ "$2" = org.apache.kylin.* ]]
then
source ${KYLIN_HOME}/conf/setenv.sh
HBASE_CLASSPATH=`hbase classpath`
#echo "hbase class path:"$HBASE_CLASSPATH
STREAM_CLASSPATH=${KYLIN_HOME}/lib/streaming/*:${KYLIN_HOME}/ext/*:${HBASE_CLASSPATH}
shift
# KYLIN_EXTRA_START_OPTS is for customized settings, checkout bin/setenv.sh
${JAVA_HOME}/bin/java -cp $STREAM_CLASSPATH ${KYLIN_EXTRA_START_OPTS} \
-Dlog4j.configuration=file:${KYLIN_HOME}/conf/stream-receiver-log4j.properties\
-DKYLIN_HOME=${KYLIN_HOME}\
-Dkylin.hbase.dependency=${hbase_dependency} \
"$@"
exit 0
fi
elif [ "$1" = "version" ]
then
retrieveDependency
exec hbase -Dlog4j.configuration=file:${KYLIN_HOME}/conf/kylin-tools-log4j.properties org.apache.kylin.common.KylinVersion
exit 0
elif [ "$1" = "diag" ]
then
echo "'kylin.sh diag' no longer supported, use diag.sh instead"
exit 0
# tool command
elif [[ "$1" = org.apache.kylin.* ]]
then
retrieveDependency
#retrive $KYLIN_EXTRA_START_OPTS from a separate file called setenv-tool.sh
unset KYLIN_EXTRA_START_OPTS # unset the global server setenv config first
if [ -f "${dir}/setenv-tool.sh" ]; then
echo "WARNING: ${dir}/setenv-tool.sh is deprecated and ignored, please remove it and use ${KYLIN_HOME}/conf/setenv-tool.sh instead"
source ${dir}/setenv-tool.sh
fi
if [ -f "${KYLIN_HOME}/conf/setenv-tool.sh" ]; then
source ${KYLIN_HOME}/conf/setenv-tool.sh
fi
hbase_pre_original=${HBASE_CLASSPATH_PREFIX}
export HBASE_CLASSPATH_PREFIX=${KYLIN_HOME}/tool/*:${HBASE_CLASSPATH_PREFIX}
exec hbase ${KYLIN_EXTRA_START_OPTS} -Dkylin.hive.dependency=${hive_dependency} -Dkylin.hbase.dependency=${hbase_dependency} -Dlog4j.configuration=file:${KYLIN_HOME}/conf/kylin-tools-log4j.properties "$@"
export HBASE_CLASSPATH_PREFIX=${hbase_pre_original}
else
quit "Usage: 'kylin.sh [-v] start' or 'kylin.sh [-v] stop' or 'kylin.sh [-v] restart'"
fi