Parent: [2d537b] (diff)

Child: [f635f7] (diff)

Download this file

fabfile.py    265 lines (209 with data), 7.9 kB

  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
"""
Staging the OSP allura
* For the most part this is ubuntu specific
* This requires fabric 1.5
"""
from fabric.api import *
from fabric.contrib.console import confirm
from fabric.contrib import files
from fabric.context_managers import *
from contextlib import contextmanager as _contextmanager
from fabric.contrib.console import confirm
import os
env.use_ssh_config = True
env.hosts = ['osp-staging']
#
# Some more or less hardcoded options
#
#ALLURA_GIT_REPO = 'http://git-wip-us.apache.org/repos/asf/incubator-allura'
#ALLURA_GIT_BRANCH = 'asf_release_1.0.0'
ALLURA_GIT_REPO = 'https://opensourceprojects.eu/git/p/osp/allura'
ALLURA_GIT_BRANCH = 'opensourceprojects'
OSP_GIT_REPO = 'http://opensourceprojects.eu/git/p/osp/opensourceprojects'
PKGDEPS = 'mongodb-server git-core default-jre-headless python-dev libssl-dev libldap2-dev libsasl2-dev libjpeg8-dev zlib1g-dev'
def _fix_lib64(name, lib='/usr/lib', lib64='/usr/lib/x86_64-linux-gnu'):
"""
Create symlinks in /usr/lib to libs in /usr/lib/x86_64...
"""
if files.exists(lib64) and not files.exists(os.path.join(lib, name )):
sudo('ln -s %s %s' % (os.path.join(lib64, name), lib))
def install(what):
"""
Install packages using apt-get
"""
sudo('DEBIAN_FRONTEND=noninteractive apt-get -q -y install %s' % what)
def enable_service(what):
"""
Enable service using update-rc.d
"""
sudo('update-rc.d %s enable' % what)
def setup_system():
"""
Install packages and setup stuff - run this on a new system
"""
sudo('apt-get update') # In case no one ran this before
install(PKGDEPS)
_fix_lib64('libz.so')
_fix_lib64('libjpeg.so')
install('subversion python-svn')
install('apache2 slapd ldap-utils')
install('build-essential g++') # * We might need this
install('python-matplotlib libfreetype6-dev libpng12-dev libjpeg-dev') # * Honestly I prefer to use the system packages
# for this - pip install is prone to fail
# here
# pip, virtualenv
install('python-pip')
sudo('pip install virtualenv')
if not user_exists('allura'):
sudo('useradd -r -s /bin/bash allura')
if not user_exists('solr'):
sudo('useradd -r -s /bin/bash solr')
sudo('update-rc.d apache2 enable')
sudo('update-rc.d mongodb enable')
sudo('a2enmod proxy_http')
ALLURA_BASE = '/opt/allura/'
ALLURA_ANVIL = os.path.join(ALLURA_BASE, 'anvil')
ALLURA_SRC = os.path.join(ALLURA_BASE, 'forge-src')
LOGDIR = os.path.join(ALLURA_BASE, 'log')
SOLR = os.path.join(ALLURA_BASE, 'solr')
@_contextmanager
def _virtualenv():
with prefix('source %s' % os.path.join(ALLURA_ANVIL, 'bin/activate')):
yield
def setup_allura():
"""
Setup allura installation
"""
if not files.exists(ALLURA_BASE):
sudo('mkdir %s' % ALLURA_BASE)
sudo('chown allura %s' % ALLURA_BASE)
if not files.exists(LOGDIR):
sudo('mkdir %s' % LOGDIR)
LOGDIR_SOLR = os.path.join(LOGDIR, 'solr')
sudo('mkdir %s' % LOGDIR_SOLR )
sudo('chown %s %s' % ('solr', LOGDIR_SOLR) )
LOGDIR_ALLURA = os.path.join(LOGDIR, 'allura')
sudo('mkdir %s' % LOGDIR_ALLURA )
sudo('chown %s %s' % ('allura', LOGDIR_ALLURA) )
# FIXME: this has not been tested yet
LOGDIR_APACHE2 = os.path.join(LOGDIR, 'apache2')
sudo('mkdir %s' % LOGDIR_APACHE2 )
sudo('chown %s %s' % ('www-data', LOGDIR_APACHE2) )
with settings(sudo_user='allura'):
#
# Run(sudo) this as user allura
#
with cd(ALLURA_BASE):
if not files.exists('forge-src'):
sudo( 'GIT_SSL_NO_VERIFY=1 git clone %s %s' % (ALLURA_GIT_REPO, ALLURA_SRC))
with cd(ALLURA_SRC):
sudo( 'git checkout %s' % ALLURA_GIT_BRANCH )
if not files.exists(ALLURA_ANVIL):
sudo('virtualenv --system-site-packages %s' % ALLURA_ANVIL)
with _virtualenv():
with cd(os.path.join(ALLURA_BASE, 'forge-src')):
sudo('pip install -r requirements.txt')
SITE_PKGS = os.path.join(ALLURA_ANVIL, 'lib/python2.7/site-packages/pysvn')
if not files.exists(SITE_PKGS):
sudo('ln -s /usr/lib/python2.7/dist-packages/pysvn %s' % SITE_PKGS )
with _virtualenv():
with cd( os.path.join(ALLURA_BASE, 'forge-src')):
with cd('Allura'):
sudo('python setup.py develop')
if files.exists('rebuild-all.bash'):
sudo('./rebuild-all.bash')
else:
# In previous versions the name was different
sudo('./rebuild.bash')
if not files.exists(SOLR):
sudo('mkdir %s' % SOLR)
sudo('chown solr %s' % SOLR)
with settings(sudo_user='solr'):
with cd(SOLR):
sudo('wget -c http://archive.apache.org/dist/lucene/solr/1.4.1/apache-solr-1.4.1.tgz')
sudo('tar xf apache-solr-1.4.1.tgz')
sudo('cp -r %s .' % os.path.join(ALLURA_SRC, 'solr_config'))
sudo('mkdir solr_config/conf')
sudo('cp apache-solr-1.4.1/example/solr/conf/solrconfig.xml solr_config/conf')
def setup_osp():
"""
Setup the OSP plugin
"""
OSP_DIR = 'OpenSourceProjects'
with cd(ALLURA_BASE):
if not files.exists(OSP_DIR):
sudo( 'GIT_SSL_NO_VERIFY=1 git clone %s %s' % (OSP_GIT_REPO, OSP_DIR))
with _virtualenv():
with cd(os.path.join(ALLURA_BASE, OSP_DIR)):
sudo('python setup.py develop')
def setup_app():
"""
Run paster setup app for allura - be *carefull* with this
"""
with settings(sudo_user='allura',
sudo_prefix=env['sudo_prefix'] + '-i '
):
with _virtualenv(), cd(os.path.join(ALLURA_SRC, 'Allura')):
sudo('paster setup-app development.ini' )
# Start services
def start_solr():
with settings(sudo_user='solr'):
with cd(os.path.join(SOLR, 'apache-solr-1.4.1/example')):
sudo('nohup java -Dsolr.solr.home=%s/solr_config -jar start.jar &> %s/solr/solr.log & sleep 1; exit 0' % (SOLR, LOGDIR))
def stop_solr():
sudo('pkill -u solr java')
def start_taskd():
# We NEED sudo -i
with settings(sudo_user='allura',
sudo_prefix=env['sudo_prefix'] + '-i '
):
with _virtualenv():
with cd(os.path.join(ALLURA_SRC, 'Allura')):
sudo('nohup paster taskd development.ini &> %s/allura/taskd.log & sleep 1; exit 0' % ( LOGDIR) )
def start_serve(config):
# We NEED sudo -i
with settings(sudo_user='allura',
sudo_prefix=env['sudo_prefix'] + '-i '
):
with _virtualenv():
sudo('nohup paster serve %s &> %s/allura/tg.log & sleep 1; exit 0' % (config, LOGDIR) )
def stop_allura():
sudo('pkill -u allura')
def start(config=ALLURA_SRC+'/Allura/development.ini'):
"""
Start all Allura related services
"""
start_solr()
start_taskd()
start_serve(config)
def start_osp():
"""
Same as @start but uses the opensourceprojects.ini settings file
"""
start(ALLURA_SRC+'/../OpenSourceProjects/opensourceprojects.ini')
def stop():
"""
Stop all services
"""
stop_solr()
stop_allura()
def restart():
"""
Stops all services and restarts a clean Allura
"""
stop()
start()
def restart_osp():
"""
Same as @restart but uses the opensourceprojects.ini settings
"""
stop()
start_osp()
def user_exists(user):
"""
Return True if a user exists or False otherwise
"""
result = run('grep %s /etc/passwd' % user, quiet=True)
if result.failed:
return False
return True