wiki:HowToRunMultipleGeonetworkInstancesUnderTomcat

How to run Multiple instances of GeoNetwork in a single Tomcat server

What is it you want to do?

When GeoNetwork is installed it typically becomes available at the URL http://domain.etc:8080/geonetwork. If you want a second copy running you might start a second instance of tomcat on another port e.g. http://domain.etc:8090/geonetwork. Instead I want to be able to run both copies in the same Tomcat server at different names rather than ports. e.g. http://domain.etc/geonetwork_test, http://domain.etc/geonetwork etc.

Why would you want to do this?

  1. You may wish to run several separate copies of GeoNetwork for test and development purposes. e.g a dev, test and production version. Each instance can be started and stopped independently, can connect to different schemas on the database etc.
  1. You may wish to run two separate portals for GeoNetwork containing different collections of metadata from two organisations. You may wish to have separate branding and titles.

Summary of changes

  • set the application name in web.xml
  • set the application name in index.html
  • set the database
  • add the instance to tomcat server.xml

These changes can be made in the original source code or after installation as a post install customisation. For the purposes of this how to I will assume the following :

The Steps

Duplicate the installation

cd /usr/local
cp -r geonetwork geonetwork_test

or you can run the installer a second time.

Set the application name in web.xml

The display-name entry in the web app xml configuration file is used extensively through GeoNetwork as the base url for links and resources.

  • edit web/geonetwork_test/WEB-INF/web.xml
  • replace <display-name>geonetwork</display-name> with <display-name>geonetwork_test</display-name> at about line 4
  • replace /geonetwork/ with /geonetwork_test/ in the parameters section further down.
        <param-name>urls-to-expire-forward</param-name>
        <param-value>/geonetwork/scripts,/geonetwork/images,/geonetwork/loc</param-value>
    

For those who like regular expressions the following sed script makes these two changes:

$NAME = geonetwork_test
sed -e "s/\(<display-name>\).*\(<\/display-name>\)/\1$NAME\2/"  -e "s/\(<param-value>\/\).*\(\/scripts,\/\).*\(\/images,\/\).*\(\/loc<\/param-value>\)/\1$NAME\2$NAME\3$NAME\4/" web/geonetwork/WEB-INF/web.xml 

Set the application name in index.html

The root folder index.html file ensures that links to http://domain.etc/geonetwork are redirected to http://domain.etc/geonetwork/srv/en/main.home

  • edit web/geonetwork_test/index.html
  • replace the line with window.location=geonetwork... with the new path
$NAME = geonetwork_test
sed -e "s/\(window.location=\"\/\).*\(\/srv\/en\/main.home\)/\1$NAME\2/" $NAME/web/geonetwork/index.html 

Set the database

Run bin/gast.sh and setup the database so that it uses a different database name. You can then use gast to initialise the new database. Alternatively directly edit the file /web/geonetwork/WEB-INF/config.xml. Look for the <resources> <resource enabled="true"> element to change the database settings.

add the instance to tomcat server.xml

There are a couple of ways to add services to the tomcat server, you can add separate host server.xml files into folders or you can add Context lines to the main server.xml file. This how to assumes the latter.

Add or modify the following code to the file /opt/tomcat/current/conf/server.xml. I'm assuming that both GeoNetwork services will share the same GeoServer.

<!-- Define the default virtual host  -->
  <Host name="localhost"  appBase="webapps"  unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
    <!-- Metadata Catalog - supporting services -->
    <Context path="/geoserver" docBase="/usr/local/geonetwork/web/geoserver" crossContext="false"  reloadable ="false" />
    
    <!-- Metadata Catalog !GeoNetwork -->
    <Context path="/geonetwork"      docBase="/usr/local/geonetwork/web/geonetwork" crossContext="false" reloadable="false" />
    <Context path="/geonetwork_test" docBase="/usr/local/geonetwork_test/web/geonetwork" crossContext="false" reloadable="false" />
  </Host>

Branding the different versions

For me the simplest way to brand the versions was to add an H1 title to the banner that shows the values of the administrative setting for name and organisation.

in web/geonetwork/xsl/banner.xsl

 <tr class="banner">
   <td class="banner">
       <h1 id="logo"><span><xsl:value-of select="//site/organization"/> - <xsl:value-of select="//site/name"/></span></h1>
   </td>
 </tr>

Andrew Watkins is Systems Development Team Manager at the National Institute of Water and Atmospheric Research (NIWA) in New Zealand

Last modified 6 years ago Last modified on Nov 7, 2013, 8:59:30 AM