forked from apache/phoenix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtephra
executable file
·310 lines (267 loc) · 6.73 KB
/
tephra
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
#!/bin/sh
#
# Copyright © 2014 Cask Data, Inc.
#
# Licensed 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.
#
# Source function library. used for "status" use case
if [ -f "/etc/rc.d/init.d/functions" ]; then
PLATFORM="RHEL"
. /etc/rc.d/init.d/functions
elif [ -f /lib/lsb/init-functions ] ; then
PLATFORM="UBUNTU"
. /lib/lsb/init-functions
else
PLATFORM="UNSUPPORTED"
fi
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
bin=`dirname "${BASH_SOURCE-$0}"`
bin=`cd "$bin"; pwd`
lib="$bin"/../lib
conf="$bin"/../conf
script=`basename $0`
# Resolve relative symlinks
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/.."
APP_HOME="`pwd -P`"
APP=`basename $0`
# Load component common environment file too
. $bin/tephra-env.sh
pid=$PID_DIR/tephra-service-${IDENT_STRING}.pid
# In other environment, the jars are expected to be in <HOME>/lib directory.
# Load all the jar files. Not ideal, but we need to load only the things that
# is needed by this script.
if [ "$CLASSPATH" = "" ]; then
CLASSPATH=${lib}/*
else
CLASSPATH=$CLASSPATH:${lib}/*
fi
# Load the configuration too.
if [ -d "$conf" ]; then
CLASSPATH=$CLASSPATH:"$conf"/
fi
# Set Log location
if [ ! -e $LOG_DIR ]; then
mkdir -p $LOG_DIR;
fi
export LOG_PREFIX="tephra-service-$IDENT_STRING-$HOSTNAME"
export LOGFILE=$LOG_PREFIX.log
loglog="${LOG_DIR}/${LOGFILE}"
# set the classpath to include hadoop and hbase dependencies
set_classpath()
{
COMP_HOME=$1
if [ -n "$HBASE_HOME" ]; then
HBASE_CP=`$HBASE_HOME/bin/hbase classpath`
elif [ `which hbase` ]; then
HBASE_CP=`hbase classpath`
fi
export HBASE_CP
if [ -n "$HBASE_CP" ]; then
CP=$COMP_HOME/phoenix-client/target/*:$HBASE_CP:$EXTRA_CLASSPATH
else
# assume Hadoop/HBase libs are included via EXTRA_CLASSPATH
echo "WARN: could not find Hadoop and HBase libraries"
CP=$COMP_HOME/phoenix-client/target/*:$EXTRA_CLASSPATH
fi
# Setup classpaths.
if [ -n "$CLASSPATH" ]; then
CLASSPATH=$CLASSPATH:$CP
else
CLASSPATH=$CP
fi
export CLASSPATH
}
# Attempts to find JAVA in few ways.
set_java ()
{
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
export JAVA="$JAVA_HOME/jre/sh/java"
else
export JAVA="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVA" ] ; then
echo "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation." >&2
exit 1
fi
else
export JAVA="java"
which java >/dev/null 2>&1 || { echo "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation." >&2 ; exit 1; }
fi
}
# checks if there exists a PID that is already running. return 0 idempotently
check_before_start()
{
if [ ! -d "$PID_DIR" ]; then
mkdir -p "$PID_DIR"
fi
if [ -f $pid ]; then
if kill -0 `cat $pid` > /dev/null 2>&1; then
#echo "$APP $SERVICE running as process `cat $pid`. Stop it first."
echo "$APP running as process `cat $pid`. Stop it first."
exit 0
fi
fi
}
# Set Niceness
if [ "$NICENESS" = "" ]; then
export NICENESS=0
fi
start() {
# Setup classpaths.
set_classpath $APP_HOME
# sets the JAVA variable.
set_java
check_before_start
echo "`date` Starting $APP service on `hostname`"
echo "`date` Starting $APP service on `hostname`" >> $loglog
echo "`ulimit -a`" >> $loglog 2>&1
export MAIN_CLASS="org.apache.tephra.TransactionServiceMain"
echo "Running class $MAIN_CLASS"
echo "Command: " "$JAVA" $OPTS -cp $CLASSPATH $JAVA_HEAPMAX $MAIN_CLASS >>$loglog
nohup nice -n $NICENESS "$JAVA" $OPTS -cp $CLASSPATH $JAVA_HEAPMAX ${MAIN_CLASS} </dev/null >>$loglog 2>&1 &
echo $! >$pid
}
stop() {
if [ -f $pid ]; then
pidToKill=`cat $pid`
# kill -0 == see if the PID exists
if kill -0 $pidToKill > /dev/null 2>&1; then
echo -n stopping $command
echo "`date` Terminating $command" >> $loglog
kill $pidToKill > /dev/null 2>&1
while kill -0 $pidToKill > /dev/null 2>&1;
do
echo -n "."
sleep 1;
done
rm $pid
echo
else
retval=$?
echo nothing to stop because kill -0 of pid $pidToKill failed with status $retval
fi
rm -f $pid
else
echo nothing to stop because no pid file $pid
fi
}
restart() {
stop
start
}
condrestart(){
case "$PLATFORM" in
"RHEL")
rh_status > /dev/null 2>&1
retval=$?
;;
"UBUNTU")
ub_status > /dev/null 2>&1
retval=$?
;;
"UNSUPPORTED")
echo "condrestart is not supported on platform"
exit 1
;;
esac
if [[ $retval -eq 0 ]]; then
restart
fi
}
rh_status() {
echo "checking status"
# call sourced status function
status -p $pid
}
ub_status() {
echo "checking status"
# call sourced status function
status_of_proc -p $pid "$0" "$APP"
}
# Executes a specific class' main method with the classpath and environment setup
run() {
classname=$1
shift
if [ -z "$classname" ]; then
echo "ERROR: No classname was given!"
echo "Usage: $0 run <fully qualified classname> [arguments]"
exit 1
fi
# Setup classpaths.
set_classpath $APP_HOME
# sets the JAVA variable.
set_java
echo "Running class $classname"
"$JAVA" $OPTS -cp $CLASSPATH $JAVA_HEAPMAX $classname $@
}
case "$1" in
start)
$1
;;
stop)
$1
;;
restart)
$1
;;
condrestart)
$1
;;
status)
case "$PLATFORM" in
"RHEL")
rh_status
;;
"UBUNTU")
ub_status
;;
"UNSUPPORTED")
echo "status is not supported on platform"
exit 1
;;
esac
;;
classpath)
set_classpath $APP_HOME
set_java
echo $CLASSPATH
;;
run)
shift
run $@
;;
*)
echo "Usage: $0 {start|stop|restart|status|run}"
exit 1
;;
esac
exit $?