Skip to content

Instantly share code, notes, and snippets.

@master-bob
Forked from mtheoryx/clean_tomcat.sh
Last active May 17, 2017 17:24
Show Gist options
  • Select an option

  • Save master-bob/58ed92fef85f257b3746 to your computer and use it in GitHub Desktop.

Select an option

Save master-bob/58ed92fef85f257b3746 to your computer and use it in GitHub Desktop.
A simple script to completely clean tomcat between Sakai deployments
#!/bin/bash
# created by Leonardo Canessa
# Modified from mtheoryx
# lcanessa1@udayton.edu
# simple script to clean tomcat prior to deploying sakai
# $CATALINA_HOME assumed to be a symlink (/opt/tomcat) to an apache-tomcat-X.Y.Z folder
tomcatVersion=`ls -l $CATALINA_HOME`
tomcat8=false
tomcat7=false
if [[ $tomcatVersion == *"apache-tomcat-8"* ]]
then
echo "Tomcat 8 detected."
tomcat8=true
elif [[ $tomcatVersion == *"apache-tomcat-7"* ]]
then
echo "Tomcat 7 detected."
tomcat7=true
else
echo "Tomcat version not detected."
exit 0
fi
if [ "$tomcat7" = true ]
then
echo "Making backwards compatible directories ..."
mkdir -pv $CATALINA_HOME/shared/classes $CATALINA_HOME/shared/lib $CATALINA_HOME/common/classes $CATALINA_HOME/common/lib $CATALINA_HOME/server/classes $CATALINA_HOME/server/lib
fi
echo "Cleaning up: "${CATALINA_HOME}" ... "
# remove old data
if [ "$tomcat7" = true ]
then
echo "Cleaning shared lib..."
rm -f $CATALINA_HOME/shared/lib/*
echo "Cleaning common lib..."
rm -f $CATALINA_HOME/common/lib/*
elif [ "$tomcat8" = true ]
then
echo "Cleaning lib..."
rm -f $CATALINA_HOME/lib/*
fi
echo "Cleaning webapps..."
rm -rf $CATALINA_HOME/webapps/*
echo "Cleaning components..."
rm -rf $CATALINA_HOME/components/*
echo "Cleaning work..."
rm -rf $CATALINA_HOME/work/*
echo "Cleaning temp.."
rm -rf $CATALINA_HOME/temp/*
echo "Tomcat resources are now clean"
echo "Copying needed resources..."
# copy needed resources
# copy libraries which aren't deployed correctly to tomcat ???
echo "Copying libraries..."
if [ "$tomcat7" = true ]
then
cp -r /opt/tomcat-libs/common $CATALINA_HOME/
cp -r /opt/tomcat-libs/shared $CATALINA_HOME/
elif [ "$tomcat8" = true ]
then
cp -r /opt/tomcat-libs/lib/* $CATALINA_HOME/lib
fi
# copy mysql connector, connector should be in $CATALINA_HOME/lib, but this
# method allows for connectorj to be kept uptodate
echo "Copying connector/J..."
if [ "$tomcat7" = true ]
then
cp /opt/connectorj/m*.jar $CATALINA_HOME/common/lib
cp /opt/ojdbc/*.jar $CATALINA_HOME/common/lib
elif [ "$tomcat8" = true ]
then
cp /opt/connectorj/m*.jar $CATALINA_HOME/lib
cp /opt/ojdbc/*.jar $CATALINA_HOME/lib
fi
echo "All done!"
# Future work, check that libraries copied correctly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment