-
Notifications
You must be signed in to change notification settings - Fork 160
/
Vagrantfile
198 lines (158 loc) · 8.28 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
#*******************************************************************************
# Copyright (c) 2011, 2018 Eurotech and/or its affiliates and others
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
# Eurotech - initial API and implementationq
#*******************************************************************************
network_address = '192.168.33.10'
# Environment variables used in the scripts
env_vars = {
'BINDING_IP' => network_address,
'ELASTICSEARCH_VERSION' => '5.4.0',
'H2DB_VERSION' => '1.4.192',
'ACTIVEMQ_VERSION' => '5.14.5',
'ARTEMIS_VERSION' => '2.2.0',
'JETTY_VERSION' => '9.4.12.v20180830',
'KAPUA_VERSION' => '1.1.3-SNAPSHOT'
}
# Vagrant 1.9.6 or major is required
# since one of the previous version had a bug with Centos/7 box
Vagrant.require_version ">= 1.9.6"
Vagrant.configure("2") do |config|
# If Virtualbox provider
# Check that vagrant-vbguest plugin is installed
# If missing, install it.
config.vm.provider "virtualbox" do |vb|
unless Vagrant.has_plugin?("vagrant-vbguest")
system('if ! vagrant plugin list | grep -q vagrant-vbguest; then echo "Installing missing plugin: vagrant-vbguest" ;vagrant plugin install vagrant-vbguest; fi')
end
end
# Share the kapua directory with the vagrant machine to allow
# the ActiveMQ broker to access the kapua code (jars)
config.vm.synced_folder "../../", "/kapua",
owner: "vagrant", group: "vagrant",
mount_options: ["dmode=775", "fmode=664"]
config.vm.box = "kapua-dev-box/0.8"
config.vm.box_check_update = false
# DBMS
config.vm.network "forwarded_port", guest: 3306, host: 3306
# ActiveMQ
config.vm.network "forwarded_port", guest: 1883, host: 1883
config.vm.network "forwarded_port", guest: 8883, host: 8883
config.vm.network "forwarded_port", guest: 61614, host: 61614
config.vm.network "forwarded_port", guest: 5005, host: 5005
# ActiveMQ Artemis
config.vm.network "forwarded_port", guest: 5672, host: 5672
config.vm.network "forwarded_port", guest: 8161, host: 8161
config.vm.network "forwarded_port", guest: 61616, host: 61616
# Elasticsearch
config.vm.network "forwarded_port", guest: 9200, host: 9200
config.vm.network "forwarded_port", guest: 9300, host: 9300
# Jetty
config.vm.network "forwarded_port", guest: 8000, host: 8000
config.vm.network "forwarded_port", guest: 8080, host: 8080
config.vm.network "forwarded_port", guest: 8443, host: 8443
config.vm.network "private_network", ip: network_address
config.vm.provider "virtualbox" do |vb|
vb.cpus = 2
vb.gui = false
vb.memory = "6144"
end
config.vm.provision "shell", env: env_vars, inline: <<-SHELL
echo "Creating Kapua certificates..."
openssl req -x509 -newkey rsa:4096 -keyout /home/vagrant/key.pem -out /home/vagrant/cert.pem -days 365 -nodes -subj '/O=Eclipse Kapua/C=XX' > /dev/null
openssl pkcs8 -topk8 -in /home/vagrant/key.pem -out /home/vagrant/key.pk8 -nocrypt > /dev/null
rm /home/vagrant/key.pem
echo "Creating Kapua certificates... DONE!"
SHELL
config.vm.provision "shell", env: env_vars, inline: <<-SHELL
# Setup permanent environment vars
sudo ln -sf /kapua/dev-tools/vagrant/develop/envs/kapua_env.sh /etc/profile.d/kapua_env.sh
export JETTY_VERSION=${JETTY_VERSION}
###########################
### H2 database startup ###
###########################
# Run the database engine
su --login -c "java -cp /usr/local/h2/h2*.jar org.h2.tools.Server -baseDir /home/vagrant/H2/kapua -webAllowOthers -tcpAllowOthers -tcpPort 3306 &" vagrant
# Create the initial database
java -cp /usr/local/h2/h2*.jar org.h2.tools.Shell -url jdbc:h2:tcp://localhost:3306/kapuadb -user "root" -password "password" -sql "CREATE SCHEMA IF NOT EXISTS kapuadb; \
CREATE USER IF NOT EXISTS kapua PASSWORD 'kapua'; \
GRANT ALL ON SCHEMA kapuadb TO kapua;"
############################
### Elasticsearch Engine ###
############################
# needed by the elasticsearch 5.4.0
ELASTICSEARCH_INSTALL_DIR=/usr/local/elasticsearch/
sudo bash -c "echo 'cluster.name: kapua-datastore' >> ${ELASTICSEARCH_INSTALL_DIR}/config/elasticsearch.yml"
sudo bash -c "echo 'transport.host: ${BINDING_IP}' >> ${ELASTICSEARCH_INSTALL_DIR}/config/elasticsearch.yml"
sudo bash -c "echo 'transport.tcp.port: 9300' >> ${ELASTICSEARCH_INSTALL_DIR}/config/elasticsearch.yml"
sudo bash -c "echo 'transport.tcp.connect_timeout: 30s' >> ${ELASTICSEARCH_INSTALL_DIR}/config/elasticsearch.yml"
sudo bash -c "echo 'http.host: ${BINDING_IP}' >> ${ELASTICSEARCH_INSTALL_DIR}/config/elasticsearch.yml"
sudo bash -c "echo 'http.port: 9200' >> ${ELASTICSEARCH_INSTALL_DIR}/config/elasticsearch.yml"
sudo bash -c "echo 'transport.ping_schedule: -1' >> ${ELASTICSEARCH_INSTALL_DIR}/config/elasticsearch.yml"
# needed when using OpenJDK
sudo bash -c "echo '-XX:-AssumeMP' >> ${ELASTICSEARCH_INSTALL_DIR}/config/jvm.options"
# Set folder permissions
sudo chown -R vagrant ${ELASTICSEARCH_INSTALL_DIR}
SHELL
config.vm.define "develop", primary: true, autostart: true do |develop|
config.vm.provider "virtualbox" do |vb|
vb.name = "kapua-develop"
end
config.vm.provision "shell", env: env_vars, inline: <<-SHELL
# Stop H2 instance
pkill -f h2
######################
### ActiveMQ setup ###
######################
# ActiveMQ post-install setup
cd /usr/local/activemq/
rm conf/activemq.xml
ln -s /kapua/assembly/broker/configurations/activemq.xml conf/activemq.xml
ln -s /kapua/assembly/broker/configurations/camel.xml conf/camel.xml
echo 'Configuring conf/log4j.properties...'
sudo sed -i 's/log4j.appender.logfile.layout.ConversionPattern=%d | %-5p | %m | %c | %t%n/log4j.appender.logfile.layout.ConversionPattern=%d | %-5p | %t | %c | %m%n/g' conf/log4j.properties
sudo sed -i 's/log4j.appender.audit.layout.ConversionPattern=%-5p | %m | %t%n/log4j.appender.audit.layout.ConversionPattern=%-5p | %t%n | %m/g' conf/log4j.properties
echo 'Configuring conf/log4j.properties... DONE!'
cp /kapua/dev-tools/vagrant/develop/broker/update-kapua-jars-cfg.sh .
cp /kapua/dev-tools/vagrant/develop/broker/start-broker.sh .
chmod 555 update-kapua-jars-cfg.sh
chmod 555 start-broker.sh
# Enable debug
sudo sed -i 's/\#ACTIVEMQ_DEBUG_OPTS=/ACTIVEMQ_DEBUG_OPTS=/g' bin/env
sudo sed -i 's/ACTIVEMQ_VERSION/'"$ACTIVEMQ_VERSION"'/g' update-kapua-jars-cfg.sh
sudo sed -i 's/ACTIVEMQ_VERSION/'"$ACTIVEMQ_VERSION"'/g' start-broker.sh
sudo sed -i 's/ARTEMIS_VERSION/'"$ARTEMIS_VERSION"'/g' start-broker.sh
sudo chown -R vagrant:vagrant /usr/local/activemq/
##############################
### Artemis setup ###
##############################
cd /usr/local/artemis/kapua
echo "Setting up Artemis..."
sudo cp /kapua/assembly/events-broker/configurations/broker.xml etc/
sudo sed -i '/<acceptor.*5672.*<\\/acceptor>/! s|<acceptor.*</acceptor>||g' etc/broker.xml
sudo sed -i "s|/usr/local/artemis|/usr/local/artemis|g" etc/artemis.profile
sudo sed -i "s|localhost:8161|${BINDING_IP}:8161|g" etc/bootstrap.xml
sudo chown -R vagrant:vagrant /usr/local/artemis/
echo "Setting up Artemis... DONE!"
##########################
### Jetty post install ###
##########################
cd /usr/local/jetty
cp /kapua/dev-tools/vagrant/develop/jetty/*.sh .
chmod 555 start-jetty.sh
chmod 555 update-kapua-war.sh
sudo sed -i 's/KAPUA_VERSION/'"$KAPUA_VERSION"'/g' update-kapua-war.sh
SHELL
config.vm.provision "shell", env: env_vars, run: "always", inline: <<-SHELL
setsid su --login -c "java -cp /usr/local/h2/h2*.jar org.h2.tools.Server -baseDir /home/vagrant/H2/kapua -webAllowOthers -tcpAllowOthers -tcpPort 3306 &" vagrant
setsid su --login -c "/usr/local/elasticsearch/bin/elasticsearch -d" vagrant
setsid su --login -c "/usr/local/artemis/kapua/bin/artemis-service start" vagrant
SHELL
end
end