Skip to content

Instantly share code, notes, and snippets.

@AgileSpirit
Last active December 16, 2015 17:19
Show Gist options
  • Save AgileSpirit/5469398 to your computer and use it in GitHub Desktop.
Save AgileSpirit/5469398 to your computer and use it in GitHub Desktop.
Script Unix de déploiement automatisé d'application Web Java vers Tomcat
#!/bin/sh
clear
echo "/********************************************/"
echo "/* QUESTIONNAIRE-SANTE NEW VERSION DEPLOYER */"
echo "/********************************************/"
#----------------------------------------------------------------------------
echo "[1/10] Configure script variables"
currentTime=$(date +"%Y-%m-%d_%H:%M:%S")
application=my-application
applicationWar=my-application.war
deliveryNewFolder=~/delivery/new
deliveryCurrentFolder=~/delivery/current
deliveryOldFolder=~/delivery/old
tomcatPID=$(ps -ef | grep tomcat | grep -v grep | grep -v restart | awk '{print $2}')
tomcatStartScript=$CATALINA_HOME/bin/startup.sh
tomcatStopScript=$CATALINA_HOME/bin/shutdown.sh
tomcatWebappsFolder=$CATALINA_HOME/webapps
tomcatWorkFolder=$CATALINA_HOME/work
tomcatTempFolder=$CATALINA_HOME/temp
tomcatLogsFolder=$CATALINA_HOME/logs
tomcatCatalinaPid=$CATALINA_HOME/logs/catalina.pid
#----------------------------------------------------------------------------
echo "[2/10] Checks if there is a new version to deploy"
if [ -f $deliveryNewFolder/$applicationWar ]
then
echo "A new version to deploy was found"
else
echo "There is no new version. ===> EXIT !"
exit 0
fi
#----------------------------------------------------------------------------
echo "[3/10] Stops Tomcat server"
if [ -f $tomcatCatalinaPid ]
then
echo "Tomcat is running on process $tomcatPID"
rm -f $tomcatCatalinaPid
$tomcatStopScript
sleep 10
else
echo "Tomcat does not appear to be running."
fi
#----------------------------------------------------------------------------
echo "[4/10] Moves the last delivered application war into the old folder"
if [ -f $deliveryCurrentFolder/$applicationWar ]
then
echo "A current application war was found in delivery current folder"
oldWarName="$applicationWar"_"$currentTime"
mv $deliveryCurrentFolder/$applicationWar $deliveryOldFolder/$oldWarName
echo "The war was moved into old folder as $oldWarName"
else
echo "There is no current application war in delivery current folder"
fi
#----------------------------------------------------------------------------
echo "[5/10] Removes the current deployed war from Tomcat webapp folder"
rm -rf $tomcatWebappsFolder/$application $tomcatWebappsFolder/$applicationWar
#----------------------------------------------------------------------------
echo "[6/10] Cleans the Tomcat work and temp folders"
rm -rf $tomcatWorkFolder/Catalina/localhost/$application
rm -rf $tomcatTempFolder/*
#----------------------------------------------------------------------------
echo "[7/10] Moves the new application war into the delivery current folder"
mv $deliveryNewFolder/$applicationWar $deliveryCurrentFolder/
#----------------------------------------------------------------------------
echo "[8/10] Copies the new application war into the Tomcat webapp folder"
cp $deliveryCurrentFolder/$applicationWar $tomcatWebappsFolder/
#----------------------------------------------------------------------------
echo "[9/10] Starts up Tomcat server"
$tomcatStartScript
#----------------------------------------------------------------------------
echo "[10/10] Creates the file 'catalina.pid' in Tomcat logs folder"
newTomcatPID=$(ps -ef | grep tomcat | grep -v grep | grep -v restart | awk '{print $2}')
echo $newTomcatPID > $tomcatCatalinaPid
echo "Tomcat is up on process $newTomcatPID"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment