This is an automated email from the ASF dual-hosted git repository.

yao pushed a commit to branch branch-1.3
in repository https://gitbox.apache.org/repos/asf/incubator-kyuubi.git


The following commit(s) were added to refs/heads/branch-1.3 by this push:
     new d8f4be3  [KYUUBI #1013] Enhance bootstrap shell script
d8f4be3 is described below

commit d8f4be3b1c7e50345f7fa05aa46acb687f6e4384
Author: Cheng Pan <[email protected]>
AuthorDate: Thu Sep 2 10:15:02 2021 +0800

    [KYUUBI #1013] Enhance bootstrap shell script
    
    <!--
    Thanks for sending a pull request!
    
    Here are some tips for you:
      1. If this is your first time, please read our contributor guidelines: 
https://kyuubi.readthedocs.io/en/latest/community/contributions.html
      2. If the PR is related to an issue in 
https://github.com/apache/incubator-kyuubi/issues, add '[KYUUBI #XXXX]' in your 
PR title, e.g., '[KYUUBI #XXXX] Your PR title ...'.
      3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., 
'[WIP][KYUUBI #XXXX] Your PR title ...'.
    -->
    
    ### _Why are the changes needed?_
    <!--
    Please clarify why the changes are needed. For instance,
      1. If you add a feature, you can talk about the use case of it.
      2. If you fix a bug, you can clarify why it is a bug.
    -->
    
    To make the error message more clear when `SPARK_HOME` is invalid.
    
    ### _How was this patch tested?_
    - [ ] Add some test cases that check the changes thoroughly including 
negative and positive cases if possible
    
    - [ ] Add screenshots for manual tests if appropriate
    
    - [ ] [Run 
test](https://kyuubi.readthedocs.io/en/latest/develop_tools/testing.html#running-tests)
 locally before make a pull request
    
    Closes #1013 from pan3793/sh.
    
    Closes #1013
    
    c9a573b1 [Cheng Pan] nit
    e1628640 [Cheng Pan] indent with 2 spaces
    68a767f5 [Cheng Pan] Address comments
    59d4f076 [Cheng Pan] Enhance load-kyuubi-env.sh
    
    Authored-by: Cheng Pan <[email protected]>
    Signed-off-by: Kent Yao <[email protected]>
    (cherry picked from commit 5edc5066f25910bf27bfcdd339540e8781ec7d8c)
    Signed-off-by: Kent Yao <[email protected]>
---
 bin/kyuubi             | 179 +++++++++++++++++++++++++------------------------
 bin/load-kyuubi-env.sh |  40 ++++++-----
 2 files changed, 110 insertions(+), 109 deletions(-)

diff --git a/bin/kyuubi b/bin/kyuubi
index c47bad3..a048e1b 100755
--- a/bin/kyuubi
+++ b/bin/kyuubi
@@ -19,7 +19,7 @@
 ## Kyuubi Server Main Entrance
 CLASS="org.apache.kyuubi.server.KyuubiServer"
 
-function usage {
+function usage() {
   echo "Usage: bin/kyuubi command"
   echo "  commands:"
   echo "    start        - Run a Kyuubi server as a daemon"
@@ -35,29 +35,29 @@ if [[ "$@" = *--help ]] || [[ "$@" = *-h ]]; then
 fi
 
 function kyuubi_logo() {
-    cat ${KYUUBI_HOME}/bin/kyuubi-logo | grep -v "^#"
+  cat ${KYUUBI_HOME}/bin/kyuubi-logo | grep -v "^#"
 }
 
 function kyuubi_rotate_log() {
-    log=$1;
-    
-    if [[ -z ${KYUUBI_MAX_LOG_FILES} ]]; then
-      num=5
-    elif [[ ${KYUUBI_MAX_LOG_FILES} -gt 0 ]]; then
-      num=${KYUUBI_MAX_LOG_FILES}
-    else
-      echo "Error: KYUUBI_MAX_LOG_FILES must be a positive number, but got 
${KYUUBI_MAX_LOG_FILES}"
-      exit -1
-    fi
-    
-    if [ -f "$log" ]; then # rotate logs
-    while [ ${num} -gt 1 ]; do
-        prev=`expr ${num} - 1`
-        [ -f "$log.$prev" ] && mv "$log.$prev" "$log.$num"
-        num=${prev}
-    done
-    mv "$log" "$log.$num";
-    fi
+  log=$1;
+
+  if [[ -z ${KYUUBI_MAX_LOG_FILES} ]]; then
+    num=5
+  elif [[ ${KYUUBI_MAX_LOG_FILES} -gt 0 ]]; then
+    num=${KYUUBI_MAX_LOG_FILES}
+  else
+    echo "Error: KYUUBI_MAX_LOG_FILES must be a positive number, but got 
${KYUUBI_MAX_LOG_FILES}"
+    exit -1
+  fi
+
+  if [ -f "$log" ]; then # rotate logs
+  while [ ${num} -gt 1 ]; do
+    prev=`expr ${num} - 1`
+    [ -f "$log.$prev" ] && mv "$log.$prev" "$log.$num"
+    num=${prev}
+  done
+  mv "$log" "$log.$num";
+  fi
 }
 
 export KYUUBI_HOME="$(cd "$(dirname "$0")"/..; pwd)"
@@ -74,6 +74,9 @@ fi
 if [[ -z ${SPARK_HOME} ]]; then
   echo "Error: SPARK_HOME IS NOT SET! CANNOT PROCEED." >&2
   exit 1
+elif [[ ! -d ${SPARK_HOME} ]]; then
+  echo "Error: SPARK_HOME[${SPARK_HOME}] DOES NOT EXIST! CANNOT PROCEED." >&2
+  exit 1
 else
   if [[ ! -x "${SPARK_HOME}/bin/spark-submit" ]]; then
     echo "Error: INVALID SPARK DISTRIBUTION! CANNOT PROCEED." >&2
@@ -98,100 +101,100 @@ cmd="${RUNNER} ${KYUUBI_JAVA_OPTS} -cp 
${KYUUBI_CLASSPATH} $CLASS"
 pid="${KYUUBI_PID_DIR}/kyuubi-$USER-$CLASS.pid"
 
 function start_kyuubi() {
-    if [[ ! -w ${KYUUBI_PID_DIR} ]]; then
-      echo "${USER} does not have 'w' permission to ${KYUUBI_PID_DIR}"
-      exit 1
-    fi
+  if [[ ! -w ${KYUUBI_PID_DIR} ]]; then
+    echo "${USER} does not have 'w' permission to ${KYUUBI_PID_DIR}"
+    exit 1
+  fi
 
-    if [[ ! -w ${KYUUBI_LOG_DIR} ]]; then
-      echo "${USER} does not have 'w' permission to ${KYUUBI_LOG_DIR}"
-      exit 1
-    fi
+  if [[ ! -w ${KYUUBI_LOG_DIR} ]]; then
+    echo "${USER} does not have 'w' permission to ${KYUUBI_LOG_DIR}"
+    exit 1
+  fi
 
-    if [ -f "$pid" ]; then
-        TARGET_ID="$(cat "$pid")"
-        if [[ $(ps -p "$TARGET_ID" -o comm=) =~ "java" ]]; then
-          echo "$CLASS running as process $TARGET_ID  Stop it first."
-          exit 1
-        fi
+  if [ -f "$pid" ]; then
+    TARGET_ID="$(cat "$pid")"
+    if [[ $(ps -p "$TARGET_ID" -o comm=) =~ "java" ]]; then
+      echo "$CLASS running as process $TARGET_ID  Stop it first."
+      exit 1
     fi
+  fi
 
-    log="${KYUUBI_LOG_DIR}/kyuubi-$USER-$CLASS-$HOSTNAME.out"
-    kyuubi_rotate_log ${log}
+  log="${KYUUBI_LOG_DIR}/kyuubi-$USER-$CLASS-$HOSTNAME.out"
+  kyuubi_rotate_log ${log}
 
-    echo "Starting $CLASS, logging to $log"
-    nohup nice -n "${KYUUBI_NICENESS:-0}" ${cmd} >> ${log} 2>&1 < /dev/null &
-    newpid="$!"
+  echo "Starting $CLASS, logging to $log"
+  nohup nice -n "${KYUUBI_NICENESS:-0}" ${cmd} >> ${log} 2>&1 < /dev/null &
+  newpid="$!"
 
-    echo "$newpid" > "$pid"
+  echo "$newpid" > "$pid"
 
-    # Poll for up to 5 seconds for the java process to start
-    for i in {1..10}
-    do
-        if [[ $(ps -p "$newpid" -o comm=) =~ "java" ]]; then
-           break
-        fi
-        sleep 0.5
-    done
-
-    sleep 2
-    # Check if the process has died; in that case we'll tail the log so the 
user can see
-    if [[ ! $(ps -p "$newpid" -o comm=) =~ "java" ]]; then
-      echo "Failed to launch: ${cmd}"
-      tail -2 "$log" | sed 's/^/  /'
-      echo "Full log in $log"
-    else
-      echo "Welcome to"
-      kyuubi_logo
+  # Poll for up to 5 seconds for the java process to start
+  for i in {1..10}
+  do
+    if [[ $(ps -p "$newpid" -o comm=) =~ "java" ]]; then
+       break
     fi
+    sleep 0.5
+  done
+
+  sleep 2
+  # Check if the process has died; in that case we'll tail the log so the user 
can see
+  if [[ ! $(ps -p "$newpid" -o comm=) =~ "java" ]]; then
+    echo "Failed to launch: ${cmd}"
+    tail -2 "$log" | sed 's/^/  /'
+    echo "Full log in $log"
+  else
+    echo "Welcome to"
+    kyuubi_logo
+  fi
 }
 
 function run_kyuubi() {
-    echo "Starting $CLASS"
-    nice -n "${KYUUBI_NICENESS:-0}" ${cmd}
+  echo "Starting $CLASS"
+  nice -n "${KYUUBI_NICENESS:-0}" ${cmd}
 }
 
 function stop_kyuubi() {
-    if [ -f ${pid} ]; then
-      TARGET_ID="$(cat "$pid")"
-      if [[ $(ps -p "$TARGET_ID" -o comm=) =~ "java" ]]; then
-        echo "Stopping $CLASS"
-        kill "$TARGET_ID" && rm -f "$pid"
-        for i in {1..20}
-        do
-            sleep 0.5
-            if [[ ! $(ps -p "$TARGET_ID" -o comm=) =~ "java" ]]; then
-              break
-            fi
-        done
-
-        if [[ $(ps -p "$TARGET_ID" -o comm=) =~ "java" ]]; then
-          echo "Failed to stop kyuubi after 10 seconds, try 'kill -9 
${TARGET_ID}' forcefully "
-        else
-           kyuubi_logo
-           echo "Bye!"
+  if [ -f ${pid} ]; then
+    TARGET_ID="$(cat "$pid")"
+    if [[ $(ps -p "$TARGET_ID" -o comm=) =~ "java" ]]; then
+      echo "Stopping $CLASS"
+      kill "$TARGET_ID" && rm -f "$pid"
+      for i in {1..20}
+      do
+        sleep 0.5
+        if [[ ! $(ps -p "$TARGET_ID" -o comm=) =~ "java" ]]; then
+          break
         fi
+      done
+
+      if [[ $(ps -p "$TARGET_ID" -o comm=) =~ "java" ]]; then
+        echo "Failed to stop kyuubi after 10 seconds, try 'kill -9 
${TARGET_ID}' forcefully "
       else
-        echo "no $CLASS to stop"
+        kyuubi_logo
+        echo "Bye!"
       fi
     else
       echo "no $CLASS to stop"
     fi
+  else
+    echo "no $CLASS to stop"
+  fi
 }
 
 function check_kyuubi() {
-    if [[ -f ${pid} ]]; then
-      TARGET_ID="$(cat "$pid")"
-      if [[ $(ps -p "$TARGET_ID" -o comm=) =~ "java" ]]; then
-        echo "Kyuubi is running (pid: $TARGET_ID)"
-      else
-        echo "Kyuubi is not running"
-      fi
+  if [[ -f ${pid} ]]; then
+    TARGET_ID="$(cat "$pid")"
+    if [[ $(ps -p "$TARGET_ID" -o comm=) =~ "java" ]]; then
+      echo "Kyuubi is running (pid: $TARGET_ID)"
     else
       echo "Kyuubi is not running"
     fi
-
+  else
+    echo "Kyuubi is not running"
+  fi
 }
+
 case $1 in
   (start | "")
     start_kyuubi
diff --git a/bin/load-kyuubi-env.sh b/bin/load-kyuubi-env.sh
index 845845d..872ca46 100755
--- a/bin/load-kyuubi-env.sh
+++ b/bin/load-kyuubi-env.sh
@@ -24,27 +24,27 @@ export 
KYUUBI_CONF_DIR="${KYUUBI_CONF_DIR:-"${KYUUBI_HOME}"/conf}"
 silent=0
 while getopts "s" arg
 do
-        case $arg in
-             s)
-                silent=1
-                ;;
-             ?)
-             echo "unknown argument"
-        exit 1
-        ;;
-        esac
+  case $arg in
+    s)
+      silent=1
+    ;;
+    ?)
+      echo "unknown argument"
+      exit 1
+    ;;
+  esac
 done
 
 KYUUBI_ENV_SH="${KYUUBI_CONF_DIR}"/kyuubi-env.sh
 if [[ -f ${KYUUBI_ENV_SH} ]]; then
-   set -a
-   if [ $silent -eq 0 ]; then
+  set -a
+  if [ $silent -eq 0 ]; then
     echo "Using kyuubi environment file ${KYUUBI_ENV_SH} to initialize..."
-   fi
-   . "${KYUUBI_ENV_SH}"
-   set +a
+  fi
+  . "${KYUUBI_ENV_SH}"
+  set +a
 else
-   echo "Warn: Not find kyuubi environment file ${KYUUBI_ENV_SH}, using 
default ones..."
+  echo "Warn: Not find kyuubi environment file ${KYUUBI_ENV_SH}, using default 
ones..."
 fi
 
 export KYUUBI_LOG_DIR="${KYUUBI_LOG_DIR:-"${KYUUBI_HOME}/logs"}"
@@ -63,9 +63,9 @@ if [[ -e ${KYUUBI_WORK_DIR_ROOT} ]]; then
 fi
 
 if [[ -z ${JAVA_HOME} ]]; then
-   if [[ $(command -v java) ]]; then
-     export JAVA_HOME="$(dirname $(dirname $(which java)))"
-   fi
+  if [[ $(command -v java) ]]; then
+    export JAVA_HOME="$(dirname $(dirname $(which java)))"
+  fi
 fi
 
 export KYUUBI_SCALA_VERSION="${KYUUBI_SCALA_VERSION:-"2.12"}"
@@ -74,9 +74,7 @@ if [[ -f ${KYUUBI_HOME}/RELEASE ]]; then
   SPARK_VERSION_BUILD="$(grep "Spark " "$KYUUBI_HOME/RELEASE" | awk -F ' ' 
'{print $2}')"
   HADOOP_VERSION_BUILD="$(grep "Hadoop " "$KYUUBI_HOME/RELEASE" | awk -F ' ' 
'{print $2}')"
   
SPARK_BUILTIN="${KYUUBI_HOME}/externals/spark-$SPARK_VERSION_BUILD-bin-hadoop${HADOOP_VERSION_BUILD:0:3}"
-fi
-
-if [[ ! -d ${SPARK_BUILTIN} ]]; then
+else
   MVN="${MVN:-"${KYUUBI_HOME}/build/mvn"}"
   SPARK_VERSION_BUILD=$("$MVN" help:evaluate -Dexpression=spark.version 
2>/dev/null\
     | grep -v "INFO"\

Reply via email to