From d35d9d1886d1e99ebe466205be993f792c90f684 Mon Sep 17 00:00:00 2001 From: Andrey Ershov Date: Thu, 14 Mar 2019 16:27:32 +0100 Subject: [PATCH] cd ES_HOME in elasticsearch-env (#39937) This commit adds cd $ES_HOME to elasticsearch-env and removes it from elasticsearch. This way, both elasticsearch and elasticsearch-cli are executed with the working directory set to $ES_HOME. The need for the fix arose from the following bug: 1. Explicitly set path.data to relative to ES_HOME path in elasticsearch.yml. 2. Run elasticsearch from any directory. Elasticsearch is able to correctly start. 3. Stop elasticsearch. 4. Run elasticsearch-node unsafe-bootstrap, not from ES_HOME directory. It will fail with an exception. This commit fixes the issue and adds a new test. This PR fixes the issue and adds a new test. Also tests >=100 are renamed because alphabetic order does not work for them. (cherry picked from commit 2ffc29306ff7366efc598e7b4dd2ce528895cd3a with fixes by #40083 and #40118) --- distribution/src/bin/elasticsearch | 1 - distribution/src/bin/elasticsearch-env | 2 ++ distribution/src/bin/elasticsearch-env.bat | 2 ++ distribution/src/bin/elasticsearch.bat | 1 - .../packaging/test/ArchiveTestCase.java | 22 ++++++++++++++++--- 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/distribution/src/bin/elasticsearch b/distribution/src/bin/elasticsearch index 6ce76b6cf01..50913fd94fc 100755 --- a/distribution/src/bin/elasticsearch +++ b/distribution/src/bin/elasticsearch @@ -20,7 +20,6 @@ ES_JVM_OPTIONS="$ES_PATH_CONF"/jvm.options JVM_OPTIONS=`"$JAVA" -cp "$ES_CLASSPATH" org.elasticsearch.tools.launchers.JvmOptionsParser "$ES_JVM_OPTIONS"` ES_JAVA_OPTS="${JVM_OPTIONS//\"\$\{ES_TMPDIR\}\"/$ES_TMPDIR} $ES_JAVA_OPTS" -cd "$ES_HOME" # manual parsing to find out, if process should be detached if ! echo $* | grep -E '(^-d |-d$| -d |--daemonize$|--daemonize )' > /dev/null; then exec \ diff --git a/distribution/src/bin/elasticsearch-env b/distribution/src/bin/elasticsearch-env index 0b5bd6b6d58..0e7f591adac 100644 --- a/distribution/src/bin/elasticsearch-env +++ b/distribution/src/bin/elasticsearch-env @@ -86,3 +86,5 @@ ES_DISTRIBUTION_TYPE=${es.distribution.type} if [ -z "$ES_TMPDIR" ]; then ES_TMPDIR=`"$JAVA" -cp "$ES_CLASSPATH" org.elasticsearch.tools.launchers.TempDirectory` fi + +cd "$ES_HOME" diff --git a/distribution/src/bin/elasticsearch-env.bat b/distribution/src/bin/elasticsearch-env.bat index 4101d186398..bfaf56d7466 100644 --- a/distribution/src/bin/elasticsearch-env.bat +++ b/distribution/src/bin/elasticsearch-env.bat @@ -60,3 +60,5 @@ set ES_DISTRIBUTION_TYPE=${es.distribution.type} if not defined ES_TMPDIR ( for /f "tokens=* usebackq" %%a in (`"%JAVA% -cp "!ES_CLASSPATH!" "org.elasticsearch.tools.launchers.TempDirectory""`) do set ES_TMPDIR=%%a ) + +cd /d "%ES_HOME%" diff --git a/distribution/src/bin/elasticsearch.bat b/distribution/src/bin/elasticsearch.bat index 9b67fa2e0ff..975af52e395 100644 --- a/distribution/src/bin/elasticsearch.bat +++ b/distribution/src/bin/elasticsearch.bat @@ -50,7 +50,6 @@ if "%MAYBE_JVM_OPTIONS_PARSER_FAILED%" == "jvm_options_parser_failed" ( exit /b 1 ) -cd /d "%ES_HOME%" %JAVA% %ES_JAVA_OPTS% -Delasticsearch -Des.path.home="%ES_HOME%" -Des.path.conf="%ES_PATH_CONF%" -Des.distribution.flavor="%ES_DISTRIBUTION_FLAVOR%" -Des.distribution.type="%ES_DISTRIBUTION_TYPE%" -cp "%ES_CLASSPATH%" "org.elasticsearch.bootstrap.Elasticsearch" !newparams! endlocal diff --git a/qa/vagrant/src/main/java/org/elasticsearch/packaging/test/ArchiveTestCase.java b/qa/vagrant/src/main/java/org/elasticsearch/packaging/test/ArchiveTestCase.java index f6b231175e4..3d1e3bd0250 100644 --- a/qa/vagrant/src/main/java/org/elasticsearch/packaging/test/ArchiveTestCase.java +++ b/qa/vagrant/src/main/java/org/elasticsearch/packaging/test/ArchiveTestCase.java @@ -328,14 +328,14 @@ public abstract class ArchiveTestCase extends PackagingTestCase { } } - public void test100ElasticsearchShardCliPackaging() { + public void test91ElasticsearchShardCliPackaging() { assumeThat(installation, is(notNullValue())); final Installation.Executables bin = installation.executables(); final Shell sh = newShell(); Platforms.PlatformAction action = () -> { - final Result result = sh.run(bin.elasticsearchShard + " help"); + final Result result = sh.run(bin.elasticsearchShard + " -h"); assertThat(result.stdout, containsString("A CLI tool to remove corrupted parts of unrecoverable shards")); }; @@ -345,7 +345,7 @@ public abstract class ArchiveTestCase extends PackagingTestCase { } } - public void test110ElasticsearchNodeCliPackaging() { + public void test92ElasticsearchNodeCliPackaging() { assumeThat(installation, is(notNullValue())); final Installation.Executables bin = installation.executables(); @@ -363,4 +363,20 @@ public abstract class ArchiveTestCase extends PackagingTestCase { } } + public void test93ElasticsearchNodeCustomDataPathAndNotEsHomeWorkDir() throws IOException { + assumeThat(installation, is(notNullValue())); + + Path relativeDataPath = installation.data.relativize(installation.home); + append(installation.config("elasticsearch.yml"), "path.data: " + relativeDataPath); + + final Shell sh = newShell(); + sh.setWorkingDirectory(getTempDir()); + + Archives.runElasticsearch(installation, sh); + Archives.stopElasticsearch(installation); + + Result result = sh.run("echo y | " + installation.executables().elasticsearchNode + " unsafe-bootstrap"); + assertThat(result.stdout, containsString("Master node was successfully bootstrapped")); + } + }