From cef5b021f57e9639b5a9a7384de1f95fd162c74f Mon Sep 17 00:00:00 2001 From: Soner Sayakci Date: Mon, 3 Apr 2023 23:20:49 +0200 Subject: [PATCH] feat: allow overwrite opensearch home Signed-off-by: Soner Sayakci --- CHANGELOG.md | 1 + distribution/src/bin/opensearch-env | 24 +++++++++++++----------- distribution/src/bin/opensearch-env.bat | 14 ++++++++------ 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e0a1316eb8b2f..86c06572b57d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Change http code on create index API with bad input raising NotXContentException from 500 to 400 ([#4773](https://github.com/opensearch-project/OpenSearch/pull/4773)) - Change http code for DecommissioningFailedException from 500 to 400 ([#5283](https://github.com/opensearch-project/OpenSearch/pull/5283)) - Improve summary error message for invalid setting updates ([#4792](https://github.com/opensearch-project/OpenSearch/pull/4792)) +- Changed `opensearch-env` to respect already set `OPENSEARCH_HOME` environment variable ([#6956](https://github.com/opensearch-project/OpenSearch/pull/6956/)) ### Deprecated diff --git a/distribution/src/bin/opensearch-env b/distribution/src/bin/opensearch-env index 6fe703a73b2de..f94824576b122 100644 --- a/distribution/src/bin/opensearch-env +++ b/distribution/src/bin/opensearch-env @@ -28,18 +28,20 @@ while [ -h "$SCRIPT" ] ; do fi done -# determine OpenSearch home; to do this, we strip from the path until we find -# bin, and then strip bin (there is an assumption here that there is no nested -# directory under bin also named bin) -OPENSEARCH_HOME=`dirname "$SCRIPT"` - -# now make OPENSEARCH_HOME absolute -OPENSEARCH_HOME=`cd "$OPENSEARCH_HOME"; pwd` - -while [ "`basename "$OPENSEARCH_HOME"`" != "bin" ]; do +if [[ -z "$OPENSEARCH_HOME" ]]; then + # determine OpenSearch home; to do this, we strip from the path until we find + # bin, and then strip bin (there is an assumption here that there is no nested + # directory under bin also named bin) + OPENSEARCH_HOME=`dirname "$SCRIPT"` + + # now make OPENSEARCH_HOME absolute + OPENSEARCH_HOME=`cd "$OPENSEARCH_HOME"; pwd` + + while [ "`basename "$OPENSEARCH_HOME"`" != "bin" ]; do + OPENSEARCH_HOME=`dirname "$OPENSEARCH_HOME"` + done OPENSEARCH_HOME=`dirname "$OPENSEARCH_HOME"` -done -OPENSEARCH_HOME=`dirname "$OPENSEARCH_HOME"` +fi # now set the classpath OPENSEARCH_CLASSPATH="$OPENSEARCH_HOME/lib/*" diff --git a/distribution/src/bin/opensearch-env.bat b/distribution/src/bin/opensearch-env.bat index 95088aaee7d3d..4b5d2237e7d0e 100644 --- a/distribution/src/bin/opensearch-env.bat +++ b/distribution/src/bin/opensearch-env.bat @@ -3,15 +3,17 @@ set SCRIPT=%0 rem determine OpenSearch home; to do this, we strip from the path until we rem find bin, and then strip bin (there is an assumption here that there is no rem nested directory under bin also named bin) -for %%I in (%SCRIPT%) do set OPENSEARCH_HOME=%%~dpI +if not defined OPENSEARCH_HOME ( + for %%I in (%SCRIPT%) do set OPENSEARCH_HOME=%%~dpI -:opensearch_home_loop -for %%I in ("%OPENSEARCH_HOME:~1,-1%") do set DIRNAME=%%~nxI -if not "%DIRNAME%" == "bin" ( + :opensearch_home_loop + for %%I in ("%OPENSEARCH_HOME:~1,-1%") do set DIRNAME=%%~nxI + if not "%DIRNAME%" == "bin" ( + for %%I in ("%OPENSEARCH_HOME%..") do set OPENSEARCH_HOME=%%~dpfI + goto opensearch_home_loop + ) for %%I in ("%OPENSEARCH_HOME%..") do set OPENSEARCH_HOME=%%~dpfI - goto opensearch_home_loop ) -for %%I in ("%OPENSEARCH_HOME%..") do set OPENSEARCH_HOME=%%~dpfI rem now set the classpath set OPENSEARCH_CLASSPATH=!OPENSEARCH_HOME!\lib\*