Skip to content

Commit 27db55f

Browse files
akhalymon-cvekrivokonmapr
authored andcommitted
MapR [SPARK-846] Add service verifier to Spark package (apache#789)
1 parent 3ee126f commit 27db55f

File tree

1 file changed

+165
-0
lines changed

1 file changed

+165
-0
lines changed

ext-conf/verify_service.sh

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
#!/usr/bin/env bash
2+
3+
# Licensed to the Apache Software Foundation (ASF) under one or more
4+
# contributor license agreements. See the NOTICE file distributed with
5+
# this work for additional information regarding copyright ownership.
6+
# The ASF licenses this file to You under the Apache License, Version 2.0
7+
# (the "License"); you may not use this file except in compliance with
8+
# the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
MAPR_HOME="${MAPR_HOME:-/opt/mapr}"
19+
ROLES_DIR="${MAPR_HOME}/roles"
20+
SPARK_VERSION="$(cat ${MAPR_HOME}/spark/sparkversion)"
21+
SPARK_HOME="${MAPR_HOME}/spark/spark-${SPARK_VERSION}"
22+
SPARK_PID_DIR="${SPARK_HOME}/pid"
23+
SPARK_IDENT_STRING="$USER"
24+
LOG_FILE=${SPARK_HOME}/logs/verify_service
25+
26+
EXIT_SUCCESS=0
27+
EXIT_NOT_RUNNING=1
28+
EXIT_RUNNING_NOT_RESPONDING=2
29+
30+
MASTER_PID_FILE=${SPARK_PID_DIR}/spark-${SPARK_IDENT_STRING}-org.apache.spark.deploy.master.Master-1.pid
31+
HISTORY_PID_FILE=${SPARK_PID_DIR}/spark-${SPARK_IDENT_STRING}-org.apache.spark.deploy.history.HistoryServer-1.pid
32+
THRIFT_PID_FILE=${SPARK_PID_DIR}/spark-${SPARK_IDENT_STRING}-org.apache.spark.sql.hive.thriftserver.HiveThriftServer2-1.pid
33+
34+
MASTER_CONFIGURED_PORT=$(grep -F standalone.port ${SPARK_HOME}/conf/spark-defaults.conf | cut -d ' ' -f 2)
35+
HISTORY_CONFIGURED_PORT=$(grep -F historyServer.port ${SPARK_HOME}/conf/spark-defaults.conf | cut -d ' ' -f 2)
36+
MASTER_PORT="${MASTER_CONFIGURED_PORT:-8080}"
37+
HISTORY_PORT="${HISTORY_CONFIGURED_PORT:-18080}"
38+
THRIFT_PORT=2304
39+
40+
logInfo() {
41+
message="$1"
42+
echo "$(timestamp) [INFO] $message" | tee -a "$LOG_FILE"
43+
}
44+
45+
logError() {
46+
message="$1"
47+
echo "$(timestamp) [ERROR] $message" | tee -a "$LOG_FILE"
48+
}
49+
50+
timestamp() {
51+
date +"[%Y-%m-%d %H:%M:%S]" # current time
52+
}
53+
54+
is_responding() {
55+
DAEMON=$1
56+
PORT=$2
57+
logInfo "Checking if $DAEMON port $PORT is open"
58+
nohup nc localhost "$PORT" </dev/null >/dev/null 2>&1
59+
if [ "$?" == 0 ]; then
60+
logInfo "$DAEMON port $PORT is open"
61+
return $EXIT_SUCCESS
62+
else
63+
logError "$DAEMON port $PORT is not open"
64+
return $EXIT_RUNNING_NOT_RESPONDING
65+
fi
66+
}
67+
68+
is_running() {
69+
SERVICE="$1"
70+
PID_FILE="$2"
71+
logInfo "Starting $SERVICE verifier at $(timestamp)"
72+
if [ -e "$PID_FILE" ] || [ -h "$PID_FILE" ]; then
73+
process_pid=$(cat "$PID_FILE" 2>/dev/null)
74+
if [ $? -ne 0 ]; then
75+
PID_FILE=$(ls -l "$PID_FILE" | awk '{print $11}')
76+
process_pid=$(cat "$PID_FILE" 2>/dev/null)
77+
fi
78+
if [ -z "$process_pid" ]; then
79+
logError "ERROR - could not get pid for $SERVICE"
80+
return $EXIT_NOT_RUNNING
81+
fi
82+
logInfo "checking to see if pid $process_pid is alive"
83+
if kill -s 0 "$process_pid" 2>/dev/null; then
84+
logInfo "pid $process_pid is alive"
85+
return $EXIT_SUCCESS
86+
else
87+
logInfo "pid $process_pid is NOT running"
88+
return $EXIT_NOT_RUNNING
89+
fi
90+
else
91+
logInfo "no pid file, service $SERVICE is NOT running"
92+
return $EXIT_NOT_RUNNING
93+
fi
94+
}
95+
96+
97+
logInfo "Starting verifier at $(date)"
98+
99+
MASTER_STATUS="$EXIT_SUCCESS"
100+
if [ -f "$ROLES_DIR/spark-master" ]; then
101+
logInfo "Spark Master is installed"
102+
if is_running master "$MASTER_PID_FILE"; then
103+
if is_responding master "$MASTER_PORT"; then
104+
MASTER_STATUS="$EXIT_SUCCESS"
105+
logInfo "Spark Master is responsive"
106+
else
107+
MASTER_STATUS="$EXIT_RUNNING_NOT_RESPONDING"
108+
logInfo "Spark Master is running but not responsive"
109+
fi
110+
else
111+
MASTER_STATUS="$EXIT_NOT_RUNNING"
112+
logInfo "Spark Master is not running"
113+
fi
114+
else
115+
logInfo "Spark Master is not installed"
116+
fi
117+
118+
HISTORY_STATUS="$EXIT_SUCCESS"
119+
if [ -f "$ROLES_DIR/spark-historyserver" ]; then
120+
logInfo "Spark history server is installed"
121+
if is_running historyserver "$HISTORY_PID_FILE"; then
122+
if is_responding historyserver "$HISTORY_PORT"; then
123+
HISTORY_STATUS="$EXIT_SUCCESS"
124+
logInfo "Spark history server is responsive"
125+
else
126+
HISTORY_STATUS="$EXIT_RUNNING_NOT_RESPONDING"
127+
logInfo "Spark history server is running but not responsive"
128+
fi
129+
else
130+
HISTORY_STATUS="$EXIT_NOT_RUNNING"
131+
logInfo "Spark history server is not running"
132+
fi
133+
else
134+
logInfo "Spark history server is not installed"
135+
fi
136+
137+
THRIFT_STATUS="$EXIT_SUCCESS"
138+
if [ -f "$ROLES_DIR/spark-thriftserver" ]; then
139+
logInfo "Thriftserver is installed"
140+
if is_running thriftserver "$THRIFT_PID_FILE"; then
141+
if is_responding thriftserver $THRIFT_PORT; then
142+
THRIFT_STATUS="$EXIT_SUCCESS"
143+
logInfo "Thriftserver is responsive"
144+
else
145+
THRIFT_STATUS="$EXIT_RUNNING_NOT_RESPONDING"
146+
logInfo "Thriftserver is running but not responsive"
147+
fi
148+
else
149+
THRIFT_STATUS="$EXIT_NOT_RUNNING"
150+
logInfo "Thriftserver is not running"
151+
fi
152+
else
153+
logInfo "Thriftserver is not installed"
154+
fi
155+
156+
157+
if [ "$THRIFT_STATUS" = "$EXIT_SUCCESS" ] && [ "$HISTORY_STATUS" = "$EXIT_SUCCESS" ] && [ "$MASTER_STATUS" = "$EXIT_SUCCESS" ]; then
158+
exit "$EXIT_SUCCESS"
159+
fi
160+
161+
if [ "$THRIFT_STATUS" = "$EXIT_RUNNING_NOT_RESPONDING" ] || [ "$HISTORY_STATUS" = "$EXIT_RUNNING_NOT_RESPONDING" ] || [ "$MASTER_STATUS" = "$EXIT_RUNNING_NOT_RESPONDING" ] ; then
162+
exit "$EXIT_RUNNING_NOT_RESPONDING"
163+
fi
164+
165+
exit "$EXIT_NOT_RUNNING"

0 commit comments

Comments
 (0)