Plugin Development: access command line arguments

Hello,

From inside a plugin, I need to get a grip of what's the absolute path of elasticsearch.yml.

motivation: I need my plugin's settings file to sit side-by-side in the config dir beside elasticsearch.yml

I can understand what's the path of the ES_HOME like this:

System.getProperty("es.path.home");

But this doesn't tell you much about the config directory is going to be. And that's because there is a command line option, namely -Epath.conf=/x/y/z that can move the config directory anywhere else and the plugin will know nothing about it.

Currently there is no Java API to get the "argv" command line arguments array of the current process (except for the JVM options).

So: How to get the value of -Epath.conf from a plugin?

You didn't mention which version of elasticsearch you are writing this plugin for. Assuming that this is something recent (5.x or above) you can get this information from Environment, which is passed as one of the parameters to the createComponents calls.

Thanks Igor!

I noticed in 6.x it's available, but In the current 5.6.3 Environment is not yet available. Any other route?

Yes, in 5.x you need to do this:

public class JvmExamplePlugin extends Plugin implements ActionPlugin {
    /* ..... */

    public JvmExamplePlugin(Settings settings) {
        Environment environment = new Environment(settings);
        /* ..... */
     }

     /* ..... */
}
1 Like

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