Apache Tomcat Upgrade

You can compare changes to the shipped configuration files between versions using the appropriate link for your version... This is important if you have customised any of the configuration files... i.e. you will need to merge in your changes after downloading the new version. If there are no shipped changes you can simply overwrite with your version.

Ensure Java also has the latest patches.

This page assumes Tomcat is installed on a Linux OS under /tomcat using a tarball (i.e. not by using a package manager like yum or apt) and that users/groups have been created, environment has been set, systemd has been configured etc.

Download Tomcat

Download latest appropriate version and copy it to /tomcat on your target server.

The Core tar.gz file is recommended

As 'root'...

cd /tomcat

TOMVER=$(ls -t apache-tomcat*.tar.gz | awk -F".tar.gz" '{ print $1 }' | head -1)

OLDVER=$(file /tomcat/latest | awk -F"/" '{ print $5 }' | tr -d '\047')

tar xvf ${TOMVER}.tar.gz -C /tomcat

rm /tomcat/${TOMVER}.tar.gz

chown -R tomcat:tomcat ${TOMVER}

chmod o+x /tomcat/${TOMVER}/bin/

The command for setting the TOMVER variable works best if there are no old tomcat tar.gz files in /tomcat i.e. it needs to return one value. If there are multiple files it picks the first one (assuming you want the most recent).
The command for setting OLDVER assumes you have a symbolic link called /tomcat/latest that points to the current version of Tomcat. If you have installed using the instructions on this website then this will be the case.

Update Config

echo ==============================================================================

for file in $(ls /tomcat/${TOMVER}/conf)

do

  echo ------------------------------------------------------------------------------

  diff -c /tomcat/${OLDVER}/conf/${file} /tomcat/${TOMVER}/conf/${file}

  echo ------------------------------------------------------------------------------

done

echo ==============================================================================

WAMDIR=webapps/manager/META-INF

echo ==============================================================================

for file in $(ls /tomcat/${TOMVER}/${WAMDIR})

do

  echo ------------------------------------------------------------------------------

  diff -c /tomcat/${OLDVER}/${WAMDIR}/${file} /tomcat/${TOMVER}/${WAMDIR}/${file}

  echo ------------------------------------------------------------------------------

done

echo ==============================================================================

Some changes will be related to the new version and no action is necessary. Others will be your customisations which you are likely to want to replicate in the new version.
Files most likely to contain customisatians include:
  • server.xml
  • tomcat-users.xml
  • context.xml

If the ONLY changes to a file are your changes you can simply copy it over.

cp /tomcat/${OLDVER}/conf/server.xml /tomcat/${TOMVER}/conf/server.xml

cp /tomcat/${OLDVER}/conf/tomcat-users.xml /tomcat/${TOMVER}/conf/tomcat-users.xml

cp /tomcat/${OLDVER}/${WAMDIR}/context.xml /tomcat/${TOMVER}/${WAMDIR}/context.xml

NOTE: If there are other changes then you should redo your changes in the new file.

Redo any Tomcat Security changes.

APEX Images

Only relevant if you are running ORDS in your Tomcat deployment

TOMVER=$(ls -td apache-tomcat-* | awk -F".tar.gz" '{ print $1 }' | head -1)

OLDVER=$(file /tomcat/latest | awk -F"/" '{ print $5 }' | tr -d '\047')

mkdir /tomcat/${TOMVER}/webapps/i/

time rsync -ahiv --stats /tomcat/${OLDVER}/webapps/i/* /tomcat/${TOMVER}/webapps/i/

chown -R tomcat:tomcat /tomcat/${TOMVER}/webapps/i/

Restart with new version

systemctl stop tomcat

ln -sTf /tomcat/${TOMVER} /tomcat/latest

systemctl start tomcat

Redeploy ORDS

Only relevant if you are running ORDS in your Tomcat deployment

cp -v /tomcat/ords/ords.war /tomcat/${TOMVER}/webapps

You may need to clear your browser cookies before ORDS/APEX will work

Bibliography