Automatic Deploy
We have an application running on tomcat and the application is managed by a git repository. As application server we use tomcat on a windows server having git installed. Now I would like to have a simple script I fire that stops the appliation server, pull changes, checkout it, remove all files not included in commits, rollout configuration files and restart tomcat.
Configuration files are stored with file extension .STG, .STG1, .PRD, .PRD1, .PRD2, .PRD3… and the normal configuration file is not part of git repository. So we can have different configuration files in the git repository and the script will take the correct one and copy it accordingly.
We do this using a simple shell script. For this create a link that has as target the following link defined:
C:\WINDOWS\system32\cmd.exe /c ""C:\Program Files\Git\usr\bin\sh.exe" --login -i updateapp.sh"
Now go into your home directory and create a file called updateapp.sh:
system="STG"
node="STG2"
net stop Tomcat7
echo Clear cache files
rm -rf /d/Archibus/apps/webcentral/tools/tomcat/webapps/archibus/schemaCompiled
rm -rf /d/Archibus/apps/webcentral/tools/tomcat/work/Catalina
echo
echo Update archibus folder
cd /d/Archibus/apps/webcentral/tools/tomcat/webapps/archibus
git checkout -f master
git fetch
git reset --hard origin/master
git clean -fd
echo
echo Update configuration files
for i in $(find . -type f -name "*.$system");
do
cp -v "$i" "${i%.$system}"
done
for i in $(find . -type f -name "*.$node");
do
cp -v "$i" "${i%.$node}"
done
echo
echo Update archibus_help folder
cd /d/Archibus/apps/webcentral/tools/tomcat/webapps/archibus_help
git checkout -f master
git fetch
git reset --hard origin/master
git clean -fd
echo Press a key to start Tomcat
read
net start Tomcat7
echo
echo Update finished
echo Press any key to exit
read