To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / deploy / provision.d @ 1606:16325d2ab2dd

1 1577:e38eee2e1d47 Chris
#!/bin/bash
2
3
set -e
4
5 1589:94669513c53c Chris
# Install necessary system packages. This assumes we are deploying on
6
# Ubuntu 16.04.
7
8
# We aim to make all of these provisioning scripts non-destructive if
9
# run more than once. In this case, running the script again will
10
# install any outstanding updates.
11
12 1587:d8949733849d Chris
apt-get update && \
13
    apt-get dist-upgrade -y && \
14
    apt-get install -y \
15
            ack-grep \
16
            apache2 \
17
            apache2-dev \
18
            apt-utils \
19
            build-essential \
20
            cron \
21 1582:f26dc3004b3f Chris
            curl \
22
            doxygen \
23 1587:d8949733849d Chris
            exim4 \
24 1582:f26dc3004b3f Chris
            git \
25 1587:d8949733849d Chris
            graphviz \
26
            imagemagick \
27
            libapache-dbi-perl \
28
            libapache2-mod-perl2 \
29
            libapr1-dev \
30
            libaprutil1-dev \
31
            libauthen-simple-ldap-perl \
32
            libcurl4-openssl-dev \
33
            libdbd-pg-perl \
34
            libpq-dev \
35
            libmagickwand-dev \
36
            libio-socket-ssl-perl \
37
            logrotate \
38 1582:f26dc3004b3f Chris
            mercurial \
39 1600:ed9c467ef922 Chris
            mercurial-git \
40 1589:94669513c53c Chris
            openjdk-9-jdk-headless \
41 1582:f26dc3004b3f Chris
            postgresql \
42 1587:d8949733849d Chris
            rsync \
43
            ruby \
44
            ruby-dev \
45
            sudo
46 1582:f26dc3004b3f Chris
47 1587:d8949733849d Chris
locale-gen en_US.UTF-8
48 1582:f26dc3004b3f Chris
49
50 1577:e38eee2e1d47 Chris
#!/bin/bash
51
52
set -e
53
54 1589:94669513c53c Chris
# Phusion Passenger as application server.
55
# This gets installed through gem, not apt, and we ask for a specific
56
# version (the last in the 4.0.x line).
57 1577:e38eee2e1d47 Chris
58
if [ ! -f /var/lib/gems/2.3.0/gems/passenger-4.0.60/buildout/apache2/mod_passenger.so ]; then
59
    gem install passenger -v 4.0.60 --no-rdoc --no-ri
60
    passenger-install-apache2-module --languages=ruby
61
fi
62
63
#!/bin/bash
64
65
set -e
66
67 1590:c18460da6620 Chris
# The webapp directory is owned and run by the code user, in group
68
# www-data. The repos and other things served directly are the other
69
# way around -- owned by the www-data user, in group code.
70 1589:94669513c53c Chris
71 1590:c18460da6620 Chris
for user in code docgen ; do
72
    if ! grep -q "^$user:" /etc/passwd ; then
73
        groupadd "$user"
74
        useradd -g "$user" -G www-data "$user"
75
    fi
76
done
77 1577:e38eee2e1d47 Chris
78
#!/bin/bash
79
80
set -e
81
82 1589:94669513c53c Chris
# We might be running in one of two ways:
83
#
84
# 1. The code directory is already at /var/www/code, either because a
85
# previous provisioning step has imported it there or because this
86
# script has been run before -- in this situation all we do is
87
# re-check the ownership and permissions. OR
88
#
89
# 2. The code directory has not yet been copied to /var/www/code, in
90
# which case we expect to find it at /code-to-deploy, e.g. as a
91
# Vagrant shared folder, and we copy it over from there. (We don't
92
# deploy directly from shared folders as we might not be able to
93
# manipulate ownership and permissions properly there.)
94
95 1577:e38eee2e1d47 Chris
if [ ! -d /var/www/code ]; then
96 1587:d8949733849d Chris
    if [ ! -d /code-to-deploy ]; then
97 1589:94669513c53c Chris
        echo "ERROR: Expected to find code tree at /var/www/code or /code-to-deploy: is the deployment script being invoked correctly?"
98 1587:d8949733849d Chris
        exit 2
99
    fi
100
    cp -a /code-to-deploy /var/www/code
101 1577:e38eee2e1d47 Chris
fi
102
103 1587:d8949733849d Chris
chown -R code.www-data /var/www/code
104 1605:18643ab36008 Chris
chmod 755 /var/www/code
105 1587:d8949733849d Chris
find /var/www/code -type d -exec chmod g+s \{\} \;
106
107 1577:e38eee2e1d47 Chris
#!/bin/bash
108
109
set -e
110
111 1589:94669513c53c Chris
# In a real deployment, /var/hg is probably mounted from somewhere
112
# else. But in an empty deployment we need to create it, and in both
113
# cases we set up the config files with their current versions here.
114
115 1577:e38eee2e1d47 Chris
if [ ! -f /var/hg/index.cgi ]; then
116
    mkdir -p /var/hg
117
fi
118 1589:94669513c53c Chris
119
cp /var/www/code/deploy/config/index.cgi /var/hg/
120
cp /var/www/code/deploy/config/hgweb.config /var/hg/
121
122
chmod +x /var/hg/index.cgi
123
124 1590:c18460da6620 Chris
chown -R www-data.code /var/hg
125 1589:94669513c53c Chris
find /var/hg -type d -exec chmod g+s \{\} \;
126
127 1577:e38eee2e1d47 Chris
#!/bin/bash
128
129
set -e
130
131 1589:94669513c53c Chris
# Copy across the database config file (the source file has presumably
132
# been generated from a skeleton, earlier in provisioning)
133
134 1593:83412a0a2389 Chris
infile=/var/www/code/deploy/config/database.yml.gen
135 1589:94669513c53c Chris
outfile=/var/www/code/config/database.yml
136 1587:d8949733849d Chris
137 1589:94669513c53c Chris
if [ ! -f "$outfile" ]; then
138
    if [ ! -f "$infile" ]; then
139
        echo "ERROR: Database config file $infile not found - has the database secret been interpolated from $infile.in correctly?"
140
        exit 2
141
    fi
142
    cp "$infile" "$outfile"
143 1577:e38eee2e1d47 Chris
fi
144
145
#!/bin/bash
146
147
set -e
148
149 1589:94669513c53c Chris
# Install Ruby gems for the web app.
150
151
# We aim to make all of these provisioning scripts non-destructive if
152
# run more than once. In this case, running the script again will
153
# install any outstanding updates.
154
155 1577:e38eee2e1d47 Chris
cd /var/www/code
156
gem install bundler
157
bundle install
158
159
#!/bin/bash
160
161
set -e
162
163 1589:94669513c53c Chris
# Create a session token if it hasn't already been created.
164
165 1577:e38eee2e1d47 Chris
cd /var/www/code
166
167 1589:94669513c53c Chris
if [ ! -f config/initializers/secret_token.rb ]; then
168
    bundle exec rake generate_secret_token
169
fi
170
171
172 1577:e38eee2e1d47 Chris
#!/bin/bash
173
174
set -e
175
176 1589:94669513c53c Chris
# Start the database and if a dump file is found, load it. The dump
177
# file is then deleted so that the db won't be overwritten on
178
# subsequent runs. (The original repo contains no dump file, so it
179
# should exist only if you have provided some data to load.)
180
181 1577:e38eee2e1d47 Chris
/etc/init.d/postgresql start
182
183
cd /var/www/code
184
185
if [ -f postgres-dumpall ]; then
186
    chmod ugo+r postgres-dumpall
187
    sudo -u postgres psql -f postgres-dumpall postgres
188 1589:94669513c53c Chris
    rm postgres-dumpall
189 1577:e38eee2e1d47 Chris
fi
190
191
#!/bin/bash
192
193
set -e
194
195 1589:94669513c53c Chris
# Install the Apache mod_perl module used for hg repo access control
196
197 1577:e38eee2e1d47 Chris
if [ ! -f /usr/local/lib/site_perl/Apache/Authn/SoundSoftware.pm ]; then
198
    mkdir -p /usr/local/lib/site_perl/Apache/Authn/
199 1589:94669513c53c Chris
    cp /var/www/code/extra/soundsoftware/SoundSoftware.pm \
200
       /usr/local/lib/site_perl/Apache/Authn/
201 1577:e38eee2e1d47 Chris
fi
202
203
#!/bin/bash
204
205
set -e
206
207 1589:94669513c53c Chris
# Install Apache config files and module loaders
208
209 1577:e38eee2e1d47 Chris
cd /var/www/code
210
211 1602:b22e234c3c7b Chris
codeconf=/var/www/code/deploy/config/code.conf.gen
212
codeconfssl=/var/www/code/deploy/config/code-ssl.conf.gen
213 1606:16325d2ab2dd Chris
staticconf=/var/www/code/deploy/config/soundsoftware-static.conf
214 1587:d8949733849d Chris
215 1602:b22e234c3c7b Chris
if [ ! -f "$codeconf" ]; then
216
    echo "ERROR: Apache config file $codeconf not found - has the database secret been interpolated from its input file correctly?"
217 1587:d8949733849d Chris
    exit 2
218
fi
219
220 1577:e38eee2e1d47 Chris
if [ ! -f /etc/apache2/sites-enabled/10-code.conf ]; then
221
222
    rm -f /etc/apache2/sites-enabled/000-default.conf
223
224 1587:d8949733849d Chris
    cp deploy/config/passenger.conf /etc/apache2/mods-available/
225
    cp deploy/config/passenger.load /etc/apache2/mods-available/
226
    cp deploy/config/perl.conf      /etc/apache2/mods-available/
227 1577:e38eee2e1d47 Chris
228
    ln -s ../mods-available/passenger.conf  /etc/apache2/mods-enabled/
229
    ln -s ../mods-available/passenger.load  /etc/apache2/mods-enabled/
230
    ln -s ../mods-available/perl.conf       /etc/apache2/mods-enabled/
231
    ln -s ../mods-available/expires.load    /etc/apache2/mods-enabled/
232
    ln -s ../mods-available/rewrite.load    /etc/apache2/mods-enabled/
233 1578:06ca2df3d7ca Chris
    ln -s ../mods-available/cgi.load        /etc/apache2/mods-enabled/
234 1605:18643ab36008 Chris
    ln -s ../mods-available/ssl.load        /etc/apache2/mods-enabled/
235 1577:e38eee2e1d47 Chris
236 1602:b22e234c3c7b Chris
    cp "$codeconf" /etc/apache2/sites-available/code.conf
237
    cp "$codeconfssl" /etc/apache2/sites-available/code-ssl.conf
238 1606:16325d2ab2dd Chris
    cp "$staticconf" /etc/apache2/sites-available/soundsoftware-static.conf
239 1577:e38eee2e1d47 Chris
    ln -s ../sites-available/code.conf /etc/apache2/sites-enabled/10-code.conf
240
241
    apache2ctl configtest
242
243
fi
244
245 1588:9149f2098413 Chris
#!/bin/bash
246
247
set -e
248
249 1589:94669513c53c Chris
# In case we are running without a properly mounted /var/hg directory,
250
# check for the existence of one repo and, if absent, attempt to clone
251
# it so that we have something we can serve for test purposes.
252
253 1588:9149f2098413 Chris
if [ ! -d /var/hg/vamp-plugin-sdk ]; then
254
    echo "Cloning vamp-plugin-sdk repo for testing..."
255
    cd /var/hg
256
    hg clone https://code.soundsoftware.ac.uk/hg/vamp-plugin-sdk
257 1590:c18460da6620 Chris
    chown -R www-data.code vamp-plugin-sdk
258 1588:9149f2098413 Chris
fi
259 1598:073a75bf07fb Chris
#!/bin/bash
260
261
set -e
262
263
# Initialise directories used as targets for cron activity (if they
264
# don't already exist)
265
266
# Reminder: the webapp directory is owned and run by the code user, in
267
# group www-data. The repos and other things served directly are
268
# usually the other way around -- owned by the www-data user, in group
269
# code. I don't recall whether there is a good reason for this.
270
271
for dir in \
272
    /var/files/backups \
273
    /var/doc \
274
    /var/files/git-mirror ; do
275
    if [ ! -d "$dir" ]; then
276
        mkdir -p "$dir"
277
        chown -R code.www-data "$dir"
278
        chmod g+s "$dir"
279
    fi
280
done
281
282
for dir in \
283
    /var/mirror ; do
284
    if [ ! -d "$dir" ]; then
285
        mkdir -p "$dir"
286
        chown -R www-data.code "$dir"
287
        chmod g+s "$dir"
288
    fi
289
done
290 1590:c18460da6620 Chris
#!/bin/bash
291
292
set -e
293
294 1596:45b0571b684d Chris
# Copy docgen scripts, including the generated scripts with
295
# interpolated API key etc, to the directory they will be run from.
296
297
# These are run from cron jobs to do the (currently daily) update of
298
# extracted documentation from Doxygen, Javadoc, and MATLAB, and to
299
# enable displaying them with the redmine_embedded plugin. (The API
300
# key is needed to automatically switch on the embedded module for a
301
# project the first time its docs are extracted.)
302 1590:c18460da6620 Chris
303
cd /var/www/code
304
305
mkdir -p docgen
306
307
for file in \
308
    doxysafe.pl \
309
    extract-doxygen.sh \
310
    extract-javadoc.sh \
311
    extract-matlabdocs.sh \
312
    matlab-docs.conf \
313
    matlab-docs-credit.html \
314
    matlab-docs.pl ; do
315
    if [ ! -f docgen/"$file" ]; then
316
        cp extra/soundsoftware/"$file" docgen/
317
    fi
318
done
319
320 1593:83412a0a2389 Chris
for file in \
321
    extract-docs.sh ; do
322
    if [ ! -f docgen/"$file" ]; then
323
        cp deploy/config/"$file".gen docgen/"$file"
324
    fi
325
done
326
327 1590:c18460da6620 Chris
chown code.www-data docgen/*
328
chmod +x docgen/*.sh
329
330
#!/bin/bash
331
332
set -e
333
334 1596:45b0571b684d Chris
# Copy reposman (repository manager) scripts, including the generated
335
# scripts with interpolated API key etc, to the directory they will be
336
# run from.
337
338
# There are two sets of scripts here:
339
#
340
# 1. The reposman script that plods through all the projects that have
341
# repositories defined, creates those repositories on disc, and
342
# registers their locations with the projects. This happens often,
343
# currently every minute.
344
#
345
# 2. The external repo management script that plods through all the
346
# projects that have external repositories defined, clones or updates
347
# those external repos to their local locations, and if necessary
348
# registers them with the projects. This happens less often, currently
349
# every hour.
350 1590:c18460da6620 Chris
351
cd /var/www/code
352
353
mkdir -p reposman
354
355
for file in \
356
    convert-external-repos.rb \
357
    reposman-soundsoftware.rb \
358
    run-hginit.sh \
359
    update-external-repo.sh ; do
360
    if [ ! -f reposman/"$file" ]; then
361
        cp extra/soundsoftware/"$file" reposman/
362
    fi
363
done
364
365
for file in \
366
    run-external.sh \
367
    run-reposman.sh ; do
368
    if [ ! -f reposman/"$file" ]; then
369 1593:83412a0a2389 Chris
        cp deploy/config/"$file".gen reposman/"$file"
370 1590:c18460da6620 Chris
    fi
371
done
372
373
chown code.www-data reposman/*
374
chmod +x reposman/*.sh
375
chmod +x reposman/*.rb
376
377
touch /var/log/reposman.log
378
touch /var/log/external-repos.log
379
chown www-data.code /var/log/reposman.log
380
chown www-data.code /var/log/external-repos.log
381
382
#!/bin/bash
383
384
set -e
385
386
# Copy cron scripts to the appropriate destinations
387
388
cd /var/www/code
389
390
if [ ! -d /etc/cron.minutely ]; then
391
    mkdir -p /etc/cron.minutely
392
    echo '*  *    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.minutely )' >> /etc/crontab
393
fi
394
395
for t in minutely hourly daily monthly; do
396
    for s in deploy/config/cron.$t/[0-9]* ; do
397
        name=$(basename $s)
398
        dest="/etc/cron.$t/$name"
399
        if [ ! -f "$dest" ]; then
400
            cp "$s" "$dest"
401
            chmod +x "$dest"
402
        fi
403
    done
404
done
405
406
407
408
#!/bin/bash
409
410
cd /var/www/code
411
cp deploy/config/logrotate.conf /etc/logrotate.conf
412 1601:07deb8466f65 Chris
#!/bin/bash
413
414
set -e
415
416
# Print reminders of the things that we haven't covered in the deploy
417
# scripts
418
419
cat <<EOF
420
421
*** APACHE SSL CONFIGURATION
422
423
    The provisioning scripts set up a simple HTTP site only. Refer to
424 1606:16325d2ab2dd Chris
    code-ssl.conf for an example HTTPS configuration (you will of
425
    course need to provide the key/cert files).
426
427
*** SMOKE TEST
428
429
    There is a smoke test script in the deploy/test directory. That
430
    is, a quick automated acceptance test that checks that basic
431
    services are returning successful HTTP codes. Consider running it
432
    against this server from another host, i.e. not just localhost.
433 1601:07deb8466f65 Chris
434
*** EMAIL
435
436
    Outgoing email is required for notifications, but has not been
437
    configured as part of this provisioning setup.
438
439
*** STATIC FRONT PAGE
440
441
    We have set up only the code/repository site -- if you want a
442
    separate front page, remember to configure that!
443
444
EOF
445 1581:ae8043b014c7 Chris
#!/bin/bash
446
447
set -e
448
449 1601:07deb8466f65 Chris
# Last action: check & start the webserver
450
451
apache2ctl configtest
452 1589:94669513c53c Chris
453 1581:ae8043b014c7 Chris
apache2ctl restart