Skip to content

Commit 2ffc293

Browse files
authored
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.
1 parent 74ba9ce commit 2ffc293

File tree

5 files changed

+22
-5
lines changed

5 files changed

+22
-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: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,14 +317,14 @@ public void test90SecurityCliPackaging() {
317317
}
318318
}
319319

320-
public void test100ElasticsearchShardCliPackaging() {
320+
public void test91ElasticsearchShardCliPackaging() {
321321
assumeThat(installation, is(notNullValue()));
322322

323323
final Installation.Executables bin = installation.executables();
324324
final Shell sh = new Shell();
325325

326326
Platforms.PlatformAction action = () -> {
327-
final Result result = sh.run(bin.elasticsearchShard + " help");
327+
final Result result = sh.run(bin.elasticsearchShard + " -h");
328328
assertThat(result.stdout, containsString("A CLI tool to remove corrupted parts of unrecoverable shards"));
329329
};
330330

@@ -334,7 +334,7 @@ public void test100ElasticsearchShardCliPackaging() {
334334
}
335335
}
336336

337-
public void test110ElasticsearchNodeCliPackaging() {
337+
public void test92ElasticsearchNodeCliPackaging() {
338338
assumeThat(installation, is(notNullValue()));
339339

340340
final Installation.Executables bin = installation.executables();
@@ -352,4 +352,19 @@ public void test110ElasticsearchNodeCliPackaging() {
352352
}
353353
}
354354

355+
public void test93ElasticsearchNodeCustomDataPathAndNotEsHomeWorkDir() throws IOException {
356+
assumeThat(installation, is(notNullValue()));
357+
358+
Path relativeDataPath = installation.data.relativize(installation.home);
359+
append(installation.config("elasticsearch.yml"), "path.data: " + relativeDataPath);
360+
361+
Archives.runElasticsearch(installation);
362+
Archives.stopElasticsearch(installation);
363+
364+
final Shell sh = new Shell(getTempDir());
365+
366+
Result result = sh.run("echo y | " + installation.executables().elasticsearchNode + " unsafe-bootstrap");
367+
assertThat(result.stdout, containsString("Master node was successfully bootstrapped"));
368+
}
369+
355370
}

0 commit comments

Comments
 (0)