source: misc/scripts/deploy_latest_gscf.sh @ 753

Last change on this file since 753 was 753, checked in by duh, 12 years ago

bugfix

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Rev
File size: 5.8 KB
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: duh $
39# $Date: 2010-07-29 12:23:51 +0000 (do, 29 jul 2010) $
40# $Rev: 753 $
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*
49DEV_PLUGINS=( db-util nadd-neutralizer )
50
51# are we user tomcat?
52if [ $USER != 'tomcat' ]
53then
54        echo "ERROR: you need to run this script as user tomcat..."
55        exit;
56fi
57
58# update project source to latest version
59echo .updating source
60cd $PATH_GRAILS_SOURCE
61$SVN revert --recursive --quiet .
62SVN_REVISION=`$SVN update | sed -n 's/At revision \(.*\)\./\1/p'`
63
64# get application version
65APP_VERSION=`sed -n 's/app.version=\(.*\)$/\1/p' <  application.properties`
66GRAILS_VERSION=`sed -n 's/app.grails.version=\(.*\)$/\1/p' <  application.properties`
67echo ".done updating application to revision "$SVN_REVISION" (version "$APP_VERSION")"
68
69# see if this grails version is available
70if [ ! -d "/home/tomcat/grails-"$GRAILS_VERSION ]
71then
72        echo ".grails version "$GRAILS_VERSION" is not installed."
73
74        cd ~
75        ls -1 ~|grep grails|grep zip|xargs -i rm ~/{}
76       
77        echo ".downloading grails release "$GRAILS_VERSION"... (this might take a while)"
78        wget -q "http://dist.codehaus.org/grails/grails-"$GRAILS_VERSION".zip"
79
80        # success?
81        if [ ! -f "grails-"$GRAILS_VERSION".zip" ]
82        then
83                echo ".could not download and install grails "$GRAILS_VERSION
84                echo " do it manually instead and update the symbolic link..."
85                exit;
86        fi
87
88        # unzip archive
89        echo ".unzipping grails release "$GRAILS_VERSION
90        unzip -qq "grails-"$GRAILS_VERSION".zip"
91
92        # update symlink
93        echo ".updating symbolic link"
94        rm grails
95        ln -s "grails-"$GRAILS_VERSION grails
96
97        # switch to source dir
98        cd $PATH_GRAILS_SOURCE
99fi
100
101# test if grails version is the correct version
102GRAILS_RUNTIME_VERSION=`grails | sed -n 's/Welcome to Grails \(.*\) - http:\/\/grails.org\//\1/p'`
103if [ $GRAILS_RUNTIME_VERSION != $GRAILS_VERSION ]
104then
105        echo "'"$GRAILS_VERSION"'"
106        echo "'"$GRAILS_RUNTIME_VERSION"'"
107        echo ".ERROR: application requires grails version "$GRAILS_VERSION" while version "$GRAILS_RUNTIME_VERSION" is installed... please fix!"
108        exit;
109fi
110
111# clean source
112echo ".clean source"
113grails clean > /dev/null
114$SVN update > /dev/null
115
116# uninstall development plugins
117index=0
118while [ "$index" -lt "${#DEV_PLUGINS[@]}" ]
119do
120        PLUGIN_INSTALLED=`find /home/tomcat/.grails/$GRAILS_VERSION/projects/gscf/plugins/ -maxdepth 1|grep -i ${DEV_PLUGINS[index]}|wc -l`
121        if [ "$PLUGIN_INSTALLED" -gt "0" ]; then
122                echo $STAMP uninstalling ${DEV_PLUGINS[index]} plugin
123                grails uninstall-plugin ${DEV_PLUGINS[index]} > /dev/null
124        fi
125        ((index++))
126done
127
128# build production war
129echo ".build production war"
130grails prod war > /dev/null
131
132# stop tomcat
133echo ".stopping tomcat"
134$PATH_TOMCAT_BIN/shutdown.sh > /dev/null
135
136# wait a while
137echo ".waiting..."
138sleep 5
139
140#backup database
141#NOW=`date +%F_%T`
142#sudo -u postgres pg_dump gscf > /home/tomcat/backups/gscf_$NOW.sql
143
144# undeploying gscf releases
145rm -rf $PATH_TOMCAT_WEBAPPS/gscf*
146
147# deploy production war
148echo ".deploying new production WAR"
149cp target/gscf-$APP_VERSION.war $PATH_TOMCAT_WEBAPPS
150
151# patch datasource.groovy
152echo ".patching datasource for demo instance"
153sed -i 's/5432\/gscf/5432\/gscf-demo/g' grails-app/conf/DataSource.groovy
154
155# patch Searchable.groovy
156echo ".patching searchable for demo instance"
157sed -i 's/searchable\/gscf\//searchable\/gscf-demo\//g' grails-app/conf/Searchable.groovy
158
159# check if the demo was indeed patched correctly
160CHECK=`cat grails-app/conf/DataSource.groovy | grep -i gscf-demo | wc -l`
161if [ $CHECK -eq 0 ]
162then
163        echo ".ERROR: datasource was not patched correctly!"
164        echo ".exiting..."
165        exit;
166fi
167
168# build demo war
169echo ".building demo war"
170grails prod war > /dev/null
171
172# deploying new demo war
173echo ".deploying new demo war"
174cp target/gscf-$APP_VERSION.war $PATH_TOMCAT_WEBAPPS/gscf-$APP_VERSION-demo.war
175
176# start tomcat
177echo ".starting tomcat"
178$PATH_TOMCAT_BIN/startup.sh 2>&1 /dev/null &
179
180# fix apache virtual host configuration
181echo ".updating apache virtual host configuration"
182ls $APACHE_VHOST_FILES|xargs -i sed -i 's/gscf-[0-9]\.[0-9]\.[0-9]/gscf-'$APP_VERSION'/g' {}
183
184# reloading apache
185echo ".telling apache to reload the configuration files (this might take 1 minute to complete)..."
186touch ~/reload_apache
187
188# done...
189echo ".done..."
190
Note: See TracBrowser for help on using the repository browser.