Skip to content

Commit

Permalink
Export HOSTNAME environment variable
Browse files Browse the repository at this point in the history
We previously explicitly set the HOSTNAME environment variable so that
${HOSTNAME} could be used a placeholder for defining the node.name in
elasticsearch.yml. We removed explicitly setting this because bash
defines HOSTNAME. The problem is that bash defines HOSTNAME as a bash
variable, not as an environment variable. Therefore, to restore the
previous behavior, we export the bash value for HOSTNAME as an
environment variable named HOSTNAME. For consistency between Windows and
the Unix-like systems, we also define HOSTNAME with a value equal to the
environment variable COMPUTERNAME on Windows.

Relates #26262
  • Loading branch information
jasontedor committed Aug 17, 2017
1 parent 60968f2 commit 99b91df
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions distribution/src/main/resources/bin/elasticsearch-env
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ fi
# check the Java version
"$JAVA" -cp "$ES_CLASSPATH" org.elasticsearch.tools.JavaVersionChecker

export HOSTNAME=$HOSTNAME

${source.path.env}

if [ -z "$ES_PATH_CONF" ]; then
Expand Down
2 changes: 2 additions & 0 deletions distribution/src/main/resources/bin/elasticsearch-env.bat
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ if not "%JAVA_OPTS%" == "" (
rem check the Java version
%JAVA% -cp "%ES_CLASSPATH%" "org.elasticsearch.tools.JavaVersionChecker" || exit /b 1

set HOSTNAME=%COMPUTERNAME%

if "%ES_PATH_CONF%" == "" (
set ES_PATH_CONF=!ES_HOME!\config
)
Original file line number Diff line number Diff line change
Expand Up @@ -450,3 +450,15 @@ fi
@test "[$GROUP] test umask" {
install_jvm_example $(readlink -m jvm-example-*.zip) 0077
}

@test "[$GROUP] hostname" {
local temp=`mktemp -d`
cp "$ESCONFIG"/elasticsearch.yml "$temp"
echo 'node.name: ${HOSTNAME}' >> "$ESCONFIG"/elasticsearch.yml
start_elasticsearch_service
wait_for_elasticsearch_status
[ "$(curl -XGET localhost:9200/_cat/nodes?h=name)" == "$HOSTNAME" ]
stop_elasticsearch_service
cp "$temp"/elasticsearch.yml "$ESCONFIG"/elasticsearch.yml
rm -rf "$temp"
}

0 comments on commit 99b91df

Please sign in to comment.