Use Env variable causing Elasticsearch not to start

I have added an env variable in elasticsearch.yml file as follows

http.port: ${PORT}

I am able to retrieve the value of this variable when I echo the value of the variable

echo $PORT
9200

But the Elasticsearch do not start with this configuration. Infact it do not start at when I use ${} values and only does when i comment it out or substitute it with actual values.

Please help me with any configuration that I am missing.

Thank you

I'm doing exactly the same and it works for me, but you must remember to export PORT in the environment of the user that starts Elasticsearch which may be a different user from the one you're logged in as.

One way around this problem is to use a wrapper script to set the environment variable and start Elasticsearch. For instance a start-es.sh with this content:

#!/bin/bash

export PORT=9255          # http.port
export TCP_PORT=9355      # transport.tcp.port

#now start Elasticsearch as a daemon process:
/basedir/es6.5.4/bin/elasticsearch -d -p /basedir/pids/es.pid 2>/basedir/logs/es.stderr

Then you just run ./start.es.sh when you want to start Elasticsearch with the right PORT setting.

Of course, you can then expand the script to add even more environment variables, for instance node and cluster name, zen discovery hosts, data path etc making elasticsearch.yml completely generic across all nodes and even across clusters, making maintenance a breeze.

Good luck!

Found the solution for this
As mentioned the below link

As I am running elasticsearch as a linux service, rather than a shell application, it has access to no environment variables except for a very select few.

I added the following line to the end of /etc/sysconfig/elasticsearch to load the environment variables I wanted available to the program:

. /path/to/environment/variables

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.