From 7b388895b7bab2c5349ed390c4f27f58a0af1729 Mon Sep 17 00:00:00 2001 From: Emor-nj Date: Wed, 17 Jan 2024 18:00:06 +0800 Subject: [PATCH] [KYUUBI #5987] Enhance KYUUBI_HOME detection in shell script to handle softlink cases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # :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 Signed-off-by: Cheng Pan --- 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 3581f6dd6bd..f277efa440f 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 9132aae39e8..17ab717e5ee 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 a1f176ec157..8a148d159f7 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 16809c0754b..0214737d46a 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 f503c3e5a5e..c85f47c4c5d 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 4d6f72ddf3e..fdff1e0c571 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