Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use environment variables within solrconfig.xml for dataDir variable?

Tags:

solr

We have a situation where we have to maybe create multiple instances of Solr/Tomcat running on different ports on either a single machine or several different machines. Towards doing this I was wondering if it's possible to specify the dataDir variable (within solrconfig.xml) using an environmentvariable for example like so: <dataDir>${envvar}/path/to/index</dataDir>.

like image 536
Ramdev Avatar asked Feb 06 '12 15:02

Ramdev


1 Answers

Yes, you can do this, but you need to do jump through a couple hoops to set this up using system properties passed to the JVM when you start it.

Anywhere you want your environment variable to work in your configuration files, put the variable like this:

${VAR}

Then, when you start your JVM, pass it the variable by doing:

java -DVAR=$your-system-variable

So, to make this concrete, here's what we do:

java -DINSTALL_ROOT=$INSTALL_ROOT -jar -server start.jar

And our config has something like:

<filter class="solr.SynonymFilterFactory" synonyms=${INSTALL_ROOT}/Solr/conf/synonyms.txt />

Works like a charm.

like image 144
mlissner Avatar answered Oct 07 '22 04:10

mlissner