Running two Alfresco Tomcat instances on one machine

Tomcat

Recently I had to split my Tomcat instance into two, because our production situation has it’s Share separate from Alfresco Repository.  As indicated by Jeff Pots in his 7 mistakes developers make when customizing Alfresco Share posting, having a single Tomcat (but deploying at a separate Share instance) is a source for error. This post describes how to split your single all-in-one Tomcat in a dedicated Alfresco Tomcat (running on port 8080), and a dedicated Share Tomcat instance (using on port 80).

(This post describes my development environment, don’t try this for production this way!)

Of course you started development having only 1 Tomcat instance, and now this is turning against you. Here is your rescue:

I start with a ‘standard’ Alfresco+Share, running in Tomcat. The file structure is:

/alfresco
/alfresco/tomcat
/alfresco/tomcat/webapps

Now, create the folders:

/share
/share/tomcat

Copy Tomcat’s subfolders bin, conf, endorsed, lib from /alfresco/tomcat to /share/tomcat
Create new subfolders;

/share/tomcat/shared
/share/tomcat/webapps

I usually run Alfresco in Command-boxes. Actually, I changed tomcat/bin/startup.bat the run mode from ‘start’ into ‘run’ (one of the last lines of the file). This prevents additional Command-boxes from popping up. This  line is now :

call "%EXECUTABLE%" run %CMD_LINE_ARGS%

Next, add a decent title in the Command-boxes, so we know what we are looking at:
Edit /alfresco/alfresco.bat
Add a line:

title Alfresco Explorer

Edit /share/alfresco.bat
Add a line:

title Alfresco Share

Also make sure (in /share/alfresco.bat) you set the current (Share) folder as ALF_HOME en CATALINA_HOME. I prefer to hard-coded the path. This is the first few lines of my bat file. (I also slimmed down the memory requirements for this instance of Tomcat…)

@echo off
 rem ---------------------------------------------------------------------------
 rem Start script for the Alfresco Server
 rem ---------------------------------------------------------------------------
 title Alfresco 345 Share

rem set Alfresco home (includes trailing \ e.g. c:\alfresco\)
 c:
 cd c:\bin\share
 set ALF_HOME=c:\bin\share\
 set CATALINA_HOME=c:\bin\share\tomcat

rem Set any default JVM options
 set JAVA_OPTS=-Xms512m -Xmx512m -Xss512k -XX:MaxPermSize=256m -XX:NewSize=256m -server -Dalfresco.home=%ALF_HOME% -Dcom.sun.management.jmxremote

Tweak the /share/tomcat/conf/server.xml
look for the string “8080”. We need to change this port number to port 80, since 8080 is already taken by the default install. I changed 8080 into 80, and 8443 into 9443


Also tweak the port number Tomcat uses to signal the shutdown message. Default is 8005, but that one is used by the original Alfresco already. I changed it into 9005


By default, Share will look at “localhost:8080/alfresco” for communication to the back-end. So, you’re lucky. Start Share, start Alfresco. Both should start up nicely. You should be able to access share by localhost/share (using your new Tomcat), and Alfresco Explorer using your good old localhost:8080/alfresco (using your ‘old’ Tomcat).

Now, kill both of your Tomcat processes, clean both of your tomcat/shared folders and deploy your Share config into share/tomcat, and your Alfresco tomcat into Alfresco/tomcat. Find out if you coded gently, if your build scripts packaged everything nicely and correct by testing your apps.

Remove share.war from alfresco/tomcat/webapps, as well as the folder alfresco/tomcat/webapps/share.
Remove alfresco.war from share/tomcat/webapps, as well as the folder share/tomcat/webapps/alfresco.
Remove alfresco/tomcat/shared/classes/alfresco/web-extension
Remove shared/tomcat/shared/classes/alfresco/extension
Remove alfresco/tomcat/shared/classes/alfresco/messages

My experience: Webscripts are fine, config is fine, and my DataTables are broken. Originally (in the 1 Tomcat-world) the front-end would ask for /alfresco/whatever/webscript and be served gently (over port 8080). We need to use the proxy url “/share/proxy/*” of course. Error fixed. Share happy. Me happy!

Remind: Skype is eager to use port 80: see menu tools – options – advanced – connection

Advertisements

8 Responses to “Running two Alfresco Tomcat instances on one machine”


  1. 1 wabson March 2, 2012 at 13:39

    Hi Tjarda, nice post, since I think this is generally not well documented.

    I’ve been using a similar set-up in my dev environment for a while now, but I only make a copy of the ‘tomcat’ directory (renamed to ‘tomcat-share’), and then I use the scripts inside it’s bin directory to start/stop it. It opens multiple windows, but that is fine for me since it allows me to monitor for errors.

    The issue I see with using a copy of alfresco.bat to start Share is that the memory allocation parameters set in JAVA_OPTs are very high for Share, which only requires modest resources. I think you could safely remove this line so that Tomcat uses the default settings.

    But overall I’d agree with you and Jeff. This is a great time-saving tip when you’re developing Share extensions, and it has the additional benefit that you can easily connect a Java debugger to Share without slowing down the repository itself.

  2. 2 Victor March 2, 2012 at 19:22

    Hi Tjara, useful post. Thank you. My coworker and I were excited to deploy share on a separate JVM so that it is feasible for faster development.

    BTW If you are running this on linux, you can avoid tweak TCP port numbers by using a virtual ip.

    http://www.appnovation.com/how-run-multiple-alfresco-server-instances-same-linux-machine
    I have tried on my ubuntu 11.10, it works like charm.

    Regards,
    Victor

  3. 3 sandy January 7, 2013 at 11:43

    I have written a Java based portable utility for automating the above steps for creating multiple instances. Since Java is platform independent, this utility works on all operating systems

  4. 5 Stefano February 25, 2013 at 16:12

    I’m just curious about wich of the tomcat/shared/alfresco folders keep alive on the two tomcat.
    Is it correct to keep just /alfresco/web-extension on the share instance?
    Does it break something?
    Because it’s a bit annoying copy-pasting the entire tomcat/shared folder on both tomcat.

    Any suggestion?

    Nice guide! 🙂

    • 6 Tjarda Peelen February 25, 2013 at 16:24

      You are right. The web-extension belongs to the Tomcat hosting Share (/share). The extension folder belongs to the Tomcat running the repository (/alfresco).

      Thanks! 😉

      • 7 Stefano February 27, 2013 at 12:09

        Noticed that (could be obvious) the folder shared/classes/alfresco/templates where custom ftl files is Share stuff too and goes in the Share tomcat instance.


  1. 1 Alfresco development using JRebel – less restarting, more focus « Open Source ECM Trackback on June 10, 2012 at 20:41
Comments are currently closed.