Logstash can't read the environment variable

Good day everyone!

Need some help here.

On my dev environment, checking the logstash configuration will show this error.

root@devlogstash:~# /usr/share/logstash/bin/logstash --path.settings /etc/logstash -t
OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
Sending Logstash logs to /var/log/logstash which is now configured via log4j2.properties
[2021-10-18T05:17:56,572][INFO ][logstash.runner          ] Starting Logstash {"logstash.version"=>"7.9.2", "jruby.version"=>"jruby 9.2.13.0 (2.5.7) 2020-08-03 9a89c94bcc OpenJDK 64-Bit Server VM 11.0.11+9-Ubuntu-0ubuntu2.20.04 on 11.0.11+9-Ubuntu-0ubuntu2.20.04 +indy +jit [linux-x86_64]"}
[2021-10-18T05:17:59,039][FATAL][logstash.runner          ] The given configuration is invalid. Reason: Unable to configure plugins: Cannot evaluate `${HSTNM}`. Replacement variable `HSTNM` is not defined in a Logstash secret store or an environment entry and there is no default value given.
[2021-10-18T05:17:59,047][ERROR][org.logstash.Logstash    ] java.lang.IllegalStateException: Logstash stopped processing because of an error: (SystemExit) exit

The variable though was already declared on /etc/default/logstash.

root@devlogstash:~# cat /etc/default/logstash |grep HSTNM
HSTNM="devlogstash"

Please advise on how to fix this error.

I don't think /etc/default/logstash is the right place to store an environment variable. /etc/environment or .bashrc and .profile are the places where environment variables are usually stored.
I took a quick look through the code and the only reference to /etc/default/logstash is in the installation scripts.
Have you tried doing: export HSTNM="devlogstash" before running logstash?

@AquaX thank you so much for the info. I'll check it out!

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