root/misc/scripts/gscf_continuous_integration.sh @ 704

Revision 704, 5.4 KB (checked in by duh, 4 years ago)

added continuous integration script (works on gentoo)

  • Property svn:executable set to *
Line 
1#!/bin/sh
2# Continuous integration build script
3#
4# What it does:
5# - checkout the latest source code from svn
6# - check if the grails version matches (if not, it downloads and
7#   installs that particular grails release to /home/tomcat and
8#   updates the symbolic link ~/grails to the new release)
9# - build a production war, undeploy the old release and deploy the
10#   new release to tomcat's webapps
11# - patch apache's virtual host configuration files in and trigger
12#   restart of apache
13#
14# Prerequisites:
15# - tomcat webabbs should be writable by user tomcat
16# - in the end this script touches a file to restart apache
17#   webserver. This particular cronjob running as root should
18#   be available as well
19# - obviously, postgres databases should be available
20#
21# @Author       Jeroen Wesbeek <J****n.W******@gmail.com>
22# @Since        20100720
23#
24# Revision Information:
25# $Author$
26# $Date$
27# $Rev$
28
29# GRAILS CONFIG
30export JAVA_HOME=/etc/java-config-2/current-system-vm
31export JAVAC=/etc/java-config-2/current-system-vm/bin/javac
32export JDK_HOME=/etc/java-config-2/current-system-vm
33export GRAILS_HOME=/home/tomcat/grails
34export PATH=/home/tomcat/grails/bin:$PATH
35
36# CONFIGURATION
37STAMP=`date +'%Y%m%d%H%M'`
38PROJECT=gscf
39USER=`/usr/bin/whoami`
40PATH_TOMCAT_WEBAPPS=/var/lib/tomcat-6/webapps/
41PATH_GRAILS_SOURCE=/home/tomcat/workspace/gscf
42TEMP=/home/tomcat/tmp
43SVN=`which svn`
44APACHE_VHOST_FILES=/etc/apache2/vhosts.d/osx.eu_gscf.conf
45
46# are we user tomcat?
47if [ $USER != 'tomcat' ]
48then
49        echo $STAMP "ERROR: you need to run this script as user tomcat..."
50        exit;
51fi
52
53# is the update locked?
54if [ -f $TEMP/$PROJECT.locked ]
55then
56        echo $STAMP project deployment is still happening
57        exit;
58fi
59
60# lock deployment
61touch $TEMP/$PROJECT.locked
62
63# get svn revision of HEAD and running application
64cd $PATH_GRAILS_SOURCE
65$SVN revert --recursive --quiet .
66SVN_REVISION=`$SVN update | sed -n 's/At revision \(.*\)\./\1/p'`
67RUNNING_REVISION=`cat $TEMP/$PROJECT.revision`
68
69# got an SVN revision?
70if [ "$SVN_REVISION" = "" ];
71then
72        echo $STAMP haven\'t got an svn revision?
73        rm $TEMP/$PROJECT.locked
74        exit;
75fi
76
77# is a new revision available?
78if [ "$RUNNING_REVISION" == "$SVN_REVISION" ]
79then
80        #echo $STAMP do nothing...
81        rm $TEMP/$PROJECT.locked
82        exit;
83fi
84
85# a new version is available, get application and
86# grails version of HEAD
87APP_VERSION=`sed -n 's/app.version=\(.*\)$/\1/p' <  application.properties`
88GRAILS_VERSION=`sed -n 's/app.grails.version=\(.*\)$/\1/p' <  application.properties`
89
90# feedback
91echo $STAMP newer version of $PROJECT is available
92echo $STAMP "deploying revision "$SVN_REVISION" (version "$APP_VERSION" / Grails "$GRAILS_VERSION") and undeploying revision "$RUNNING_REVISION"..."
93
94# see if this grails version is available
95if [ ! -d "/home/tomcat/grails-"$GRAILS_VERSION ]
96then
97        echo $STAMP "grails version "$GRAILS_VERSION" is not installed."
98
99        cd ~
100        ls -1 ~|grep grails|grep zip|xargs -i rm ~/{}
101       
102        echo $STAMP "downloading grails release "$GRAILS_VERSION"... (this might take a while)"
103        wget -q "http://dist.codehaus.org/grails/grails-"$GRAILS_VERSION".zip"
104
105        # success?
106        if [ ! -f "grails-"$GRAILS_VERSION".zip" ]
107        then
108                echo $STAMP "could not download and install grails "$GRAILS_VERSION
109                echo $STAMP "do it manually instead and update the symbolic link..."
110                exit;
111        fi
112
113        # unzip archive
114        echo $STAMP "unzipping grails release "$GRAILS_VERSION
115        unzip -qq "grails-"$GRAILS_VERSION".zip"
116
117        # update symlink
118        echo $STAMP "updating symbolic link"
119        rm grails
120        ln -s "grails-"$GRAILS_VERSION grails
121
122        # switch to source dir
123        cd $PATH_GRAILS_SOURCE
124fi
125
126# patch index page to contain revision information
127echo $STAMP patching index page...
128sed -i 's/<\/b>/<\/b> \(<font color="red">svn revision: '$SVN_REVISION', deployed at: '$STAMP'<\/font>\)/g' grails-app/views/home/index.gsp
129sed -i 's/Welcome to GSCF version/Welcome to the <b>continuous integration build<\/b> of GSCF/g' grails-app/views/home/index.gsp
130
131# build new war
132echo $STAMP building new war...
133grails prod war > /dev/null
134
135# stop tomcat
136# (a couple of times, sometimes it does not work
137#  properly or is slow. make sure sudoers is
138#  configured properly. On NBX-es this does not
139#  work as it uses shared modules that -somehow-
140#  make the sudo commands fail)
141echo $STAMP stopping tomcat...
142sudo /etc/init.d/tomcat-6 stop > /dev/null
143sleep 10
144sudo /etc/init.d/tomcat-6 stop > /dev/null
145sleep 10
146sudo /etc/init.d/tomcat-6 stop > /dev/null
147sleep 10
148
149# undeploying gscf releases
150rm -rf $PATH_TOMCAT_WEBAPPS/gscf*
151
152# deploying new build
153echo $STAMP deploying new production WAR
154cp target/gscf-$APP_VERSION.war $PATH_TOMCAT_WEBAPPS
155
156# start tomcat
157# (make sure sudoers is configured properly. On NBX-es
158#  this does not work as it uses shared modules that
159#  -somehow- make the sudo commands fail)
160echo $STAMP starting tomcat...
161sudo /etc/init.d/tomcat-6 start > /dev/null
162
163# fix virtual host files
164echo $STAMP updating apache virtual host configuration
165ls $APACHE_VHOST_FILES|xargs -i sed -i 's/gscf-[0-9]\.[0-9]\.[0-9]/gscf-'$APP_VERSION'/g' {}
166
167# restart apache
168# (make sure sudoers is configured properly. On NBX-es
169#  this does not work as it uses shared modules that
170#  -somehow- make the sudo commands fail)
171echo $STAMP reloading Apache
172sudo /etc/init.d/apache2 graceful > /dev/null
173
174# update revision file
175echo $SVN_REVISION > $TEMP/$PROJECT.revision
176
177# remove lock file
178if [ -f $TEMP/$PROJECT.locked ]
179then
180        rm $TEMP/$PROJECT.locked
181fi
182
183echo $STAMP" done deploying "$PROJECT" revision "$SVN_REVISION" (version "$APP_VERSION")"
Note: See TracBrowser for help on using the browser.