Thursday, July 31, 2008

Running Two Tomcat Service Instances On The Same Machine

I saw this question on a forum recently and though the requirement may not be very common, it was certainly an interesting idea. At first I thought it wasn't possible but after little tampering with the registry, it turned out to be quite easy to achieve.

 Editing the registry is risky! If you're unsure or can't live with the consequences, don't do it. And remember, ALWAYS BACKUP!

The instructions below are for Tomcat 6.0 which is installed as service on a Windows [XP] machine.

To begin with, these are the keys that are created by the Tomcat installer in the registry; you'll need to modify them. I'll refer to them by their numbers in the steps.

I. HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet \Services\Tomcat6
II. HKEY_LOCAL_MACHINE\SOFTWARE\Apache Software Foundation\Procrun 2.0\Tomcat6
III. HKEY_LOCAL_MACHINE\SOFTWARE\Apache Software Foundation\Tomcat\6.0
IV. HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows \CurrentVersion\Run
V. HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows \CurrentVersion\Uninstall\Apache Tomcat 6.0
VI. HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum \Root\LEGACY_TOMCAT6

  1. Install your first instance of Tomcat to, say, C:\Tomcat6_1
  2. Start > Run > regedit > [ENTER] will bring up the registry editor
  3. Navigate to key I and rename it from [...]Tomcat6 to, say, [...]Tomcat6_1. This will ensure the next install will not overwrite this key
  4. You should see the values for this key in the right pane; modify DisplayName from Apache Tomcat to, say, Apache Tomcat 1. This is so that you know which service is which later, in the Services console (Start > Run > services.msc > [ENTER])
  5. Modify the ImagePath value from [...]//RS//Tomcat6 to [...]//RS//Tomcat6_1. This is the name of the service instance that will be started; we'll need this name later so keep it in mind
  6. The Enum key under key I has a value 0 which points to key VI. Change the data to reflect the change in the key name that you'll be making later i.e. modify Root\LEGACY_TOMCAT6\0000 to Root\LEGACY_TOMCAT6_1\0000
  7. Navigate to key II and rename it also; from [...]Tomcat6 to [...]Tomcat6_1. Again, this is to avoid overwriting when installing the second service
  8. Similarly, modify key III from [...]6.0 to [...]6.0_1. Same reason as above
  9. Navigate to key IV and modify the value (not the value's data) from ApacheTomcatMonitor to ApacheTomcatMonitor_1. This key is for the monitor application; modifying the key will avoid overwriting of the key on the second install and you'll be able to run two instances of the monitor, one for each service
  10. Now you modify the data of this value; [...]//MS//Tomcat6 to [..]//MS//Tomcat6_1. This is the name of the service that you modified above, for the ImagePath value
  11. If you want to be able to uninstall both the instances of Tomcat later (recommended!), you need to modify key V and rename it from [...]Apache Tomcat 6.0 to [...]Apache Tomcat 6.0_1. Again, to avoid overwriting of the uninstall information
  12. I'm not very sure about key VI but I suggest you modify it also. Rename it from [..]LEGACY_TOMCAT6 to [..]LEGACY_TOMCAT6_1
  13. Restart your system now for the changes to take place
  14. Once you're sure the current install is working as expected, you can install the second instance of your Tomcat. I installed to C:\Tomcat6_2
  15. Before you start the second service, you need to change the ports since otherwise it's going to start with exactly the same ones as your first service and throw exceptions and quit. (You could've changed the HTTP listen port while installing) You need to change the HTTP and SHUTDOWN listen ports at least. If either of these is the same or bound to some other process, Tomcat will not start.
    1. Go to $CATALINA_HOME\conf\server.xml ($CATALINA_HOME refers to the Tomcat install directory)
    2. Modify the value for <Server port="8005" shutdown="SHUTDOWN"> appropriately
    3. Ditto for <Connector port="8080" protocol="HTTP/1.1"

  16. Restart the system and the two instances of the monitor as well as the services should start up with no issues


You can, of course, extend this to any number of services.

4 comments:

Louis Vézina said...

Thank you for this post, it help with my installation! :-)

ashu said...

fantastic post,its so useful.i found it very educational.

Harry Shergill said...
This comment has been removed by the author.
Anonymous said...

thanks a lot . This was very useful