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

chengpan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kyuubi.git


The following commit(s) were added to refs/heads/master by this push:
     new 7b388895b [KYUUBI #5987] Enhance KYUUBI_HOME detection in shell script 
to handle softlink cases
7b388895b is described below

commit 7b388895b7bab2c5349ed390c4f27f58a0af1729
Author: Emor-nj <[email protected]>
AuthorDate: Wed Jan 17 18:00:06 2024 +0800

    [KYUUBI #5987] Enhance KYUUBI_HOME detection in shell script to handle 
softlink cases
    
    # :mag: Description
    ## Issue References ๐Ÿ”—
    
    This pull request fixes #5987
    Modify the logic in the beeline script that specifies the KYUUBI_HOME 
environment variable.
    
    ## Describe Your Solution ๐Ÿ”ง
    
     If the environment has already declared KYUUBI_HOME, it should use the 
pre-declared KYUUBI_HOME instead of forcefully specifying the parent directory 
of the current one.
    
    ## Types of changes :bookmark:
    
    - [ ] Bugfix (non-breaking change which fixes an issue)
    - [ ] New feature (non-breaking change which adds functionality)
    - [ ] Breaking change (fix or feature that would cause existing 
functionality to change)
    
    ## Test Plan ๐Ÿงช
    
    #### Behavior Without This Pull Request :coffin:
    1. set soft link:
     `ln -s /opt/soft/kyuubi/kyuubi/bin/beeline /usr/bin/kyuubi-beeline`
    2. set env like:
    `export KYUUBI_HOME=/opt/soft/kyuubi/kyuubi`
    3. run kyuubi-beeline:
    `kyuubi-beeline -u 
"jdbc:hive2://xx.xx.xx.xx:2181,xx.xx.xx.xx:2181,xx.xx.xx.xx:2181/tmp;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=kyuubi;principal=hive/_HOSTxxx"`
    4. command will fail:
    `/bin/kyuubi-beeline: line 27: //bin/load-kyuubi-env.sh: No such file or 
directory
    Error: JAVA_HOME IS NOT SET! CANNOT PROCEED.`
    
    #### Behavior With This Pull Request :tada:
    1. set soft link:
     `ln -s /opt/soft/kyuubi/kyuubi/bin/beeline /usr/bin/kyuubi-beeline`
    2. set env like:
    `export KYUUBI_HOME=/opt/soft/kyuubi/kyuubi`
    3. run kyuubi-beeline:
    `kyuubi-beeline -u 
"jdbc:hive2://xx.xx.xx.xx:2181,xx.xx.xx.xx:2181,xx.xx.xx.xx:2181/tmp;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=kyuubi;principal=hive/_HOSTxxx"`
    4. command will success
    #### Related Unit Tests
    
    ---
    
    # Checklist ๐Ÿ“
    
    - [ ] This patch was not authored or co-authored using [Generative 
Tooling](https://www.apache.org/legal/generative-tooling.html)
    
    **Be nice. Be informative.**
    
    Closes #5988 from Emor-nj/kyuubi-beeline.
    
    Closes #5987
    
    3a988e0f7 [Emor-nj] fix KYUUBI_HOME is always empty in load-kyuubi-env.sh
    cc703870f [Emor-nj] fix load-kyuubi-env.sh
    a10142825 [Emor-nj] Remove unnecessary exports.
    f48db3f81 [Emor-nj] uniformly modify all related scripts.
    35215b978 [Emor-nj] Modify the logic in the beeline script that specifies 
the KYUUBI_HOME environment variable.
    
    Authored-by: Emor-nj <[email protected]>
    Signed-off-by: Cheng Pan <[email protected]>
---
 bin/beeline            | 4 +++-
 bin/kyuubi             | 4 +++-
 bin/kyuubi-admin       | 4 +++-
 bin/kyuubi-ctl         | 4 +++-
 bin/kyuubi-zk-cli      | 5 +++--
 bin/load-kyuubi-env.sh | 5 +++--
 6 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/bin/beeline b/bin/beeline
index 3581f6dd6..f277efa44 100755
--- a/bin/beeline
+++ b/bin/beeline
@@ -19,7 +19,9 @@
 ## Kyuubi BeeLine Entrance
 CLASS="org.apache.hive.beeline.KyuubiBeeLine"
 
-export KYUUBI_HOME="$(cd "$(dirname "$0")"/..; pwd)"
+if [ -z "${KYUUBI_HOME}" ]; then
+  KYUUBI_HOME="$(cd "`dirname "$0"`"/..; pwd)"
+fi
 
 . "${KYUUBI_HOME}/bin/load-kyuubi-env.sh" -s
 
diff --git a/bin/kyuubi b/bin/kyuubi
index 9132aae39..17ab717e5 100755
--- a/bin/kyuubi
+++ b/bin/kyuubi
@@ -62,7 +62,9 @@ function kyuubi_rotate_log() {
   fi
 }
 
-export KYUUBI_HOME="$(cd "$(dirname "$0")"/..; pwd)"
+if [ -z "${KYUUBI_HOME}" ]; then
+  KYUUBI_HOME="$(cd "`dirname "$0"`"/..; pwd)"
+fi
 
 if [[ $1 == "start" ]] || [[ $1 == "run" ]]; then
   . "${KYUUBI_HOME}/bin/load-kyuubi-env.sh"
diff --git a/bin/kyuubi-admin b/bin/kyuubi-admin
index a1f176ec1..8a148d159 100755
--- a/bin/kyuubi-admin
+++ b/bin/kyuubi-admin
@@ -19,7 +19,9 @@
 ## Kyuubi Admin Control Client Entrance
 CLASS="org.apache.kyuubi.ctl.cli.AdminControlCli"
 
-export KYUUBI_HOME="$(cd "$(dirname "$0")"/..; pwd)"
+if [ -z "${KYUUBI_HOME}" ]; then
+  KYUUBI_HOME="$(cd "`dirname "$0"`"/..; pwd)"
+fi
 
 . "${KYUUBI_HOME}/bin/load-kyuubi-env.sh" -s
 
diff --git a/bin/kyuubi-ctl b/bin/kyuubi-ctl
index 16809c075..0214737d4 100755
--- a/bin/kyuubi-ctl
+++ b/bin/kyuubi-ctl
@@ -19,7 +19,9 @@
 ## Kyuubi Control Client Entrance
 CLASS="org.apache.kyuubi.ctl.cli.ControlCli"
 
-export KYUUBI_HOME="$(cd "$(dirname "$0")"/..; pwd)"
+if [ -z "${KYUUBI_HOME}" ]; then
+  KYUUBI_HOME="$(cd "`dirname "$0"`"/..; pwd)"
+fi
 
 . "${KYUUBI_HOME}/bin/load-kyuubi-env.sh" -s
 
diff --git a/bin/kyuubi-zk-cli b/bin/kyuubi-zk-cli
index f503c3e5a..c85f47c4c 100755
--- a/bin/kyuubi-zk-cli
+++ b/bin/kyuubi-zk-cli
@@ -19,8 +19,9 @@
 ## Zookeeper Shell Client Entrance
 CLASS="org.apache.kyuubi.shaded.zookeeper.ZooKeeperMain"
 
-export KYUUBI_HOME="$(cd "$(dirname "$0")"/..; pwd)"
-
+if [ -z "${KYUUBI_HOME}" ]; then
+  KYUUBI_HOME="$(cd "`dirname "$0"`"/..; pwd)"
+fi
 . "${KYUUBI_HOME}/bin/load-kyuubi-env.sh" -s
 
 if [[ -z ${JAVA_HOME} ]]; then
diff --git a/bin/load-kyuubi-env.sh b/bin/load-kyuubi-env.sh
index 4d6f72ddf..fdff1e0c5 100755
--- a/bin/load-kyuubi-env.sh
+++ b/bin/load-kyuubi-env.sh
@@ -17,8 +17,9 @@
 #
 
 
-export KYUUBI_HOME="${KYUUBI_HOME:-"$(cd "$(dirname "$0")"/.. || exit; pwd)"}"
-
+if [ -z "${KYUUBI_HOME}" ]; then
+  export KYUUBI_HOME="$(cd "$(dirname "$0")"/.. || exit; pwd)"
+fi
 export KYUUBI_CONF_DIR="${KYUUBI_CONF_DIR:-"${KYUUBI_HOME}"/conf}"
 
 silent=0

Reply via email to