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 @ 1589:94669513c53c

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 1589:94669513c53c Chris
            openjdk-9-jdk-headless \
40 1582:f26dc3004b3f Chris
            postgresql \
41 1587:d8949733849d Chris
            rsync \
42
            ruby \
43
            ruby-dev \
44
            sudo
45 1582:f26dc3004b3f Chris
46 1587:d8949733849d Chris
apt-get clean && rm -rf /var/lib/apt/lists/*
47
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 1589:94669513c53c Chris
# The "code" user (in group www-data) owns the site and repo
68
# directories.
69
70 1577:e38eee2e1d47 Chris
if ! grep -q '^code:' /etc/passwd ; then
71
    groupadd code
72
    useradd -g code -G www-data code
73
fi
74
75
#!/bin/bash
76
77
set -e
78
79 1589:94669513c53c Chris
# We might be running in one of two ways:
80
#
81
# 1. The code directory is already at /var/www/code, either because a
82
# previous provisioning step has imported it there or because this
83
# script has been run before -- in this situation all we do is
84
# re-check the ownership and permissions. OR
85
#
86
# 2. The code directory has not yet been copied to /var/www/code, in
87
# which case we expect to find it at /code-to-deploy, e.g. as a
88
# Vagrant shared folder, and we copy it over from there. (We don't
89
# deploy directly from shared folders as we might not be able to
90
# manipulate ownership and permissions properly there.)
91
92 1577:e38eee2e1d47 Chris
if [ ! -d /var/www/code ]; then
93 1587:d8949733849d Chris
    if [ ! -d /code-to-deploy ]; then
94 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?"
95 1587:d8949733849d Chris
        exit 2
96
    fi
97
    cp -a /code-to-deploy /var/www/code
98 1577:e38eee2e1d47 Chris
fi
99
100 1587:d8949733849d Chris
chown -R code.www-data /var/www/code
101
find /var/www/code -type d -exec chmod g+s \{\} \;
102
103
104 1577:e38eee2e1d47 Chris
#!/bin/bash
105
106
set -e
107
108 1589:94669513c53c Chris
# In a real deployment, /var/hg is probably mounted from somewhere
109
# else. But in an empty deployment we need to create it, and in both
110
# cases we set up the config files with their current versions here.
111
112 1577:e38eee2e1d47 Chris
if [ ! -f /var/hg/index.cgi ]; then
113
    mkdir -p /var/hg
114
fi
115 1589:94669513c53c Chris
116
cp /var/www/code/deploy/config/index.cgi /var/hg/
117
cp /var/www/code/deploy/config/hgweb.config /var/hg/
118
119
chmod +x /var/hg/index.cgi
120
121
chown -R code.www-data /var/hg
122
find /var/hg -type d -exec chmod g+s \{\} \;
123
124 1577:e38eee2e1d47 Chris
#!/bin/bash
125
126
set -e
127
128 1589:94669513c53c Chris
# Copy across the database config file (the source file has presumably
129
# been generated from a skeleton, earlier in provisioning)
130
131 1587:d8949733849d Chris
infile=/var/www/code/deploy/config/database.yml
132 1589:94669513c53c Chris
outfile=/var/www/code/config/database.yml
133 1587:d8949733849d Chris
134 1589:94669513c53c Chris
if [ ! -f "$outfile" ]; then
135
    if [ ! -f "$infile" ]; then
136
        echo "ERROR: Database config file $infile not found - has the database secret been interpolated from $infile.in correctly?"
137
        exit 2
138
    fi
139
    cp "$infile" "$outfile"
140 1577:e38eee2e1d47 Chris
fi
141
142
#!/bin/bash
143
144
set -e
145
146 1589:94669513c53c Chris
# Install Ruby gems for the web app.
147
148
# We aim to make all of these provisioning scripts non-destructive if
149
# run more than once. In this case, running the script again will
150
# install any outstanding updates.
151
152 1577:e38eee2e1d47 Chris
cd /var/www/code
153
gem install bundler
154
bundle install
155
156
#!/bin/bash
157
158
set -e
159
160 1589:94669513c53c Chris
# Create a session token if it hasn't already been created.
161
162 1577:e38eee2e1d47 Chris
cd /var/www/code
163
164 1589:94669513c53c Chris
if [ ! -f config/initializers/secret_token.rb ]; then
165
    bundle exec rake generate_secret_token
166
fi
167
168
169 1577:e38eee2e1d47 Chris
#!/bin/bash
170
171
set -e
172
173 1589:94669513c53c Chris
# Start the database and if a dump file is found, load it. The dump
174
# file is then deleted so that the db won't be overwritten on
175
# subsequent runs. (The original repo contains no dump file, so it
176
# should exist only if you have provided some data to load.)
177
178 1577:e38eee2e1d47 Chris
/etc/init.d/postgresql start
179
180
cd /var/www/code
181
182
if [ -f postgres-dumpall ]; then
183
    chmod ugo+r postgres-dumpall
184
    sudo -u postgres psql -f postgres-dumpall postgres
185 1589:94669513c53c Chris
    rm postgres-dumpall
186 1577:e38eee2e1d47 Chris
fi
187
188
#!/bin/bash
189
190
set -e
191
192 1589:94669513c53c Chris
# Install the Apache mod_perl module used for hg repo access control
193
194 1577:e38eee2e1d47 Chris
if [ ! -f /usr/local/lib/site_perl/Apache/Authn/SoundSoftware.pm ]; then
195
    mkdir -p /usr/local/lib/site_perl/Apache/Authn/
196 1589:94669513c53c Chris
    cp /var/www/code/extra/soundsoftware/SoundSoftware.pm \
197
       /usr/local/lib/site_perl/Apache/Authn/
198 1577:e38eee2e1d47 Chris
fi
199
200
#!/bin/bash
201
202
set -e
203
204 1589:94669513c53c Chris
# Install Apache config files and module loaders
205
206 1577:e38eee2e1d47 Chris
cd /var/www/code
207
208 1587:d8949733849d Chris
codeconffile=/var/www/code/deploy/config/code.conf
209
210
if [ ! -f "$codeconffile" ]; then
211
    echo "ERROR: Apache config file $codeconffile not found - has the database secret been interpolated from $codeconffile.in correctly?"
212
    exit 2
213
fi
214
215 1577:e38eee2e1d47 Chris
if [ ! -f /etc/apache2/sites-enabled/10-code.conf ]; then
216
217
    rm -f /etc/apache2/sites-enabled/000-default.conf
218
219 1587:d8949733849d Chris
    cp deploy/config/passenger.conf /etc/apache2/mods-available/
220
    cp deploy/config/passenger.load /etc/apache2/mods-available/
221
    cp deploy/config/perl.conf      /etc/apache2/mods-available/
222 1577:e38eee2e1d47 Chris
223
    ln -s ../mods-available/passenger.conf  /etc/apache2/mods-enabled/
224
    ln -s ../mods-available/passenger.load  /etc/apache2/mods-enabled/
225
    ln -s ../mods-available/perl.conf       /etc/apache2/mods-enabled/
226
    ln -s ../mods-available/expires.load    /etc/apache2/mods-enabled/
227
    ln -s ../mods-available/rewrite.load    /etc/apache2/mods-enabled/
228 1578:06ca2df3d7ca Chris
    ln -s ../mods-available/cgi.load        /etc/apache2/mods-enabled/
229 1577:e38eee2e1d47 Chris
230 1587:d8949733849d Chris
    cp "$codeconffile" /etc/apache2/sites-available/code.conf
231 1577:e38eee2e1d47 Chris
    ln -s ../sites-available/code.conf /etc/apache2/sites-enabled/10-code.conf
232
233
    apache2ctl configtest
234
235
fi
236
237 1588:9149f2098413 Chris
#!/bin/bash
238
239
set -e
240
241 1589:94669513c53c Chris
# In case we are running without a properly mounted /var/hg directory,
242
# check for the existence of one repo and, if absent, attempt to clone
243
# it so that we have something we can serve for test purposes.
244
245 1588:9149f2098413 Chris
if [ ! -d /var/hg/vamp-plugin-sdk ]; then
246
    echo "Cloning vamp-plugin-sdk repo for testing..."
247
    cd /var/hg
248
    hg clone https://code.soundsoftware.ac.uk/hg/vamp-plugin-sdk
249
    chown -R code.www-data vamp-plugin-sdk
250
fi
251 1581:ae8043b014c7 Chris
#!/bin/bash
252
253
set -e
254
255 1589:94669513c53c Chris
# Last action: start the webserver
256
257 1581:ae8043b014c7 Chris
apache2ctl restart