Environment variables
CATALINA_BASE
- The root of a particular Tomcat instance (the same as
$CATALINA_HOME
if multiple instances aren’t configured) - This points to the location of configuration files, logs, startup scripts, web apps, and work/temp folders
- The root of a particular Tomcat instance (the same as
CATALINA_HOME
- The root of your Tomcat installation
- This points to where the Tomcat binaries are located
The environment variables are normally set in the startup scripts for Tomcat
- RHEL 7:
- See: /etc/tomcat/tomcat.conf
- RHEL 6:
- See: /etc/tomcat6/tomcat6.conf
Undeploy (delete) a deployed Tomcat application
RHEL 6:
- Set
CATALINA_BASE
andCATALINA_HOME
source /etc/tomcat6/tomcat6.conf
- If the application was deployed as a WAR file:
- Remove the application from $CATALINA_BASE/webapps
sudo mv $CATALINA_BASE/webapps/myapp.war $CATALINA_BASE/myapp.war-`date +%Y%m%d`
- If Tomcat is running, it should automatically remove the deployed app from $CATALINA_BASE/webapps and $CATALINA_BASE/work/Catalina/localhost. Watch the folder and wait for it to be removed:
ls $CATALINA_BASE/webapps ls $CATALINA_BASE/work/Catalina/localhost
When the app is undeployed, the subfolder with the same name as your WAR file will disappear (e.g. $CATALINA_BASE/webapps/myapp, $CATALINA_BASE/work/Catalina/localhost/myapp)
- Remove the application from $CATALINA_BASE/webapps
- If the application is deployed using a context fragment (i.e. via an XML file in $CATALINA_HOME/conf/Catalina/localhost):
- Get the location of the war file
$ grep docBase $CATALINA_HOME/conf/Catalina/localhost/idp.xml <Context docBase="/opt/shibboleth-idp/war/idp.war"
- If you want to fully remove the application (you won’t be replacing it with a new version):
Warning: This will also remove the context fragment XML file- Remove the old WAR file
sudo mv /opt/shibboleth-idp/war/idp.war /opt/shibboleth-idp/war/idp.war-`date +%Y%m%d`
- If Tomcat is running, it should automatically remove the deployed app from $CATALINA_BASE/work/Catalina/localhost and the context fragment from $CATALINA_HOME/conf/Catalina/localhost:
ls $CATALINA_HOME/conf/Catalina/localhost ls $CATALINA_BASE/work/Catalina/localhost
- Remove the old WAR file
- If you intend on updating the application with a new WAR file:
- Make a backup copy of the old WAR file
sudo cp /opt/shibboleth-idp/war/idp.war /opt/shibboleth-idp/war/idp.war-`date +%Y%m%d`
- Make a backup copy of the old WAR file
- Get the location of the war file
Update a deployed Tomcat application
- Undeploy the old WAR file
- See above
- Once the app is undeployed, deploy the new WAR file
- If the old WAR file was in the webapps folder:
- Put the new WAR file in place
sudo cp myapp.war $CATALINA_BASE/webapps
- Watch the webapps folder to make sure the app is deployed
ls $CATALINA_BASE/webapps
If you don’t see a subfolder with the same name as your WAR file (e.g. $CATALINA_BASE/webapps/myapp) within a minute or so, check the logs for errors
- Put the new WAR file in place
- If the old WAR file was deployed using a context fragment:
- Put the new WAR file in place
sudo cp idp.war /opt/shibboleth-idp/war
- Watch the work folder to make sure the app is deployed
ls -l $CATALINA_HOME/work/Catalina/localhost/idp/
- Put the new WAR file in place
- If the old WAR file was in the webapps folder:
Customizing application context
-
Copy the filename of the application’s WAR file from $CATALINA_BASE/webapps (e.g. myApp.war)
- Create a new context fragment file in $CATALINA_HOME/conf/Catalina/localhost
- Use the same filename as the war file, but replace the .war extension with .xml (e.g. myApp.xml)
-
Add the xml header and an empty
<Context>
element<?xml version="1.0"?> <Context> </Context>
-
Add any customizations as desired
<Context swallowOutput="true"> <WatchedResource>...
-
If this is a new context file, it should automatically be picked up and applied by Tomcat. Otherwise, Tomcat may need to be restarted
sudo systemctl restart tomcat