Upstart script should use set -a before loading /etc/default/logstash
- Dominant language
- Java
- Stars
- 14.9k
- Forks
- 3.5k
- Avg merge
- 19h 14m
- Merged PRs (30d)
- 63
Description
- Version: Logstash 5.1.1
- Operating System: CentOS/RHEL 6.8 (Upstart)
- Config File:
input {
beats {
port => "${TCP_PORT}"
}
}
output {
}
- Steps to Reproduce:
If you set your environment variables in /etc/default/logstash or /etc/sysconfig/logstash as based on the upstart script:
script
[ -r "/etc/default/logstash" ] && . "/etc/default/logstash"
[ -r "/etc/sysconfig/logstash" ] && . "/etc/sysconfig/logstash"
exec chroot --userspec logstash:logstash / /usr/share/logstash/bin/logstash "--path.settings" "/etc/logstash" >> /var/log/logstash-stdout.log 2>> /var/log/logstash-stderr.log
end script
The problem here is that if you use the convention of TCP_PORT=1234 then this doesn't work:
[root@localhost logstash]# cat /etc/default/logstash
TCP_PORT=1234
[root@localhost logstash]# initctl start logstash
logstash start/running, process 38564
[root@localhost logstash]# tail -1 logstash-plain.log
[2016-12-14T07:59:38,147][ERROR][logstash.agent ] fetched an invalid config {:config=>"input {\n beats {\n port => \"${TCP_PORT}\"\n }\n}\n\nfilter {\n mutate {\n add_field => { \"beat\" => \"%{[@metadata][beat]}\" } \n }\n}\n\noutput {\n# if \"metric\" in [tags] {\n# stdout {\n# codec => line {\n# format => \"Rate: %{[events][rate_1m]}\"\n# }\n# }\n# } else {\n# null {\n# workers => 2\n# }\n# stdout { codec => rubydebug }\n# }\n# elasticsearch {\n# hosts => [ \"${HOST}:9200\" ]\n# } \n}\n\n\n", :reason=>"Cannot evaluate `${TCP_PORT}`. Environment variable `TCP_PORT` is not set and there is no default value given."}
However if specify set -a prior to loading /etc/default/logstash then it works:
[root@localhost logstash]# tail -5 /etc/init/logstash.conf
set -a
[ -r "/etc/default/logstash" ] && . "/etc/default/logstash"
[ -r "/etc/sysconfig/logstash" ] && . "/etc/sysconfig/logstash"
exec chroot --userspec logstash:logstash / /usr/share/logstash/bin/logstash "--path.settings" "/etc/logstash" >> /var/log/logstash-stdout.log 2>> /var/log/logstash-stderr.log
end script
[root@localhost logstash]# initctl start logstash
logstash start/running, process 38956
[root@localhost logstash]# netstat -an | grep :1234
tcp 0 0 :::1234 :::* LISTEN
[2016-12-14T08:08:13,452][INFO ][logstash.inputs.beats ] Beats inputs: Starting input listener {:address=>"0.0.0.0:1234"}
Contributor guide
Assessment
This issue has not been assessed yet.