Debian – How to override default `solr.home` in XML files under `Catalina/localhost`

debianenvironment-variablessolrtomcattomcat7

I'm trying to configure two instances of Solr on the same host and I'd like to override solr.home for each instance.

I've created two files under Catalina/localhost/ as suggested in Solr Tomcat wiki:

$ cat solr-prod.xml 
<Context docBase="webapps/solr-prod.war" debug="0" crossContext="true" >
   <Environment name="solr/home" type="java.lang.String" value="/opt/solr-prod/home" override="true" />
</Context>
$ cat solr-qa.xml 
<Context docBase="webapps/solr-qa.war" debug="0" crossContext="true" >
   <Environment name="solr/home" type="java.lang.String" value="/opt/solr-qa/home" override="true" />
</Context>

Btw. I've tried to use absolute path, but without success.

However upon Tomcat restart, it's ignoring my configuration:

$ sudo sh -x /etc/init.d/tomcat7 start
...
+ catalina_sh start
+ sed s/\"/\\\"/g
+ echo -Djava.awt.headless=true -Dsolr.solr.home=/opt/solr/home -Dsolr.data.dir=/opt/solr/data -Xmx128m -XX:+UseConcMarkSweepGC
+ JAVA_OPTS=-Djava.awt.headless=true -Dsolr.solr.home=/opt/solr/home -Dsolr.data.dir=/opt/solr/data -Xmx128m -XX:+UseConcMarkSweepGC

by setting its own -Dsolr.solr.home and -Dsolr.solr.home which I don't know from where it's coming.

The above configuration files are loaded and running according to Tomcat Web Application Manager at /manager/html.

The problem is when I'm accessing my Solr4 instances via web I can see that Args are set for both of them to:

-Dsolr.data.dir=/opt/solr/data
-Dsolr.solr.home=/opt/solr/home

So it seems that my environment variable is ignored for some reason and it's overridden by argument.

I don't have /opt/solr argument hardcoded anywhere either within /var/lib/tomcat7, /usr/share/tomcat7 or in WEB-INF/web.xml (which is commented).

Any ideas how to set-up these environment variables correctly?

Best Answer

I've found these default settings for solr.home and solr.data in /etc/default/tomcat7.

Other possible locations could be in: /usr/share/tomcat7/defaults.template as part of JAVA_OPTS.

Removing solr variables from there, it allows to use separate solr instances as per config files defined in conf/Catalina/localhost.

So for each instance, separate XML files should be created.

For example:

<Context docBase="webapps/solr.war" debug="0" crossContext="true" >
   <Environment name="solr/home" type="java.lang.String" value="/opt/solr/home" override="true" />
</Context>

where value of solr/home is the path to solr, either /opt/solr/home or /var/lib/solr (whatever path you have or already chosen).