Skip to content

Instantly share code, notes, and snippets.

@geowa4
Created December 3, 2011 21:51
Show Gist options
  • Save geowa4/1428257 to your computer and use it in GitHub Desktop.
Save geowa4/1428257 to your computer and use it in GitHub Desktop.
Simple Bash script to download Tomcat 7.0.23 and deploy a WAR.
#!/bin/bash
TOMCAT=apache-tomcat-7.0.23
TOMCAT_WEBAPPS=$TOMCAT/webapps
TOMCAT_CONFIG=$TOMCAT/conf/server.xml
TOMCAT_START=$TOMCAT/bin/startup.sh
TOMCAT_ARCHIVE=$TOMCAT.tar.gz
TOMCAT_URL=http://apache.mirrorcatalogs.com/tomcat/tomcat-7/v7.0.23/bin/$TOMCAT_ARCHIVE
WAR_FILE=whatever.war
if [ ! -e $TOMCAT ]; then
if [ ! -r $TOMCAT_ARCHIVE ]; then
if [ -n "$(which curl)" ]; then
curl -O $TOMCAT_URL
elif [ -n "$(which wget)" ]; then
wget $TOMCAT_URL
fi
fi
if [ ! -r $TOMCAT_ARCHIVE ]; then
echo "Tomcat could not be downloaded." 1>&2
echo "Verify that eiter curl or wget is installed." 1>&2
echo "If they are, check your internet connection and try again." 1>&2
echo "You may also download $TOMCAT_ARCHIVE and place it in this folder." 1>&2
exit 1
fi
tar -zxf $TOMCAT_ARCHIVE
rm $TOMCAT_ARCHIVE
fi
if [ ! -w $TOMCAT -o ! -w $TOMCAT_WEBAPPS ]; then
echo "$TOMCAT and $TOMCAT_WEBAPPS must be writable." 1>&2
exit 1
fi
if [ ! -r $WAR_FILE ]; then
echo "$WAR_FILE is missing. Download it and run this again to deploy it." 1>&2
else
cp $WAR_FILE $TOMCAT_WEBAPPS
fi
# place tomcat customizations here
sed -i s/8080/9090/g $TOMCAT_CONFIG
$TOMCAT_START
#!/bin/bash
TOMCAT=apache-tomcat-7.0.23
TOMCAT_SHUTDOWN=$TOMCAT/bin/shutdown.sh
$TOMCAT_SHUTDOWN
rm -fr $TOMCAT
@gopalroy2025
Copy link

DO U HAVE SAME SCRIPT FOR TOMCAT 8 ?

@paulofreitasmobicare
Copy link

Change this two lines:
TOMCAT=apache-tomcat-8.5.41
TOMCAT_URL=http://ftp.unicamp.br/pub/apache/tomcat/tomcat-8/v8.5.41/bin/$TOMCAT_ARCHIVE

@PushkarKumar963
Copy link

what is whatever.war

@geowa4
Copy link
Author

geowa4 commented Sep 9, 2019

what is whatever.war

Example path to your .war file intended to be changed for your needs.

@subhorocks187
Copy link

subhorocks187 commented Nov 1, 2019

Suppose I have vm where I need to run this same scrpit, but that vm don't have internet connection. Then how can we install and deploy the file?

@geowa4
Copy link
Author

geowa4 commented Nov 4, 2019

Is user data/cloud config an option?

@subhorocks187
Copy link

Not sure,
One more point, I am trying another approach where I am putting the Apache tomcat.gz.tz file and using the script I am unzipping it and copy the UI code into webapps folder but don't know it's not working.
Giving me error.

@subhorocks187
Copy link

I checked it again..
It's working.. thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment