Updating Tomcat after a yum install

Problem: You have already installed Tomcat 6.0.N in CentOS (or similar) successfully, but now you want to upgrade to 6.0.M, yet yum is telling you that there’s no upgrade for Tomcat.

Under these circumstances you’ll think of installing the new binaries directly from Apache. But your existing Tomcat deployments will not be migrated, and instead of the directory links under /usr/share/tomcat6 you will have a single directory hierarchy with no links, which is probably rather different to what you are used to, and will probably break a lot of scripts that assume the files are in their current locations.

Fortunately, if you need Tomcat 6.0.M in a hurry, there’s an easy procedure to replace the essential Tomcat binaries/links without breaking your existing deployments. (Here I assume a simple “point upgrade” where the deployed applications are already known to be compatible with the newer Tomcat.)

Download the latest Core apache-tomcat-6.Y.ZZ.tar.gz from http://tomcat.apache.org/download-60.cgi and put it in the /tmp directory. Now, assume for this example that 6.Y.ZZ is 6.0.33, and assume that yum has already installed your older Tomcat to /usr/share/tomcat6, do the following as root:

  • tcver=6.0.33
  • cd /usr/share
  • mv /tmp/apache-tomcat-$tcver.tar.gz .
  • tar -xzf apache-tomcat-$tcver.tar.gz
  • mv apache-tomcat-$tcver tomcat-$tcver
  • /sbin/service tomcat6 stop
  • Wait for Tomcat to stop before proceeding with:
  • rm -f /usr/share/tomcat6/lib/*-6.*.jar
  • rm -f /usr/share/tomcat6/bin/*-6.*.jar
  • ln -f -s /usr/share/tomcat-$tcver/lib/annotations-api.jar /usr/share/tomcat6/lib/annotations-api.jar
  • ln -f -s /usr/share/tomcat-$tcver/lib/catalina-ant.jar /usr/share/tomcat6/lib/catalina-ant.jar
  • ln -f -s /usr/share/tomcat-$tcver/lib/catalina-ha.jar /usr/share/tomcat6/lib/catalina-ha.jar
  • ln -f -s /usr/share/tomcat-$tcver/lib/catalina.jar /usr/share/tomcat6/lib/catalina.jar
  • ln -f -s /usr/share/tomcat-$tcver/lib/catalina-tribes.jar /usr/share/tomcat6/lib/catalina-tribes.jar
  • ln -f -s /usr/share/tomcat-$tcver/lib/jasper-el.jar /usr/share/tomcat6/lib/jasper-el.jar
  • ln -f -s /usr/share/tomcat-$tcver/lib/jasper.jar /usr/share/tomcat6/lib/jasper.jar
  • ln -f -s /usr/share/tomcat-$tcver/lib/tomcat-coyote.jar /usr/share/tomcat6/lib/tomcat-coyote.jar
  • ln -f -s /usr/share/tomcat-$tcver/lib/tomcat-i18n-es.jar /usr/share/tomcat6/lib/tomcat-i18n-es.jar
  • ln -f -s /usr/share/tomcat-$tcver/lib/tomcat-i18n-fr.jar /usr/share/tomcat6/lib/tomcat-i18n-fr.jar
  • ln -f -s /usr/share/tomcat-$tcver/lib/tomcat-i18n-ja.jar /usr/share/tomcat6/lib/tomcat-i18n-ja.jar
  • ln -f -s /usr/share/tomcat-$tcver/lib/el-api.jar /usr/share/tomcat6/lib/el-api.jar
  • ln -f -s /usr/share/tomcat-$tcver/lib/jsp-api.jar /usr/share/tomcat6/lib/jsp-api.jar
  • ln -f -s /usr/share/tomcat-$tcver/lib/servlet-api.jar /usr/share/tomcat6/lib/servlet-api.jar
  • ln -f -s /usr/share/tomcat-$tcver/bin/bootstrap.jar /usr/share/tomcat6/bin/bootstrap.jar
  • ln -f -s /usr/share/tomcat-$tcver/bin/tomcat-juli.jar /usr/share/tomcat6/bin/tomcat-juli.jar
  • Finally, restart Tomcat:
  • /sbin/service tomcat6 start

Here’s a quick explanation: yum installed Tomcat under /usr/share/tomcat6, with most of the subdirectories actually linking to various other places around your disk. Inside the current lib directory you will find that the jar files appear with unversioned base names and also with versioned names. The unversioned files are actually links to the co-located versioned files. My procedure deletes the old versioned jar files, and then replaces all the old links with new links to the new jars that have been extracted to the nearby /usr/share/tomcat-6.Y.ZZ directory. Ditto for two jars in the current bin directory.

Using yum as a starting point is handy, because it arranges the directories in suitable places, and sets up the lifecycle scripts. It’s just a pity that the repositories are not always up-to-date with the Apache releases. Hopefully the above procedure will get you over your current Tomcat version issue.

Categorised as: Coding

Comment Free Zone

Comments are closed.