/
runLlapDaemon.sh
executable file
·144 lines (115 loc) · 4.84 KB
/
runLlapDaemon.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
#!/usr/bin/env bash
set -x
# 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.
# Environment Variables
# LLAP_DAEMON_HOME
# LLAP_DAEMON_USER_CLASSPATH
# LLAP_DAEMON_HEAPSIZE - MB
# LLAP_DAEMON_OPTS - additional options
# LLAP_DAEMON_LOG_LEVEL - default is INFO
# LLAP_DAEMON_LOGGER - default is console
# LLAP_DAEMON_LOG_DIR - defaults to /tmp
# LLAP_DAEMON_TMP_DIR - defaults to /tmp
# LLAP_LOG4J2_PROPERTIES_FILE_NAME - defaults to llap-daemon-log4j2.properties
# LLAP_DAEMON_LOG_FILE -
# LLAP_DAEMON_CONF_DIR
function print_usage() {
echo "Usage: llap-daemon.sh [COMMAND]"
echo "Commands: "
echo " classpath print classpath"
echo " run run the daemon"
}
# if no args specified, show usage
if [ $# = 0 ]; then
print_usage
exit 1
fi
# get arguments
COMMAND=$1
shift
JAVA=$JAVA_HOME/bin/java
LOG_LEVEL_DEFAULT="INFO"
LOGGER_DEFAULT="console"
JAVA_VERSION=$($JAVA -version 2>&1 | grep -i version | cut -d'"' -f2 | cut -d'.' -f1) # returns "1", "9", "11" for jdk 8,9,11 respectively
JAVA_GC_OPTS="-XX:+PrintGCDetails -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=4 -XX:GCLogFileSize=100M -XX:+PrintGCDateStamps"
if [ "$JAVA_VERSION" -gt "1" ]; then # from java9+, -Xlog argument should be used
JAVA_GC_OPTS="-Xlog:gc*,safepoint:gc.log:time,uptime:filecount=4,filesize=100M"
fi
JAVA_OPTS_BASE="-server -Djava.net.preferIPv4Stack=true -XX:+UseNUMA -verbose:gc $JAVA_GC_OPTS"
if [ ! -d "${LLAP_DAEMON_HOME}" ]; then
echo No LLAP_DAEMON_HOME set, or is not a directory.
echo Please specify it in the environment.
exit 1
fi
if [ ! -d "${LLAP_DAEMON_CONF_DIR}" ]; then
echo No LLAP_DAEMON_CONF_DIR set, or is not a directory.
echo Please specify it in the environment.
exit 1
fi
if [ ! -n "${LLAP_DAEMON_LOGGER}" ]; then
echo "LLAP_DAEMON_LOGGER not defined... using default: ${LOGGER_DEFAULT}"
LLAP_DAEMON_LOGGER=${LOGGER_DEFAULT}
fi
if [ ! -n "${LLAP_DAEMON_LOG_LEVEL}" ]; then
echo "LLAP_DAEMON_LOG_LEVEL not defined... using default: ${LOG_LEVEL_DEFAULT}"
LLAP_DAEMON_LOG_LEVEL=${LOG_LEVEL_DEFAULT}
fi
CLASSPATH=${LLAP_DAEMON_CONF_DIR}:${LLAP_DAEMON_HOME}/lib/*:${LLAP_DAEMON_HOME}/lib/tez/*:${LLAP_DAEMON_HOME}/lib/udfs/*:.
if [ -n "LLAP_DAEMON_USER_CLASSPATH" ]; then
CLASSPATH=${CLASSPATH}:${LLAP_DAEMON_USER_CLASSPATH}
fi
if [ ! -n "${LLAP_DAEMON_LOG_DIR}" ]; then
echo "LLAP_DAEMON_LOG_DIR not defined. Using default"
LLAP_DAEMON_LOG_DIR="/tmp/llapDaemonLogs"
fi
if [ "$LLAP_DAEMON_LOGFILE" = "" ]; then
LLAP_DAEMON_LOG_FILE='llapdaemon.log'
fi
if [ "LLAP_LOG4J2_PROPERTIES_FILE_NAME" = "" ]; then
LLAP_LOG4J2_PROPERTIES_FILE_NAME='llap-daemon-log4j2.properties'
fi
if [ "$LLAP_DAEMON_HEAPSIZE" = "" ]; then
LLAP_DAEMON_HEAPSIZE=4096
fi
if [ -n "$LLAP_DAEMON_LD_PATH" ]; then
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$LLAP_DAEMON_LD_PATH
fi
# Figure out classes based on the command
if [ "$COMMAND" = "classpath" ] ; then
echo $CLASSPATH
exit
elif [ "$COMMAND" = "run" ] ; then
CLASS='org.apache.hadoop.hive.llap.daemon.impl.LlapDaemon'
fi
JAVA_OPTS_BASE="${JAVA_OPTS_BASE} -Xloggc:${LLAP_DAEMON_LOG_DIR}/gc_$(date +%Y-%m-%d-%H).log"
LLAP_DAEMON_OPTS="${LLAP_DAEMON_OPTS} ${JAVA_OPTS_BASE}"
# Set the default GC option if none set
if [[ ! "$LLAP_DAEMON_OPTS" =~ \+Use[^[:space:]]+GC ]]
then
LLAP_DAEMON_OPTS="${LLAP_DAEMON_OPTS} -XX:+UseParallelGC"
fi
# In general, avoid using the OS temporary directory
if [ -n "$LLAP_DAEMON_TMP_DIR" ]; then
export LLAP_DAEMON_OPTS="${LLAP_DAEMON_OPTS} -Djava.io.tmpdir=$LLAP_DAEMON_TMP_DIR"
fi
LLAP_DAEMON_OPTS="${LLAP_DAEMON_OPTS} -Dlog4j.configurationFile=${LLAP_LOG4J2_PROPERTIES_FILE_NAME}"
LLAP_DAEMON_OPTS="${LLAP_DAEMON_OPTS} -Dllap.daemon.log.dir=${LLAP_DAEMON_LOG_DIR}"
LLAP_DAEMON_OPTS="${LLAP_DAEMON_OPTS} -Dllap.daemon.log.file=${LLAP_DAEMON_LOG_FILE}"
LLAP_DAEMON_OPTS="${LLAP_DAEMON_OPTS} -Dllap.daemon.root.logger=${LLAP_DAEMON_LOGGER}"
LLAP_DAEMON_OPTS="${LLAP_DAEMON_OPTS} -Dllap.daemon.log.level=${LLAP_DAEMON_LOG_LEVEL}"
export MALLOC_ARENA_MAX=4
export JVM_PID="$$"
exec "$JAVA" -Dproc_llapdaemon -Xms$(( ${LLAP_DAEMON_HEAPSIZE} / 2 ))m -Xmx${LLAP_DAEMON_HEAPSIZE}m ${LLAP_DAEMON_OPTS} -classpath "$CLASSPATH" $CLASS "$@"