Java not found when executing script that needs Java

After upgrading to Logstash 8.11.3, our Logstash stopped working because it can no longer execute a script that needs Java. I believe this is caused by Logstash now using it's internally shipped JDK.

Logstash Exec Input Plugin Configuration

exec {
  command => '/ourpath/wildfly/bin/jboss-cli.sh --controller=localhost:9990 --user=admin --password=******** --connect --command="/subsystem=datasources/data-source=OurDS/statistics=pool:read-resource(include-runtime=true)" --output-json'
  interval => 30
}

Error

/ourpath/wildfly/bin/jboss-cli.sh: line 88: exec: java: not found

We made Logstash echo JAVA, JAVA_HOME and other variables to see what it can see, and it looks like it sees nothing.

This did work on our previous Logstash version, which I'm guessing was 8.7.0.

Anyone have any ideas how to fix this?

Potential solutions we have though about:

  • Not using the internal Logstash JDK, but this seems like bad practice.
  • Manually setting variables for Logstash, such as JAVA, JAVA_HOME, pointing to our local JDK.

If you configure

exec { command => "env" schedule => "* * * * *" }
filter {
    mutate { split => { "message" => "
" } }
}

you will see that JAVACMD points to the Java executable. This gets configured by /usr/share/logstash/bin/bin/logstash.lib.sh

1 Like

So would you suggest editing the jboss-cli.sh script to use Logstash's Java executable instead?

That's one option. Another would be to create a wrapper that parses the directory from JAVACMD and adds it to PATH. Then invoke the wrapper from the exec input. There are many ways to get what you want.

1 Like