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 @ 1602:b22e234c3c7b

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
find /var/www/code -type d -exec chmod g+s \{\} \;
105
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 1587:d8949733849d Chris
214 1602:b22e234c3c7b Chris
if [ ! -f "$codeconf" ]; then
215
    echo "ERROR: Apache config file $codeconf not found - has the database secret been interpolated from its input file correctly?"
216 1587:d8949733849d Chris
    exit 2
217
fi
218
219 1577:e38eee2e1d47 Chris
if [ ! -f /etc/apache2/sites-enabled/10-code.conf ]; then
220
221
    rm -f /etc/apache2/sites-enabled/000-default.conf
222
223 1587:d8949733849d Chris
    cp deploy/config/passenger.conf /etc/apache2/mods-available/
224
    cp deploy/config/passenger.load /etc/apache2/mods-available/
225
    cp deploy/config/perl.conf      /etc/apache2/mods-available/
226 1577:e38eee2e1d47 Chris
227
    ln -s ../mods-available/passenger.conf  /etc/apache2/mods-enabled/
228
    ln -s ../mods-available/passenger.load  /etc/apache2/mods-enabled/
229
    ln -s ../mods-available/perl.conf       /etc/apache2/mods-enabled/
230
    ln -s ../mods-available/expires.load    /etc/apache2/mods-enabled/
231
    ln -s ../mods-available/rewrite.load    /etc/apache2/mods-enabled/
232 1578:06ca2df3d7ca Chris
    ln -s ../mods-available/cgi.load        /etc/apache2/mods-enabled/
233 1577:e38eee2e1d47 Chris
234 1602:b22e234c3c7b Chris
    cp "$codeconf" /etc/apache2/sites-available/code.conf
235
    cp "$codeconfssl" /etc/apache2/sites-available/code-ssl.conf
236 1577:e38eee2e1d47 Chris
    ln -s ../sites-available/code.conf /etc/apache2/sites-enabled/10-code.conf
237
238
    apache2ctl configtest
239
240
fi
241
242 1588:9149f2098413 Chris
#!/bin/bash
243
244
set -e
245
246 1589:94669513c53c Chris
# In case we are running without a properly mounted /var/hg directory,
247
# check for the existence of one repo and, if absent, attempt to clone
248
# it so that we have something we can serve for test purposes.
249
250 1588:9149f2098413 Chris
if [ ! -d /var/hg/vamp-plugin-sdk ]; then
251
    echo "Cloning vamp-plugin-sdk repo for testing..."
252
    cd /var/hg
253
    hg clone https://code.soundsoftware.ac.uk/hg/vamp-plugin-sdk
254 1590:c18460da6620 Chris
    chown -R www-data.code vamp-plugin-sdk
255 1588:9149f2098413 Chris
fi
256 1598:073a75bf07fb Chris
#!/bin/bash
257
258
set -e
259
260
# Initialise directories used as targets for cron activity (if they
261
# don't already exist)
262
263
# Reminder: the webapp directory is owned and run by the code user, in
264
# group www-data. The repos and other things served directly are
265
# usually the other way around -- owned by the www-data user, in group
266
# code. I don't recall whether there is a good reason for this.
267
268
for dir in \
269
    /var/files/backups \
270
    /var/doc \
271
    /var/files/git-mirror ; do
272
    if [ ! -d "$dir" ]; then
273
        mkdir -p "$dir"
274
        chown -R code.www-data "$dir"
275
        chmod g+s "$dir"
276
    fi
277
done
278
279
for dir in \
280
    /var/mirror ; do
281
    if [ ! -d "$dir" ]; then
282
        mkdir -p "$dir"
283
        chown -R www-data.code "$dir"
284
        chmod g+s "$dir"
285
    fi
286
done
287 1590:c18460da6620 Chris
#!/bin/bash
288
289
set -e
290
291 1596:45b0571b684d Chris
# Copy docgen scripts, including the generated scripts with
292
# interpolated API key etc, to the directory they will be run from.
293
294
# These are run from cron jobs to do the (currently daily) update of
295
# extracted documentation from Doxygen, Javadoc, and MATLAB, and to
296
# enable displaying them with the redmine_embedded plugin. (The API
297
# key is needed to automatically switch on the embedded module for a
298
# project the first time its docs are extracted.)
299 1590:c18460da6620 Chris
300
cd /var/www/code
301
302
mkdir -p docgen
303
304
for file in \
305
    doxysafe.pl \
306
    extract-doxygen.sh \
307
    extract-javadoc.sh \
308
    extract-matlabdocs.sh \
309
    matlab-docs.conf \
310
    matlab-docs-credit.html \
311
    matlab-docs.pl ; do
312
    if [ ! -f docgen/"$file" ]; then
313
        cp extra/soundsoftware/"$file" docgen/
314
    fi
315
done
316
317 1593:83412a0a2389 Chris
for file in \
318
    extract-docs.sh ; do
319
    if [ ! -f docgen/"$file" ]; then
320
        cp deploy/config/"$file".gen docgen/"$file"
321
    fi
322
done
323
324 1590:c18460da6620 Chris
chown code.www-data docgen/*
325
chmod +x docgen/*.sh
326
327
#!/bin/bash
328
329
set -e
330
331 1596:45b0571b684d Chris
# Copy reposman (repository manager) scripts, including the generated
332
# scripts with interpolated API key etc, to the directory they will be
333
# run from.
334
335
# There are two sets of scripts here:
336
#
337
# 1. The reposman script that plods through all the projects that have
338
# repositories defined, creates those repositories on disc, and
339
# registers their locations with the projects. This happens often,
340
# currently every minute.
341
#
342
# 2. The external repo management script that plods through all the
343
# projects that have external repositories defined, clones or updates
344
# those external repos to their local locations, and if necessary
345
# registers them with the projects. This happens less often, currently
346
# every hour.
347 1590:c18460da6620 Chris
348
cd /var/www/code
349
350
mkdir -p reposman
351
352
for file in \
353
    convert-external-repos.rb \
354
    reposman-soundsoftware.rb \
355
    run-hginit.sh \
356
    update-external-repo.sh ; do
357
    if [ ! -f reposman/"$file" ]; then
358
        cp extra/soundsoftware/"$file" reposman/
359
    fi
360
done
361
362
for file in \
363
    run-external.sh \
364
    run-reposman.sh ; do
365
    if [ ! -f reposman/"$file" ]; then
366 1593:83412a0a2389 Chris
        cp deploy/config/"$file".gen reposman/"$file"
367 1590:c18460da6620 Chris
    fi
368
done
369
370
chown code.www-data reposman/*
371
chmod +x reposman/*.sh
372
chmod +x reposman/*.rb
373
374
touch /var/log/reposman.log
375
touch /var/log/external-repos.log
376
chown www-data.code /var/log/reposman.log
377
chown www-data.code /var/log/external-repos.log
378
379
#!/bin/bash
380
381
set -e
382
383
# Copy cron scripts to the appropriate destinations
384
385
cd /var/www/code
386
387
if [ ! -d /etc/cron.minutely ]; then
388
    mkdir -p /etc/cron.minutely
389
    echo '*  *    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.minutely )' >> /etc/crontab
390
fi
391
392
for t in minutely hourly daily monthly; do
393
    for s in deploy/config/cron.$t/[0-9]* ; do
394
        name=$(basename $s)
395
        dest="/etc/cron.$t/$name"
396
        if [ ! -f "$dest" ]; then
397
            cp "$s" "$dest"
398
            chmod +x "$dest"
399
        fi
400
    done
401
done
402
403
404
405
#!/bin/bash
406
407
cd /var/www/code
408
cp deploy/config/logrotate.conf /etc/logrotate.conf
409 1601:07deb8466f65 Chris
#!/bin/bash
410
411
set -e
412
413
# Print reminders of the things that we haven't covered in the deploy
414
# scripts
415
416
cat <<EOF
417
418
*** APACHE SSL CONFIGURATION
419
420
    The provisioning scripts set up a simple HTTP site only. Refer to
421
    deploy/config/code-ssl.conf.in for an example HTTPS configuration
422
    (you will of course need to provide the key/cert files).
423
424
*** EMAIL
425
426
    Outgoing email is required for notifications, but has not been
427
    configured as part of this provisioning setup.
428
429
*** STATIC FRONT PAGE
430
431
    We have set up only the code/repository site -- if you want a
432
    separate front page, remember to configure that!
433
434
EOF
435 1581:ae8043b014c7 Chris
#!/bin/bash
436
437
set -e
438
439 1601:07deb8466f65 Chris
# Last action: check & start the webserver
440
441
apache2ctl configtest
442 1589:94669513c53c Chris
443 1581:ae8043b014c7 Chris
apache2ctl restart