dengzhhu653 commented on code in PR #3386:
URL: https://github.com/apache/hive/pull/3386#discussion_r908002850


##########
bin/ext/hiveserver2.sh:
##########
@@ -16,24 +16,83 @@
 THISSERVICE=hiveserver2
 export SERVICE_LIST="${SERVICE_LIST}${THISSERVICE} "
 
+if [ "$HIVESERVER2_PID_DIR" = "" ]; then
+  HIVESERVER2_PID_DIR=$HIVE_CONF_DIR
+fi
+
+HIVESERVER2_PID=$HIVESERVER2_PID_DIR/hiveserver2.pid
+
+before_start() {
+  #ckeck if the process is not running
+  mkdir -p "$HIVESERVER2_PID_DIR"
+  if [ -f $HIVESERVER2_PID ]; then
+    if kill -0 $(cat $HIVESERVER2_PID) >/dev/null 2>&1; then
+      echo "HiveServer2 running as process $(cat $HIVESERVER2_PID).  Stop it 
first."
+      exit 1
+    fi
+  fi
+}
+
 hiveserver2() {
-  >&2 echo "$(timestamp): Starting HiveServer2"
-  CLASS=org.apache.hive.service.server.HiveServer2
-  if $cygwin; then
-    HIVE_LIB=`cygpath -w "$HIVE_LIB"`
+  if [ "$1" = "--graceful_stop" ]; then
+    pid=$2
+    if [ "$pid" = "" -a -f $HIVESERVER2_PID ]; then
+      pid=$(cat $HIVESERVER2_PID)
+    fi
+    if [ "$pid" != "" ]; then
+      timeout=$3
+      killAndWait $pid ${timeout:-1800}
+    fi
+  else
+    before_start
+    echo >&2 "$(timestamp): Starting HiveServer2"
+    CLASS=org.apache.hive.service.server.HiveServer2
+    if $cygwin; then
+      HIVE_LIB=$(cygpath -w "$HIVE_LIB")
+    fi
+    JAR=${HIVE_LIB}/hive-service-[0-9].*.jar
+
+    export HADOOP_CLIENT_OPTS=" -Dproc_hiveserver2 $HADOOP_CLIENT_OPTS "
+    export HADOOP_OPTS="$HIVESERVER2_HADOOP_OPTS $HADOOP_OPTS"
+    hiveserver2_pid="$$"

Review Comment:
   > so this would be the PID of the current shell script that starts HS2 
right? At this point, we havent launched the HS2 process yet
   
   yeah, that's right.  the `exec` command will inherit the process ID of the 
parent, we also have used in 
[hive](https://github.com/apache/hive/blob/master/bin/hive#L383) to get the pid 
of the service process.
   
   > Dont we need the PID of HS2 process? if so, should HS2 write this file? 
also, what happens when there are multiple HS2 instances?
   
   yes, the pid is used later for killing the process, so we should persist it 
into a file where locates at $HIVE_CONF_DIR/hiveserver2.pid by default, usually 
we have a single corresponding `HIVE_CONF_DIR` for each HS2 instance, and this 
can be changed via env `HIVESERVER2_PID_DIR` when starting the HS2.
   Also add a 
[check](https://github.com/apache/hive/blob/23452342c84cef625b1b89f5e3e9e16bbe9103ad/bin/ext/hiveserver2.sh#L25-L34)
 here before we start HS2, this avoid mutiple HS2 instances writing its pid to 
the same file.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to