This repository has been archived by the owner on Jun 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy-openquake-centos6.sh
executable file
·319 lines (259 loc) · 9.54 KB
/
deploy-openquake-centos6.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
#!/bin/bash
# CentOS/RHEL OpenQuake deployment script
# Copyright (C) 2013-2014, Daniele Viganò (daniele@vigano.me), GEM Foundation
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
## Initialization
if [ $GEM_SET_DEBUG ]; then
set -x
fi
set -e
set -o pipefail
if [ $GEM_SET_OQPREFIX ]; then
OQPREFIX=$GEM_SET_OQPREFIX
else
OQPREFIX='/opt/openquake'
fi
if [ $GEM_SET_OQUSER ]; then
OQUSER=$GEM_SET_OQUSER
else
OQUSER='oq-engine'
fi
function run_tests {
cd $OQPREFIX/openquake/oq-engine
nosetests -v --with-xunit --with-coverage --cover-package=openquake.engine --with-doctest -x tests/
nosetests -a 'qa,hazard,classical' -v --with-xunit --xunit-file=xunit-qa-hazard-classical.xml
nosetests -a 'qa,hazard,event_based' -v --with-xunit --xunit-file=xunit-qa-hazard-event-based.xml
nosetests -a 'qa,hazard,disagg' -v --with-xunit --xunit-file=xunit-qa-hazard-disagg.xml
nosetests -a 'qa,hazard,scenario' -v --with-xunit --xunit-file=xunit-qa-hazard-scenario.xml
nosetests -a 'qa,risk,classical' -v --with-xunit --xunit-file=xunit-qa-risk-classical.xml
nosetests -a 'qa,risk,event_based' -v --with-xunit --xunit-file=xunit-qa-risk-event-based.xml
nosetests -a 'qa,risk,classical_bcr' -v --with-xunit --xunit-file=xunit-qa-risk-classical-bcr.xml
nosetests -a 'qa,risk,event_based_bcr' -v --with-xunit --xunit-file=xunit-qa-risk-event-based-bcr.xml
nosetests -a 'qa,risk,scenario_damage' -v --with-xunit --xunit-file=xunit-qa-risk-scenario-damage.xml
nosetests -a 'qa,risk,scenario' -v --with-xunit --xunit-file=xunit-qa-risk-scenario.xml
python-coverage xml --include="openquake/*"
}
function setup_env {
if [[ $(whoami) == "openquake" ]]; then
echo "ERROR: this script can not be run as 'openquake'. Please run it with another user." >&2 && exit 1
fi
pm "Creating $OQPREFIX with owner $OQUSER"
/usr/sbin/adduser -d $OQPREFIX $OQUSER
if [ ! -d $OQPREFIX ]; then
mkdir $OQPREFIX
fi
cd $OQPREFIX
mkdir bin local log openquake src
cat <<EOF >> $OQPREFIX/env.sh
## Lines below were added by OpenQuake deployment script
PATH=$OQPREFIX/openquake/oq-engine/bin:$OQPREFIX/local/bin:$OQPREFIX/local/sbin:$PATH:$OQPREFIX/bin
LD_LIBRARY_PATH=$OQPREFIX/local/lib:$OQPREFIX/local/lib64
CPATH=$OQPREFIX/local/include
PYTHONPATH=.:$OQPREFIX/openquake/oq-engine:$OQPREFIX/openquake/oq-hazardlib:$OQPREFIX/openquake/oq-risklib
PGDATA=$OQPREFIX/local/var/postgresql
export PATH
export LD_LIBRARY_PATH
export CPATH
export PYTHONPATH
export PGDATA
EOF
cat <<EOF >> $OQPREFIX/.bash_profile
source $OQPREFIX/env.sh
EOF
cat <<EOF >> $HOME/.screenrc
# make the shell in every window as your login shell
shell -$SHELL
EOF
source $OQPREFIX/env.sh
}
function setup_db {
su - $OQUSER -c "source $OQPREFIX/env.sh; $OQPREFIX/local/bin/initdb"
cat <<EOF >> $OQPREFIX/local/var/postgresql/postgresql.conf
standard_conforming_strings = off
EOF
cd $OQPREFIX/openquake/oq-engine/openquake/engine/bin
cat $OQPREFIX/src/openquake-centos/oq-patches/oq_create_db.patch | sed "s|_OQPREFIX_|$OQPREFIX|g" | sed "s|_OQUSER_|$OQUSER|g" | patch -p0
}
function pm {
echo -e "\n### $1 ###\n"
}
## User environment
pm 'Environment setup'
setup_env
## Build System (CentOS 6)
pm 'Install pre-requisites'
yum install -y bzip2 wget gcc gcc-c++.x86_64 compat-gcc-34-c++.x86_64 openssl-devel.x86_64 zlib*.x86_64 make.x86_64 ncurses-devel.x86_64 bzip2-devel.x86_64 readline-devel.x86_64 zip.x86_64 unzip.x86_64 nc.x86_64 libcurl-devel.x86_64 expat-devel.x86_64 gettext.x86_64 gettext-devel.x86_64 xmlto.x86_64 perl-ExtUtils-MakeMaker.x86_64 pcre.x86_64 pcre-devel.x86_64 patch.x86_64 gcc-gfortran.x86_64 compat-gcc-34-g77.x86_64 libgfortran.x86_64 blas*.x86_64 lapack*.x86_64 libxslt.x86_64 libxslt-devel.x86_64 unixODBC-devel.x86_64
## Git
pm 'Install GIT'
cd $OQPREFIX/src
wget https://github.com/git/git/archive/v2.3.1.tar.gz
tar xzf v2.3.1.tar.gz
cd git-2.3.1
make prefix=$OQPREFIX/local install
## Python 2.7
pm 'Install Python'
cd $OQPREFIX/src
wget http://www.python.org/ftp/python/2.7.8/Python-2.7.8.tgz
tar xzf Python-2.7.8.tgz
cd Python-2.7.8
./configure --prefix=$OQPREFIX/local --enable-shared
make
make install
## setuptools
cd $OQPREFIX/src
wget https://bootstrap.pypa.io/ez_setup.py -O - | python
## pip
cd $OQPREFIX/src
wget https://bootstrap.pypa.io/get-pip.py -O - | python
## numpy & scipy deps.
cp /usr/lib64/libblas.so /usr/lib64/liblapack.so $OQPREFIX/local/lib64
## numpy (1.8.1)
pm 'Install NumPy'
pip install numpy==1.8.1
## scipy (0.13.0)
pm 'Install SciPy'
pip install scipy==0.13.0
## pip various dep
pip install amqp==1.3.3 mock==1.0.1 lxml==3.3.4 psutil==1.2.1 nose==1.3.1 futures==2.1.6
## Celery
pip install Celery==3.1.6
## Django
pip install django==1.6.1
## erlang _(RabbitMQ dep.)_
pm 'Install Erlang'
cd $OQPREFIX/src
wget http://www.erlang.org/download/otp_src_R16B03.tar.gz
tar xzf otp_src_R16B03.tar.gz
cd otp_src_R16B03
./configure
make
make RELEASE_ROOT=$OQPREFIX/local/erlang release
cd $OQPREFIX/local/erlang && ./Install -minimal $OQPREFIX/local/erlang
cd bin && for a in $(ls); do ln -f -s -t $OQPREFIX/local/bin ../erlang/bin/$a; done
## RabbitMQ
pm 'Install RabbitMQ'
cd $OQPREFIX/src
wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.2.4/rabbitmq-server-3.2.4.tar.gz
tar xzf rabbitmq-server-3.2.4.tar.gz
cd rabbitmq-server-3.2.4
export TARGET_DIR=$OQPREFIX/local
export SBIN_DIR=$OQPREFIX/local/sbin
export MAN_DIR=$OQPREFIX/local/share/man/
export MNESIA_DIR=$OQPREFIX/local/var/rabbitmq
make && make install
## Postgres (9.1)
pm 'Install PostgreSQL'
cd $OQPREFIX/src
wget http://ftp.postgresql.org/pub/source/v9.3.6/postgresql-9.3.6.tar.gz
tar xzf postgresql-9.3.6.tar.gz
cd postgresql-9.3.6
./configure --prefix=$OQPREFIX/local --with-python
make
make install
## Psycopg2
pip install psycopg2==2.4.5
## Swig _(Geos dep.)_
cd $OQPREFIX/src
wget http://prdownloads.sourceforge.net/swig/swig-2.0.11.tar.gz
tar xzf swig-2.0.11.tar.gz
cd swig-2.0.11
./configure --prefix=$OQPREFIX/local --without-alllang --with-python
make
make install
## Geos _(PostGIS dep.)_
cd $OQPREFIX/src
wget http://download.osgeo.org/geos/geos-3.4.2.tar.bz2
tar xjf geos-3.4.2.tar.bz2
cd geos-3.4.2
CFLAGS="-m64" CPPFLAGS="-m64" CXXFLAGS="-m64" LDFLAGS="-m64" FFLAGS="-m64" LDFLAGS="-L/usr/lib64/" ./configure --prefix=$OQPREFIX/local --enable-python
make
make install
## proj.4 _(PostGIS dep.)_
cd $OQPREFIX/src
wget http://download.osgeo.org/proj/proj-4.8.0.tar.gz
tar xzf proj-4.8.0.tar.gz
cd proj-4.8.0
./configure --prefix=$OQPREFIX/local
make
make install
## Shapely (1.3.0)
pip install Shapely==1.3.0
## PostGIS (1.5.8)
cd $OQPREFIX/src
wget http://download.osgeo.org/postgis/source/postgis-2.1.2.tar.gz
tar xzf postgis-2.1.2.tar.gz
cd postgis-2.1.2
./configure --prefix=$OQPREFIX/local --with-projdir=$OQPREFIX/local
make
make install
cp $OQPREFIX/src/postgis-2.1.2/doc/postgis_comments.sql $OQPREFIX/local/share/postgresql/contrib/postgis-2.1
## Get useful stuff
pm 'Install the OpenQuake Engine'
cd $OQPREFIX/src
git clone https://github.com/daniviga/openquake-centos.git
cp -v $OQPREFIX/src/openquake-centos/bin/* $OQPREFIX/bin/
chmod +x $OQPREFIX/bin/*
## Get OpenQuake
cd $OQPREFIX/openquake
git clone -b release-1.3 https://github.com/gem/oq-engine.git
git clone -b release-1.3 https://github.com/gem/oq-hazardlib.git
git clone -b release-1.3 https://github.com/gem/oq-risklib.git
## Setup OpenQuake
cd $OQPREFIX/openquake/oq-engine
echo "GEOS_LIBRARY_PATH = '$OQPREFIX/local/lib/libgeos_c.so'" >> openquake/engine/settings.py
## Build hazardlib speedups
cd $OQPREFIX/openquake/oq-hazardlib
python setup.py build_ext
cd openquake/hazardlib/geo
ln -f -s ../../../build/lib.*/openquake/hazardlib/geo/*.so .
chown -R $OQUSER.$OQUSER $OQPREFIX
chmod 755 $OQPREFIX
### DB setup
setup_db
su - $OQUSER -c "$OQPREFIX/local/bin/pg_ctl -D $OQPREFIX/local/var/postgresql -l $OQPREFIX/postgresql-main.log start"
pm 'Wait the DB to come up'
sleep 10
for i in {1..5}; do
su - $OQUSER -c "$OQPREFIX/local/bin/pg_ctl -D $OQPREFIX/local/var/postgresql -l $OQPREFIX/postgresql-main.log status > /dev/null"
if [ $? -ne 0 ]; then
sleep 5
else
break
fi
done
pm 'Install the OpenQuake Engine DB'
su - $OQUSER -c "$OQPREFIX/openquake/oq-engine/bin/oq_create_db --db-name=openquake2 --yes"
$OQPREFIX/openquake/oq-engine/bin/oq-engine --upgrade-db --yes
pm 'Start the OpenQuake Engine software stack and services'
cat $OQPREFIX/src/openquake-centos/init.d/oq-engine | sed "s|_OQPREFIX_|$OQPREFIX|g" | sed "s|_OQUSER_|$OQUSER|g" > /etc/rc.d/init.d/oq-engine
chmod +x /etc/rc.d/init.d/oq-engine
chkconfig --add oq-engine
service oq-engine stop
service oq-engine start
pm 'DONE!'
### Run a real computation test
#cd $OQPREFIX/openquake/oq-engine
#bin/openquake --rh=demos/hazard/SimpleFaultSourceClassicalPSHA/job.ini
#
### Extra tools
#### htop
#cd $OQPREFIX/src
#wget http://downloads.sourceforge.net/project/htop/htop/1.0.2/htop-1.0.2.tar.gz
#tar xzf htop-1.0.2.tar.gz
#cd htop-1.0.2
#./configure --prefix=$OQPREFIX/local
#make
#make install
#htop