Skip to content

Commit d857033

Browse files
committed
Fix using relative custom config path
Previously a user could set a custom config path to a relative directory using ES_PATH_CONF. In a previous change related to enabling GC logging by default, we forced the working directory for Elasticsearch to be ES_HOME. This had the impact of causing all relative paths to be relative to ES_HOME, against the intent of the user. This commit addresses this by making ES_PATH_CONF absolute before we switch the working directory to ES_HOME. Relates #28700
1 parent ff762a9 commit d857033

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

distribution/src/main/resources/bin/elasticsearch-env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ if [ -z "$ES_PATH_CONF" ]; then
7474
exit 1
7575
fi
7676

77+
# now make ES_PATH_CONF absolute
78+
ES_PATH_CONF=`cd "$ES_PATH_CONF"; pwd`
79+
7780
if [ -z "$ES_TMPDIR" ]; then
7881
set +e
7982
mktemp --version 2>&1 | grep coreutils > /dev/null

distribution/src/main/resources/bin/elasticsearch-env.bat

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ if not defined ES_PATH_CONF (
5050
set ES_PATH_CONF=!ES_HOME!\config
5151
)
5252

53+
rem now make ES_PATH_CONF absolute
54+
for %%I in ("%ES_PATH_CONF%..") do set ES_PATH_CONF=%%~dpfI
55+
5356
if not defined ES_TMPDIR (
5457
set ES_TMPDIR=!TMP!\elasticsearch
5558
)

qa/vagrant/src/test/resources/packaging/tests/20_tar_package.bats

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,23 @@ setup() {
139139
stop_elasticsearch_service
140140
}
141141

142+
@test "[TAR] relative ES_PATH_CONF" {
143+
local es_path_conf=$ES_PATH_CONF
144+
local temp=`mktemp -d`
145+
mkdir "$temp"/config
146+
cp "$ESCONFIG"/elasticsearch.yml "$temp"/config
147+
cp "$ESCONFIG"/log4j2.properties "$temp"/config
148+
cp "$ESCONFIG/jvm.options" "$temp/config"
149+
chown -R elasticsearch:elasticsearch "$temp"
150+
echo "node.name: relative" >> "$temp"/config/elasticsearch.yml
151+
cd "$temp"
152+
export ES_PATH_CONF=config
153+
start_elasticsearch_service
154+
curl -s -XGET localhost:9200/_nodes | fgrep '"name":"relative"'
155+
stop_elasticsearch_service
156+
export ES_PATH_CONF=$es_path_conf
157+
}
158+
142159
@test "[TAR] remove tar" {
143160
rm -rf "/tmp/elasticsearch"
144161
}

0 commit comments

Comments
 (0)