Heads up! These docs are for Portofino 3, which is a legacy product. Check out Portofino 4!

Posted by Angelo Lupo
on May 12th, 2010



Occasionally, you may want to run many instances of Portofino to support different business processes. As an example, there could be one instance for a CRM, another one for an employee directory, and a third one for a product/supplier database. As another example there could be just one application but deployed three times for three different customers.

There are two options:

  • Deploying the Portofino war three times. We'll end up with three separate directories containing the expanded war.
  • Expanding the Portofino war once and creating three instances (three web application contexts) that point to the same directory.

In this tutorial I'll explain the latter option. This can be useful to manage Portofino's installations centrally: e.g., if I upgrade to a newer version of Portofino, I only need to change one expanded war.

 

The set-up

We are going to build an example with three instances running at the following urls:

  • http://127.0.0.1/instance1
  • http://127.0.0.1/instance2
  • http://127.0.0.1/instance3

The three instances will share the same expanded war, but can be configured to point to different databases, so we have three completely different applications based on Portofino.

Installing Portofino

Manually unpack the portofino.war (as a zip file) into a directory of your choice (e.g.c:\programs\portofino).

Create a Portofino configuration file (portofino-custom.properties)  for each instance in a dedicated directory of your choice (e.g. c:\programs\portofino-settings). The folder c:\programs\portofino-settings will have the following files:

  • instance1-portofino-custom.properties
  • instance2-portofino-custom.properties
  • instance3-portofino-custom.properties

Configure each of the files as you would normally, pointing to different databases.

Configuring Tomcat 6

For a complete reference on Apache Tomcat's configuration and usage, see the official documentation.

We are going to create a context for each instance under apache-tomcat\conf\Catalina\. In each file we will set the same docbase (c:\programs\portofino), and an enviroment variable with the path to the specific portofino-custom.properties.

For the first instance:

Create the file c:\programs\apache-tomcat\conf\Catalina\localhost\instance1.xml

<?xml version="1.0" encoding="UTF-8"?>
<Context
  docBase="c:\programs\portofino"
  crossContext="false"
  privileged="false"
  reloadable="false">

<!-- pointer to the configuration file of Portofino -->
<Environment name="portofino-custom.properties"
  value="c:\programs\portofino-settings\instance1-portofino-custom.properties"
  type="java.lang.String" override="false"/>
</Context>

For the second instance:

Create the file c:\programs\apache-tomcat\conf\Catalina\localhost\instance2.xml

<?xml version="1.0" encoding="UTF-8"?>
<Context
  docBase="c:\programs\portofino"
  crossContext="false"
  privileged="false"
  reloadable="false">

<!-- pointer to the configuration file of Portofino -->
<Environment name="portofino-custom.properties"
  value="c:\programs\portofino-settings\instance2-portofino-custom.properties"
  type="java.lang.String" override="false"/>
</Context>

For the third instance:

Create the file c:\programs\apache-tomcat\conf\Catalina\localhost\instance3.xml 

<?xml version="1.0" encoding="UTF-8"?>
<Context
  docBase="c:\programs\portofino"
  crossContext="false"
  privileged="false"
  reloadable="false">

<!-- pointer to the configuration file of Portofino -->
<Environment name="portofino-custom.properties"
  value="c:\programs\portofino-settings\instance3-portofino-custom.properties"
  type="java.lang.String" override="false"/>
</Context>

Restart Tomcat

Restart your Tomcat, start your browser and then you'll find the three instances available at the desired URLs: http://127.0.0.1/instance1, http://127.0.0.1/instance2 and http://127.0.0.1/instance3.

One caveat

Sharing one war directory means sharing all of its contents, including any customizations. So the approach I've described works only if you use the standard Portofino war, without customizations or with the same customizations for all apps.

On the other hand, if you need different customizations for the various application instances your best option is to deploy three different (customized) wars.