root/misc/scripts/deploy_latest_gscf.sh @ 678

Revision 678, 5.5 KB (checked in by duh, 4 years ago)

Adding gscf deploy script, see source for information...

  • Property svn:executable set to *
Line 
1#!/bin/sh
2# Automated deploy script for release a new production and a new
3# demo instance of gscf on nbx14. This script needs to be run as
4# user tomcat
5#
6# What it does:
7# - checkout the latest source code from svn
8# - check if the grails version matches (if not, it downloads and
9#   installs that particular grails release to /home/tomcat and
10#   updates the symbolic link ~/grails to the new release)
11# - build a production war, undeploy the old release and deploy the
12#   new release to tomcat's webapps
13# - patch some configuration files for the demo version
14# - build a demo war, undeploy the old release and deploy the
15#   new release to tomcat's webapps
16# - restart tomcat
17# - patch apache's virtual host configuration files in and trigger
18#   restart of apache
19#
20# Prerequisites:
21# - tomcat webabbs should be writable by user tomcat
22# - tomcat bin files should be executable by user tomcat
23# - in the end this script touches a file to restart apache
24#   webserver. This particular cronjob running as root should
25#   be available as well
26# - obviously, postgres databases should be available (respectively
27#   gscf and gscf-demo)
28# - a /home/tomcat/.bashrc containing the following lines:
29#       export GRAILS_HOME=/home/tomcat/grails
30#       export PATH=/home/tomcat/grails/bin:$PATH
31#       export JAVA_HOME=/usr/lib/jvm/java-6-sun
32#       export CATALINA_OPTS="-Xms1024m -Xmx1024m -XX:MaxPermSize=512m -XX:MaxHeapFreeRatio=70 -XX:MaxGCPauseMillis=10 -XX:+UseConcMarkSweepGC"
33#
34# @Author       Jeroen Wesbeek <J****n.W******@gmail.com>
35# @Since        20100720
36#
37# Revision Information:
38# $Author$
39# $Date$
40# $Rev$
41
42# CONFIGURATION
43USER=`/usr/bin/whoami`
44PATH_TOMCAT_BIN=/home/tomcat/apache-tomcat-6.0.26/bin
45PATH_TOMCAT_WEBAPPS=/home/tomcat/apache-tomcat-6.0.26/webapps
46PATH_GRAILS_SOURCE=/home/tomcat/workspace/gscf
47SVN=`which svn`
48APACHE_VHOST_FILES=/etc/apache2/sites-available/dbnp*
49
50# are we user tomcat?
51if [ $USER != 'tomcat' ]
52then
53        echo "ERROR: you need to run this script as user tomcat..."
54        exit;
55fi
56
57# update project source to latest version
58echo .updating source
59cd $PATH_GRAILS_SOURCE
60SVN_REVISION=`$SVN update | sed -n 's/At revision \(.*\)\./\1/p'`
61
62# get application version
63APP_VERSION=`sed -n 's/app.version=\(.*\)$/\1/p' <  application.properties`
64GRAILS_VERSION=`sed -n 's/app.grails.version=\(.*\)$/\1/p' <  application.properties`
65echo ".done updating application to revision "$SVN_REVISION" (version "$APP_VERSION")"
66
67# see if this grails version is available
68if [ ! -d "/home/tomcat/grails-"$GRAILS_VERSION ]
69then
70        echo ".grails version "$GRAILS_VERSION" is not installed."
71
72        cd ~
73        rm grails*.zip > /dev/null
74       
75        echo ".downloading grails release "$GRAILS_VERSION"... (this might take a while)"
76        wget -q "http://dist.codehaus.org/grails/grails-"$GRAILS_VERSION".zip"
77
78        # success?
79        if [ ! -f "grails-"$GRAILS_VERSION".zip" ]
80        then
81                echo ".could not download and install grails "$GRAILS_VERSION
82                echo " do it manually instead and update the symbolic link..."
83                exit;
84        fi
85
86        # unzip archive
87        echo ".unzipping grails release "$GRAILS_VERSION
88        unzip -qq "grails-"$GRAILS_VERSION".zip"
89
90        # update symlink
91        echo ".updating symbolic link"
92        rm grails
93        ln -s "grails-"$GRAILS_VERSION grails
94
95        # switch to source dir
96        cd $PATH_GRAILS_SOURCE
97fi
98
99# test if grails version is the correct version
100GRAILS_RUNTIME_VERSION=`grails | sed -n 's/Welcome to Grails \(.*\) - http:\/\/grails.org\//\1/p'`
101if [ $GRAILS_RUNTIME_VERSION != $GRAILS_VERSION ]
102then
103        echo "'"$GRAILS_VERSION"'"
104        echo "'"$GRAILS_RUNTIME_VERSION"'"
105        echo ".ERROR: application requires grails version "$GRAILS_VERSION" while version "$GRAILS_RUNTIME_VERSION" is installed... please fix!"
106        exit;
107fi
108
109# clean source
110echo ".clean source"
111grails clean > /dev/null
112svn update > /dev/null
113
114# make sure patched configuration files are okay
115svn revert grails-app/conf/DataSource.groovy > /dev/null
116svn revert grails-app/conf/Searchable.groovy > /dev/null
117
118# build production war
119echo ".build production war"
120grails prod war > /dev/null
121
122# stop tomcat
123echo ".stopping tomcat"
124$PATH_TOMCAT_BIN/shutdown.sh 2>&1 /dev/null &
125
126# wait a while
127echo ".waiting..."
128sleep 5
129
130# undeploy old production war
131echo ".undeploying old production war"
132ls $PATH_TOMCAT_WEBAPPS/gscf*.war|grep -v demo|xargs -i rm {}
133
134# deploy production war
135echo ".deploying new production WAR"
136cp target/gscf-$APP_VERSION.war $PATH_TOMCAT_WEBAPPS
137
138# patch datasource.groovy
139echo ".patching datasource for demo instance"
140sed -i 's/5432\/gscf/5432\/gscf-demo/g' grails-app/conf/DataSource.groovy
141
142# patch Searchable.groovy
143echo ".patching searchable for demo instance"
144sed -i 's/searchable\/gscf\//searchable\/gscf-demo\//g' grails-app/conf/Searchable.groovy
145
146# check if the demo was indeed patched correctly
147CHECK=`cat grails-app/conf/DataSource.groovy | grep -i gscf-demo | wc -l`
148if [ $CHECK -eq 0 ]
149then
150        echo ".ERROR: datasource was not patched correctly!"
151        echo ".exiting..."
152        exit;
153fi
154
155# build demo war
156echo ".building demo war"
157grails prod war > /dev/null
158
159# undeploy old demo war
160echo ".undeploying old demo war"
161ls $PATH_TOMCAT_WEBAPPS/gscf*-demo.war|xargs -i rm {}
162
163# deploying new demo war
164echo ".deploying new demo war"
165cp target/gscf-$APP_VERSION.war $PATH_TOMCAT_WEBAPPS/gscf-$APP_VERSION-demo.war
166
167# start tomcat
168echo ".starting tomcat"
169$PATH_TOMCAT_BIN/startup.sh 2>&1 /dev/null &
170
171# fix apache virtual host configuration
172echo ".updating apache virtual host configuration"
173ls /etc/apache2/sites-available/dbnp*|xargs -i sed -i 's/gscf-[0-9]\.[0-9]\.[0-9]/gscf-'$APP_VERSION'/g' {}
174
175# reloading apache
176echo ".telling apache to reload the configuration files (this might take 1 minute to complete)..."
177touch ~/reload_apache
178
179# done...
180echo ".done..."
181
Note: See TracBrowser for help on using the browser.