I've been setting up our super-awesome new server this week and last night I ran into an issue that I thought I should blog about.
This is a Windows Server 2008 R2 64-bit machine with 8GB RAM and I am installing ColdFusion 9 running on Tomcat 6. And, as with everything Tomcat related, it was a pain in the ass and the documentation sucked.
To add Tomcat as a Windows service is pretty easy.
You just run:
For those that don't understand the notation above, CATALINA_HOME is the directory where Tomcat is. So in my case, we are going to N:\tomcat\bin and running service.bat.
This sets up Tomcat as a service, but by default it only gives it some tiny bit of memory to work with (256m or something, like it's 2002 again). So, of course, the moment I deployed a second instance of ColdFusion 9 on this container, I started getting "java.lang.OutOfMemoryError: PermGen space" errors.
So I Googled, and I Googled, and I Googled. There are SO MANY "solutions" for this problem that it is ridiculous. Unfortunately, none of them worked (for me). First it seems like most people suggested setting either a JAVA_OPTS or a CATALINA_OPTS environment variable with the new settings, but that doesn't seem to work. I saw at least one person suggest that the Tomcat service will NOT use the environment variables, even if they are set. My experience says that that is correct. When I set those variables, the Tomcat service would not use them (even after a reboot).
The next solution I saw was to add the settings to a setenv.bat file in the %CATALINA_HOME%/bin directory. So I tried it. Again the service did not pick up the settings (NOTE: When I ran Tomcat manually using startup.bat it DID pickup changes in both of the above named locations).
The last thing I tried was changing the settings of the service itself using the incredible cryptic command line options that I won't even get into. You can see them here: http://tomcat.apache.org/tomcat-6.0-doc/windows-service-howto.html
Finally, I gave up. It was 1:15AM (this morning) and I was pissed and tired. So i went to bed and figured I would look again today. Of course, I dreamed about Tomcat troubleshooting, so that sucked.
This morning, I sat down and looked at it again. Then, I saw this little bit of text on the above referenced HOW-TO page.
Tomcat6w is a GUI application for monitoring and configuring Tomcat services(Bold added for emphasis)
Everywhere else that they mention Tomcat6w they refer to it as the "Monitoring" program. This is the FIRST place I have seen it mentioned that it has a DAMN UI for changing the service.
So I ran it:
And I got an error like "The service Tomcat6 does not exist" or something. Great! Well, that was helpful. Do some more digging.
Here are the rest of the instructions for Tomcat6w.exe:
The available command line options are:
//ES// Edit service configuration This is the default operation. It is called if the no option is provided but the executable is renamed to servicenameW.exe //MS// Monitor service Put the icon in the system try
Awesome. WTF does this crap mean? I've never seen command line options like this before. And, of course, there are NO examples (The open source way of doing things).
So I tried passing in the //ES// param, and I got the same error message. Then I saw the part at the end of the explanation that says that renaming the executable to servicenameW.exe would do something. So, i tried it. Of course, servicenameW.exe didn't do a thing, because then didn't mean to literally name it that (I feel stupid about it now, but I was ready to try anything then). They mean you should give it the same name as the service and append w.exe to the end. So I went to look for the name of the service.
By default it looks like the service.bat file mention above gives the Tomcat service the name "Apache Tomcat 6". So I tried that. Of course, it didn't work, that is just the "display name". If you go into the service config you'll find the actual name of the service here:
So I renamed the file to tomcatServicew.exe (I had given the service a custom name while following some other instructions. Later I found out that if you don't specify a name it will automatically call it tomcat6 and all of this will work).
And then, BOOOM-shaka-laka.
At first I thought it had just reopened the other service config window. But then I saw the tabs highlighted above. So I clicked on the Java tab.
Here were some of the options I was looking for. I knew I wanted to increase heap memory and such anyway. But there was not a separate field for the MaxPermSize. But the was another arguments field.
So here is what I ended up with.
Now my Tomcat service starts just fine and has the appropriate amount of memory. All my CF instances start as expected and are REALLY fast.
I hope this helps someone, because I could have used a post like this last night.