From 49ef1d97c008255928d3b1f5b9944db37e5512b5 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 | 2 ++ distribution/src/bin/opensearch-env | 24 +++++++++++++----------- distribution/src/bin/opensearch-env.bat | 14 ++++++++------ 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 795abe8bdce49..bed7bdb97c1b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Bump: Netty from 4.1.90.Final to 4.1.91.Final , ASM 9.4 to ASM 9.5, ByteBuddy 1.14.2 to 1.14.3 ([#6981](https://github.com/opensearch-project/OpenSearch/pull/6981)) ### Changed +- Changed `opensearch-env` to respect already set `OPENSEARCH_HOME` environment variable ([#6956](https://github.com/opensearch-project/OpenSearch/pull/6956/)) + ### Deprecated ### Removed ### Fixed diff --git a/distribution/src/bin/opensearch-env b/distribution/src/bin/opensearch-env index f9d8e607b7d5b..072a3bcc3d7d0 100644 --- a/distribution/src/bin/opensearch-env +++ b/distribution/src/bin/opensearch-env @@ -19,18 +19,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\*