Skip to content

Commit d35d9d1

Browse files
author
Andrey Ershov
committed
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 2ffc293 with fixes by #40083 and #40118)
1 parent 5be12e0 commit d35d9d1

File tree

5 files changed

+23
-5
lines changed

5 files changed

+23
-5
lines changed

distribution/src/bin/elasticsearch

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ ES_JVM_OPTIONS="$ES_PATH_CONF"/jvm.options
2020
JVM_OPTIONS=`"$JAVA" -cp "$ES_CLASSPATH" org.elasticsearch.tools.launchers.JvmOptionsParser "$ES_JVM_OPTIONS"`
2121
ES_JAVA_OPTS="${JVM_OPTIONS//\"\$\{ES_TMPDIR\}\"/$ES_TMPDIR} $ES_JAVA_OPTS"
2222

23-
cd "$ES_HOME"
2423
# manual parsing to find out, if process should be detached
2524
if ! echo $* | grep -E '(^-d |-d$| -d |--daemonize$|--daemonize )' > /dev/null; then
2625
exec \

distribution/src/bin/elasticsearch-env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,5 @@ ES_DISTRIBUTION_TYPE=${es.distribution.type}
8686
if [ -z "$ES_TMPDIR" ]; then
8787
ES_TMPDIR=`"$JAVA" -cp "$ES_CLASSPATH" org.elasticsearch.tools.launchers.TempDirectory`
8888
fi
89+
90+
cd "$ES_HOME"

distribution/src/bin/elasticsearch-env.bat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,5 @@ set ES_DISTRIBUTION_TYPE=${es.distribution.type}
6060
if not defined ES_TMPDIR (
6161
for /f "tokens=* usebackq" %%a in (`"%JAVA% -cp "!ES_CLASSPATH!" "org.elasticsearch.tools.launchers.TempDirectory""`) do set ES_TMPDIR=%%a
6262
)
63+
64+
cd /d "%ES_HOME%"

distribution/src/bin/elasticsearch.bat

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ if "%MAYBE_JVM_OPTIONS_PARSER_FAILED%" == "jvm_options_parser_failed" (
5050
exit /b 1
5151
)
5252

53-
cd /d "%ES_HOME%"
5453
%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!
5554

5655
endlocal

qa/vagrant/src/main/java/org/elasticsearch/packaging/test/ArchiveTestCase.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,14 +328,14 @@ public void test90SecurityCliPackaging() {
328328
}
329329
}
330330

331-
public void test100ElasticsearchShardCliPackaging() {
331+
public void test91ElasticsearchShardCliPackaging() {
332332
assumeThat(installation, is(notNullValue()));
333333

334334
final Installation.Executables bin = installation.executables();
335335
final Shell sh = newShell();
336336

337337
Platforms.PlatformAction action = () -> {
338-
final Result result = sh.run(bin.elasticsearchShard + " help");
338+
final Result result = sh.run(bin.elasticsearchShard + " -h");
339339
assertThat(result.stdout, containsString("A CLI tool to remove corrupted parts of unrecoverable shards"));
340340
};
341341

@@ -345,7 +345,7 @@ public void test100ElasticsearchShardCliPackaging() {
345345
}
346346
}
347347

348-
public void test110ElasticsearchNodeCliPackaging() {
348+
public void test92ElasticsearchNodeCliPackaging() {
349349
assumeThat(installation, is(notNullValue()));
350350

351351
final Installation.Executables bin = installation.executables();
@@ -363,4 +363,20 @@ public void test110ElasticsearchNodeCliPackaging() {
363363
}
364364
}
365365

366+
public void test93ElasticsearchNodeCustomDataPathAndNotEsHomeWorkDir() throws IOException {
367+
assumeThat(installation, is(notNullValue()));
368+
369+
Path relativeDataPath = installation.data.relativize(installation.home);
370+
append(installation.config("elasticsearch.yml"), "path.data: " + relativeDataPath);
371+
372+
final Shell sh = newShell();
373+
sh.setWorkingDirectory(getTempDir());
374+
375+
Archives.runElasticsearch(installation, sh);
376+
Archives.stopElasticsearch(installation);
377+
378+
Result result = sh.run("echo y | " + installation.executables().elasticsearchNode + " unsafe-bootstrap");
379+
assertThat(result.stdout, containsString("Master node was successfully bootstrapped"));
380+
}
381+
366382
}

0 commit comments

Comments
 (0)