root/misc/scripts/deploy_latest_gscf.sh @ 685

Revision 685, 5.3 KB (checked in by duh, 4 years ago)

small improvement

  • 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
60$SVN revert --recursive --quiet .
61SVN_REVISION=`$SVN update | sed -n 's/At revision \(.*\)\./\1/p'`
62
63# get application version
64APP_VERSION=`sed -n 's/app.version=\(.*\)$/\1/p' <  application.properties`
65GRAILS_VERSION=`sed -n 's/app.grails.version=\(.*\)$/\1/p' <  application.properties`
66echo ".done updating application to revision "$SVN_REVISION" (version "$APP_VERSION")"
67
68# see if this grails version is available
69if [ ! -d "/home/tomcat/grails-"$GRAILS_VERSION ]
70then
71        echo ".grails version "$GRAILS_VERSION" is not installed."
72
73        cd ~
74        ls -1 ~|grep grails|grep zip|xargs -i rm ~/{}
75       
76        echo ".downloading grails release "$GRAILS_VERSION"... (this might take a while)"
77        wget -q "http://dist.codehaus.org/grails/grails-"$GRAILS_VERSION".zip"
78
79        # success?
80        if [ ! -f "grails-"$GRAILS_VERSION".zip" ]
81        then
82                echo ".could not download and install grails "$GRAILS_VERSION
83                echo " do it manually instead and update the symbolic link..."
84                exit;
85        fi
86
87        # unzip archive
88        echo ".unzipping grails release "$GRAILS_VERSION
89        unzip -qq "grails-"$GRAILS_VERSION".zip"
90
91        # update symlink
92        echo ".updating symbolic link"
93        rm grails
94        ln -s "grails-"$GRAILS_VERSION grails
95
96        # switch to source dir
97        cd $PATH_GRAILS_SOURCE
98fi
99
100# test if grails version is the correct version
101GRAILS_RUNTIME_VERSION=`grails | sed -n 's/Welcome to Grails \(.*\) - http:\/\/grails.org\//\1/p'`
102if [ $GRAILS_RUNTIME_VERSION != $GRAILS_VERSION ]
103then
104        echo "'"$GRAILS_VERSION"'"
105        echo "'"$GRAILS_RUNTIME_VERSION"'"
106        echo ".ERROR: application requires grails version "$GRAILS_VERSION" while version "$GRAILS_RUNTIME_VERSION" is installed... please fix!"
107        exit;
108fi
109
110# clean source
111echo ".clean source"
112grails clean > /dev/null
113$SVN update > /dev/null
114
115# build production war
116echo ".build production war"
117grails prod war > /dev/null
118
119# stop tomcat
120echo ".stopping tomcat"
121$PATH_TOMCAT_BIN/shutdown.sh 2>&1 /dev/null &
122
123# wait a while
124echo ".waiting..."
125sleep 5
126
127# undeploying gscf releases
128rm -rf $PATH_TOMCAT_WEBAPPS/gscf*
129
130# deploy production war
131echo ".deploying new production WAR"
132cp target/gscf-$APP_VERSION.war $PATH_TOMCAT_WEBAPPS
133
134# patch datasource.groovy
135echo ".patching datasource for demo instance"
136sed -i 's/5432\/gscf/5432\/gscf-demo/g' grails-app/conf/DataSource.groovy
137
138# patch Searchable.groovy
139echo ".patching searchable for demo instance"
140sed -i 's/searchable\/gscf\//searchable\/gscf-demo\//g' grails-app/conf/Searchable.groovy
141
142# check if the demo was indeed patched correctly
143CHECK=`cat grails-app/conf/DataSource.groovy | grep -i gscf-demo | wc -l`
144if [ $CHECK -eq 0 ]
145then
146        echo ".ERROR: datasource was not patched correctly!"
147        echo ".exiting..."
148        exit;
149fi
150
151# build demo war
152echo ".building demo war"
153grails prod war > /dev/null
154
155# deploying new demo war
156echo ".deploying new demo war"
157cp target/gscf-$APP_VERSION.war $PATH_TOMCAT_WEBAPPS/gscf-$APP_VERSION-demo.war
158
159# start tomcat
160echo ".starting tomcat"
161$PATH_TOMCAT_BIN/startup.sh 2>&1 /dev/null &
162
163# fix apache virtual host configuration
164echo ".updating apache virtual host configuration"
165ls /etc/apache2/sites-available/dbnp*|xargs -i sed -i 's/gscf-[0-9]\.[0-9]\.[0-9]/gscf-'$APP_VERSION'/g' {}
166
167# reloading apache
168echo ".telling apache to reload the configuration files (this might take 1 minute to complete)..."
169touch ~/reload_apache
170
171# done...
172echo ".done..."
173
Note: See TracBrowser for help on using the browser.