-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathVagrantfile
250 lines (212 loc) · 9.58 KB
/
Vagrantfile
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
# -*- mode: ruby -*-
# vi: set ft=ruby shiftwidth=4 :
# Enable this to do a build after the system is set up.
do_build = true
Vagrant.configure("2") do |config|
# Disable audio and get reasonable specs
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--audio", "none"]
vb.cpus = 2
vb.memory = 2048
end
# Skip VB Gest Additions update
if Vagrant.has_plugin?("vagrant-vbguest")
config.vbguest.auto_update = false
end
# Build an el7 machine as the default
config.vm.define "esmond-el7-py3", primary: true, autostart: true do |el7|
# set box to official CentOS 7 image
el7.vm.box = "bento/centos-7"
# explcitly set shared folder to virtualbox type. If not set will choose rsync
# which is just a one-way share that is less useful in this context
el7.vm.synced_folder ".", "/vagrant", type: "virtualbox"
# Set hostname
el7.vm.hostname = "esmond-el7-py3"
el7.vm.provider "virtualbox" do |v|
# Prevent VirtualBox from interfering with host audio stack
v.customize ["modifyvm", :id, "--audio", "none"]
end
# Enable IPv4. Cannot be directly before or after line that sets IPv6 address. Looks
# to be a strange bug where IPv6 and IPv4 mixed-up by vagrant otherwise and one
#interface will appear not to have an address. If you look at network-scripts file
# you will see a mangled result where IPv4 is set for IPv6 or vice versa
#el7.vm.network "private_network", ip: "10.0.0.203"
# Setup port forwarding to apache
#el7.vm.network "forwarded_port", guest: 443, host: "21443", host_ip: "127.0.0.1"
#el7.vm.network "forwarded_port", guest: 80, host: "21080", host_ip: "127.0.0.1"
# Enable IPv6. Currently only supports setting via static IP. Address below in the
# reserved local address range for IPv6
#el7.vm.network "private_network", ip: "fdac:218a:75e5:69c8::203"
#Disable selinux
el7.vm.provision "disable-selinux", type: "shell", inline: <<-SHELL
sed -i s/SELINUX=enforcing/SELINUX=permissive/g /etc/selinux/config
SHELL
#reload VM since selinux requires reboot. Requires `vagrant plugin install vagrant-reload`
el7.vm.provision :reload
#Install all requirements and perform initial setup
el7.vm.provision "initial-setup", type: "shell", inline: <<-SHELL
#env variables
export ESMOND_ROOT=/usr/lib/esmond
export ESMOND_CONF=/etc/esmond/esmond.conf
export DJANGO_SETTINGS_MODULE=esmond.settings
## install yum dependencies
yum install -y epel-release
yum install -y centos-release-scl
yum install -y http://software.internet2.edu/rpms/el7/x86_64/4/packages/perfSONAR-repo-0.9-1.noarch.rpm
# TODO: Should be from production
yum install -y perfSONAR-repo-nightly-minor
yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
yum clean all
yum install -y gcc\
kernel-devel\
kernel-headers\
dkms\
make\
bzip2\
perl\
python3\
python3-virtualenv\
httpd\
mod_wsgi\
python3-mock\
python3-memcached\
python3-psycopg2\
python3-requests\
python3-thrift\
rh-python36-mod_wsgi\
cassandra20\
sqlite\
sqlite-devel\
memcached\
java-1.7.0-openjdk\
postgresql10\
postgresql10-server\
postgresql10-devel\
drop-in
## setup shared folders and files
if ! [ -d /vagrant/vagrant-data/esmond-el7/etc/esmond ]; then
rm -rf /vagrant/vagrant-data/esmond-el7/etc/esmond
fi
if ! [ -L /etc/esmond ]; then
rm -rf /etc/esmond
fi
if ! [ -L /usr/lib/esmond ]; then
rm -rf /usr/lib/esmond
fi
mkdir -p /vagrant/vagrant-data/esmond-el7/etc/esmond
cd /vagrant
ln -fs /vagrant/vagrant-data/esmond-el7/etc/esmond /etc/esmond
if ! [ -e /etc/esmond/esmond.conf ]; then
cp rpm/config_files/esmond.conf /etc/esmond/esmond.conf
chmod 644 /etc/esmond/esmond.conf
fi
ln -fs /vagrant /usr/lib/esmond
cp -f /vagrant/rpm/config_files/tmpfiles.conf /usr/lib/tmpfiles.d/esmond.conf
chmod 644 /usr/lib/tmpfiles.d/esmond.conf
ln -fs /vagrant/util/esmond_manage /usr/sbin
#have to copy so apache starts on boot
cp -f /vagrant/rpm/config_files/apache-esmond.conf /etc/httpd/conf.d/apache-esmond.conf
chmod 644 /etc/httpd/conf.d/apache-esmond.conf
ln -fs /vagrant/rpm/config_files/esmond.csh /etc/profile.d/esmond.csh
ln -fs /vagrant/rpm/config_files/esmond.sh /etc/profile.d/esmond.sh
ln -fs /usr/pgsql-10/bin/pg_config /usr/sbin/pg_config
## Make PostgreSQL ready. In production, pScheduler's
## postgres-init handles this.
/usr/pgsql-10/bin/postgresql-10-setup initdb
systemctl enable --now postgresql-10
## Setup python environment
virtualenv-3 --prompt="(esmond)" .
. bin/activate
python3 -m pip install --install-option="--prefix=/vagrant" -r requirements.txt
python3 -m pip install --install-option="--prefix=/vagrant" django-tastypie
#need below for unittests
python3 -m pip install --install-option="--prefix=/vagrant" --upgrade setuptools
python3 -m pip install --install-option="--prefix=/vagrant" mock
## Setup logging
mkdir -p /var/run/cassandra/
mkdir -p /var/log/esmond
mkdir -p /var/log/esmond/crashlog
touch /var/log/esmond/esmond.log
touch /var/log/esmond/django.log
touch /var/log/esmond/install.log
chown -R apache:apache /var/log/esmond
## Finish Django setup
#TODO: Handle this better
cp -f rpm/config_files/settings.py esmond/settings.py
grep -q "SECRET_KEY =" esmond/settings.py|| python3 util/gen_django_secret_key.py >> esmond/settings.py
./rpm/scripts/configure_esmond
## Configure DB
USER_EXISTS=$(su -l postgres -c "psql -tAc \\"SELECT 1 FROM pg_roles WHERE rolname='esmond'\\"")
if [ $? -ne 0 ]; then
echo "Unable to connect to postgresql to check user. Your esmond database may not be initialized"
fi
if [ "$USER_EXISTS" != "1" ]; then
DB_PASSWORD=$(< /dev/urandom tr -dc _A-Za-z0-9 | head -c32;echo;)
su -l postgres -c "psql -c \\"CREATE USER esmond WITH PASSWORD '${DB_PASSWORD}'\\""
su -l postgres -c "psql -c \\"CREATE DATABASE esmond\\""
su -l postgres -c "psql -c \\"GRANT ALL ON DATABASE esmond to esmond\\""
#need this for unit tests
su -l postgres -c "psql -c \\"ALTER USER esmond CREATEDB\\""
sed -i "s/sql_db_name = .*/sql_db_name = esmond/g" /etc/esmond/esmond.conf
sed -i "s/sql_db_user = .*/sql_db_user = esmond/g" /etc/esmond/esmond.conf
sed -i "s/sql_db_password = .*/sql_db_password = ${DB_PASSWORD}/g" /etc/esmond/esmond.conf
drop-in -n -t esmond - /var/lib/pgsql/10/data/pg_hba.conf <<EOF
#
# esmond
#
# This user should never need to access the database from anywhere
# other than locally.
#
local esmond esmond md5
host esmond esmond 127.0.0.1/32 md5
host esmond esmond ::1/128 md5
local test_esmond esmond md5
host test_esmond esmond 127.0.0.1/32 md5
host test_esmond esmond ::1/128 md5
local postgres esmond md5
host postgres esmond 127.0.0.1/32 md5
host postgres esmond ::1/128 md5
EOF
fi
## Restart remaining services
systemctl enable postgresql-10
systemctl restart postgresql-10
systemctl enable cassandra
systemctl restart cassandra
systemctl enable httpd
systemctl restart httpd
#build database
./rpm/scripts/configure_esmond 2
SHELL
# Do the build if we're configured to do so
if do_build
el7.vm.provision "build", type: "shell", inline: <<-SHELL
echo
echo Building Esmond
echo
set -e
# TODO: See if there's a way to get this location from Vagrant
cd /vagrant
RPMBUILD="${HOME}/rpmbuild"
yum -y install git rpm-build
BRANCH=$(git rev-parse --abbrev-ref HEAD)
RPMVERSION=$(rpmspec -q --qf "%{Version}\n" rpm/esmond.spec | head -1)
for DIR in SOURCES SRPMS
do
mkdir -p "${RPMBUILD}/${DIR}"
done
git archive --format=tar --prefix="esmond-${RPMVERSION}/" "remotes/origin/${BRANCH}" \
| gzip > "${RPMBUILD}/SOURCES/esmond-${RPMVERSION}.tar.gz"
rpmbuild -bs rpm/esmond.spec
yum-builddep -y ${RPMBUILD}/SRPMS/*.src.rpm
rpmbuild -ba rpm/esmond.spec
cp ${RPMBUILD}/RPMS/$(uname -m)/* .
SHELL
end
# Runs on all hosts before they are provisioned independent of OS
config.vm.provision "account", type: "shell", inline: <<-SHELL
/usr/sbin/groupadd -r esmond 2> /dev/null || :
/usr/sbin/useradd -g esmond -r -s /sbin/nologin -c "Esmond User" -d /tmp esmond 2> /dev/null || :
SHELL
end
end