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 @ 1611:89d3095ddc70

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