forked from apache/gobblin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgobblin-service.sh
139 lines (120 loc) · 3.42 KB
/
gobblin-service.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
#!/usr/bin/env 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.
#
# Print an error message and exit
function die() {
echo -e "\nError: $@\n" 1>&2
print_usage
exit 1
}
function print_usage() {
echo "gobblin-service.sh <start | stop>"
echo "Where OPTION can be:"
echo " --jvmflags <string of jvm flags> String containing any additional JVM flags to include"
echo " --jars <column-separated list of extra jars> Column-separated list of extra jars to put on the CLASSPATH"
echo " --help Display this help and exit"
}
function start() {
for jarFile in `ls ${FWDIR_LIB}/*`
do
GOBBLIN_JARS=${GOBBLIN_JARS}:${jarFile}
done
export HADOOP_USER_CLASSPATH_FIRST=true
CLASSPATH=${FWDIR_CONF}:${GOBBLIN_JARS}:${SERVICE_CONF_DIR}:${HADOOP_HOME}/lib
if [ -n "$EXTRA_JARS" ]; then
CLASSPATH=$CLASSPATH:"$EXTRA_JARS"
fi
LOG_ARGS="1>${FWDIR_LOGS}/GobblinService.stdout 2>${FWDIR_LOGS}/GobblinService.stderr"
# LOG4J_ARGS="-Dlog4j.configuration=conf/log4j.xml"
DEBUGGER_ARGS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5006"
LOG4J_PATH=file://${FWDIR_CONF}/log4j-service.properties
COMMAND="$JAVA_HOME/bin/java -Dlog4j.configuration=$LOG4J_PATH -cp $CLASSPATH $JVM_FLAGS $LOG4J_ARGS $DEBUGGER_ARGS org.apache.gobblin.service.modules.core.GobblinServiceManager --service_name $SERVICE_NAME $LOG_ARGS"
echo "Running command:"
echo "$COMMAND"
nohup $COMMAND >service.out 2>&1 & echo $! > $PID
}
function stop() {
if [ -f "$PID" ]; then
if kill -0 $PID_VALUE > /dev/null 2>&1; then
echo 'Stopping the Gobblin service'
kill $PID_VALUE
else
echo "Process $PID_VALUE is not running"
fi
else
echo "No pid file found"
fi
}
FWDIR="$(cd `dirname $0`/..; pwd)"
FWDIR_LIB=${FWDIR}/lib
FWDIR_CONF=${FWDIR}/conf/service
FWDIR_BIN=${FWDIR}/bin
FWDIR_LOGS=${FWDIR}/logs
SERVICE_NAME="gobblin_service"
. ${FWDIR_BIN}/gobblin-env.sh
for i in "$@"
do
case "$1" in
start|stop)
ACTION="$1"
;;
--jvmflags)
JVM_FLAGS="$2"
shift
;;
--jars)
EXTRA_JARS="$2"
shift
;;
--service)
SERVICE_NAME="$2"
shift
;;
--help)
print_usage
exit 0
;;
*)
;;
esac
shift
done
if [ -z "$JAVA_HOME" ]; then
die "Environment variable JAVA_HOME not set!"
fi
# User defined JVM flags overrides $GOBBLIN_JVM_FLAGS (if any)
if [ -n "$JVM_FLAGS" ]; then
JVM_FLAGS="-Xmx1g -Xms512m"
fi
PID="$FWDIR/.gobblin-service-app-pid"
if [ -f "$PID" ]; then
PID_VALUE=`cat $PID` > /dev/null 2>&1
else
PID_VALUE=""
fi
case "$ACTION" in
"start")
start
;;
"stop")
stop
;;
*)
print_usage
exit 1
;;
esac