问题
I understand that logstash now supports environment variables in config, as described here.
But I can't seem to get it working when running logstash as a service. I am on ubuntu 14.04, logstash 1:2.3.3-1, and I launch logstash with sudo service logstash start
.
A final twist is that I am including logstash in a docker container, and I do NOT want to hardcode the variable value in my Dockerfile, I want it to ultimately be sourced from the command line when I launch the container, e.g. docker run -e ES_HOST='my_host' ...etc...
. This is really the main reason I want to use environment variables.
However the value does not seem to be making it all the way to logstash:
#<LogStash::ConfigurationError: Host '${ES_HOST}:443' was specified, but is not valid! Use either a full URL or a hostname:port string!>
Even taking the docker out of the mix, I cannot seem to get logstash to see the enviroment vars when I run it as a service. I found this about making environment variables available to services in ubuntu, so I added this line to the end of /etc/default/logstash
:
ES_HOST=my_host
And I even inserted this into the /etc/init.d/logstash to make sure it was getting set:
[ -f /etc/default/logstash ] && . /etc/default/logstash
if [ -z "$ES_HOST" ] ; then
echo "ES_HOST is not set, please set it in /etc/default/logstash" >&2
exit 1
fi
But logstash still gives the same error, complaining that Host '${ES_HOST}:443' was specified, but is not valid!
FYI the output section from my logstash config in /etc/logstash/conf.d/my-config
looks like this:
output {
elasticsearch {
hosts => ["${ES_HOST}:443"]
ssl => true
}
}
来源:https://stackoverflow.com/questions/38064309/environment-variable-replacement-in-logstash-when-running-as-a-service-in-ubuntu