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.

Wednesday, July 16, 2008

Making A 2/3-Pin Socket Power Cord For A CN13/CN14 (Standard PC) Power Point

OR Putting An Old UPS To Use



The power situation in India is pretty bad; I've had days when the power would go keep coming and going out every 10-15 minutes. Needless to say, the effect on my Internet experience is pretty dampening.

A friend of mine recently lent me an old APC UPS. We figured it'd be enough to power my network switch and my DSL modem, keeping my connection alive.

Unfortunately, the UPS only had output in the form of IEC C13 sockets (female).


This wasn't going to work for me because I needed to connect common C, D or M type 2/3-pin plugs. I asked at a few shops but there doesn't seem to be any connector or convertor for this purpose. So I decided to hack together something to use.

I bought a CN14-CN13 cable and a box type 3-pin socket.



I sliced off the CN13 (female) connector on the cable and separated the wires in the remaining part. I then wired them to the plug-point and, well, that was it! I now have this:


I simply plug it into the back of the UPS and I have backup power! Very easy, very obvious but it still pretty satisfying and very useful :D

 Be careful with the wiring! If you've never done it before, you should consider getting someone who has to assist you. I had a bit of trouble when some loose wires I'd left in the box short-circuited and blew the connection apart!

Tuesday, July 1, 2008

Google Toolbar Flags orkut.co.in As A Web Forgery

A funny thing happened today; I was checking out my communities on orkut when this popped up in Firefox -

orkut-web-forgery
This is the first time that I've seen this. I believe it's a Google Toolbar feature, but I'm not quite sure. The odd thing is that the warning only appeared when I tried to go to the communities pages while on the orkut.co.in domain and not on orkut.com.

I followed the This isn't a web forgery link ( which took me to a Google page, hence my assumption this is a Google Toolbar feature ) and reported the error. But it's ironic that Google's feature would block one of Google's own websites!