forked from sanbales/openmbee-vm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bashrc
228 lines (182 loc) · 11.5 KB
/
.bashrc
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
#!/usr/bin/env bash
set -a
. /vagrant/.env
set +a
alias dc='${DOCKER_COMPOSE_LOCATION} -f /vagrant/docker-compose.yml --project-directory /vagrant'
commands() {
cat << EOF
MMS VM Custom Commands Help:
clean_restart - remove all containers and volumes and restart containers
dc - function alias for docker-compose (alias for 'docker-compose -f /vagrant/docker-compose.yml')
enter <container> - shell into a running container (e.g., 'enter db' to enter the PostgreSQL container)
initialize_db - populate the PostgreSQL service with the necessary permissions and databases
initialize_search - populate the Elasticsearch service by uploading the MMS Mapping Template
setup - start stopped services and (if necessary) initialize their data
teardown - remove all containers and volumes
jena <cmds> - run command on the Jena docker container
EOF
}
enter() {
${DOCKER_COMPOSE_LOCATION} -f /vagrant/docker-compose.yml --project-directory /vagrant exec "${1}" env TERM=xterm /bin/sh
}
setup() {
latest_mms_version=$(curl -s https://registry.hub.docker.com/v2/repositories/openmbee/mms/tags | python -c "import sys,json; print(json.load(sys.stdin)['results'][1]['name'])")
echo ">>> Starting containerized services. Installing latest MMS version: ${latest_mms_version}"
${DOCKER_COMPOSE_LOCATION} -f /vagrant/docker-compose.yml --project-directory /vagrant up -d
echo ">>> Initializing the database service (PostgreSQL)"
initialize_db
echo ">>> Initializing the search service (Elasticsearch)"
initialize_search
echo ""
#transfer the corrected files to the docker tomcat directories:
#the .properties files change Alfresco to use the HTTP protocol instead of the HTTPS (the default); the tomcat-users files creates necessary admin user
#after files are written, restart openmbee-mms container for changes to take effect
echo ">>> copying correct MMS and Tomcat config files to vagrant vm..."
docker cp /vagrant/alfresco-global.properties openmbee-mms:/usr/local/tomcat/shared/classes/alfresco-global.properties
docker cp /vagrant/mms.properties openmbee-mms:/usr/local/tomcat/shared/classes/mms.properties
docker cp /vagrant/tomcat-users.xml openmbee-mms:/usr/local/tomcat/conf/tomcat-users.xml
docker restart openmbee-mms
#coerce (again) Postgres to create the required `alfresco` and `mms` databases
echo ">>> ensuring the necessary databases were created"
initialize_db
echo ">>> Installing View Editor files"
echo " > Getting latest View Editor files..."
latest_ve_version=$(curl -s https://github.com/Open-MBEE/ve/releases/latest | grep -oP "tag/([0-9\.])+" | cut -d "/" -f 2)
wget -q https://github.com/Open-MBEE/ve/releases/download/${latest_ve_version}/ve-${latest_ve_version}.zip
yum -q -y install unzip
unzip -qq ve-${latest_ve_version}.zip
mv dist ve\#\#${latest_ve_version}
echo " > Extracting and copying View Editor files over..."
docker cp ve\#\#${latest_ve_version} openmbee-mms:/usr/local/tomcat/webapps/
docker exec -i openmbee-mms sh -c "mkdir /usr/local/tomcat/webapps/ve##${latest_ve_version}/WEB-INF"
docker cp /vagrant/mms_tomcat_web.xml openmbee-mms:/usr/local/tomcat/webapps/ve\#\#${latest_ve_version}/WEB-INF/web.xml
echo " > View Editor installed."
echo ">>> Installing Apache Jena Fuseki server..."
initialize_apache_jena_fuseki
echo ">>> Installing WebProtege server..."
initialize_webprotege
echo ">>> You can now use 'dc logs' to inspect the services"
}
teardown() {
${DOCKER_COMPOSE_LOCATION} -f /vagrant/docker-compose.yml --project-directory /vagrant stop
${DOCKER_COMPOSE_LOCATION} -f /vagrant/docker-compose.yml --project-directory /vagrant kill
${DOCKER_COMPOSE_LOCATION} -f /vagrant/docker-compose.yml --project-directory /vagrant rm -f -v
docker system prune -f
docker volume prune -f
if [[ -f ${ES_MAPPING_TEMPLATE_FILE} ]]; then
rm ${ES_MAPPING_TEMPLATE_FILE}
fi
}
clean_restart() {
teardown
setup
}
initialize_db() {
if ! [[ `${DOCKER_COMPOSE_LOCATION} -f /vagrant/docker-compose.yml --project-directory /vagrant ps -q ${PG_SERVICE_NAME}` ]]; then
echo " > Waiting ${PG_WAIT} seconds for PostgreSQL service to start"
sleep ${PG_WAIT}
fi
# Check to see PostgreSQL service is running by requesting list of available databases
if ! `${DOCKER_COMPOSE_LOCATION} -f /vagrant/docker-compose.yml --project-directory /vagrant exec -T ${PG_SERVICE_NAME} psql -lq -U ${PG_USERNAME} | grep -q "List of databases"`; then
echo " > Waiting ${PG_WAIT} seconds for PostgreSQL to begin accepting connections"
sleep ${PG_WAIT}
fi
# Check to see if new user has ability to create databases
if `${DOCKER_COMPOSE_LOCATION} -f /vagrant/docker-compose.yml --project-directory /vagrant exec -T ${PG_SERVICE_NAME} psql -U ${PG_USERNAME} -c "${PG_TEST_CREATEDB_ROLE_COMMAND}" | grep -q "(0 row)"`; then
echo " > Giving '${PG_USERNAME}' permission to create databases"
${DOCKER_COMPOSE_LOCATION} -f /vagrant/docker-compose.yml --project-directory /vagrant exec -T ${PG_SERVICE_NAME} psql -U ${PG_USERNAME} -c "ALTER ROLE ${PG_USERNAME} CREATEDB"
fi
if ! `${DOCKER_COMPOSE_LOCATION} -f /vagrant/docker-compose.yml --project-directory /vagrant exec -T ${PG_SERVICE_NAME} psql -lqt -U ${PG_USERNAME} | cut -d \| -f 1 | grep -qw alfresco`; then
echo " > Creating the Alfresco database ('alfresco')"
${DOCKER_COMPOSE_LOCATION} -f /vagrant/docker-compose.yml --project-directory /vagrant exec -T ${PG_SERVICE_NAME} createdb -U ${PG_USERNAME} alfresco
fi
if ! `${DOCKER_COMPOSE_LOCATION} -f /vagrant/docker-compose.yml --project-directory /vagrant exec -T ${PG_SERVICE_NAME} psql -lqt -U ${PG_USERNAME} | cut -d \| -f 1 | grep -qw ${PG_DB_NAME}`; then
echo " > Creating the MMS database ('${PG_DB_NAME}')"
${DOCKER_COMPOSE_LOCATION} -f /vagrant/docker-compose.yml --project-directory /vagrant exec -T ${PG_SERVICE_NAME} createdb -U ${PG_USERNAME} ${PG_DB_NAME}
fi
if ! `${DOCKER_COMPOSE_LOCATION} -f /vagrant/docker-compose.yml --project-directory /vagrant exec -T ${PG_SERVICE_NAME} psql -U ${PG_USERNAME} -d ${PG_DB_NAME} -c "\dt" | grep -qw organizations`; then
${DOCKER_COMPOSE_LOCATION} -f /vagrant/docker-compose.yml --project-directory /vagrant exec -T ${PG_SERVICE_NAME} psql -U ${PG_USERNAME} -d ${PG_DB_NAME} -c "${PG_DB_CREATION_COMMAND}"
fi
}
initialize_search() {
if [[ ! `${DOCKER_COMPOSE_LOCATION} -f /vagrant/docker-compose.yml --project-directory /vagrant ps -q ${ES_SERVICE_NAME}` ]]; then
echo " > Waiting ${ES_WAIT} seconds for Elasticsearch service to start"
sleep ${ES_WAIT}
fi
if [[ ! -f "${ES_MAPPING_TEMPLATE_FILE}" ]]; then
echo " > ERROR. Could not find '${ES_MAPPING_TEMPLATE_FILE}'!"
# echo " > Attempting to download the Elasticsearch Mapping File from the OpenMBEE MMS GitHub Repo"
# wget -O ${ES_MAPPING_TEMPLATE_FILE} ${ES_MAPPING_TEMPLATE_URL}
fi
ES_RESPONSE=`curl -s -XGET http://127.0.0.1:${ES_PORT}/_template/template`
if [[ "${ES_RESPONSE:0:1}" != "{" ]]; then
echo " > Sleeping to make sure Elasticsearch is running"
sleep ${ES_WAIT}
echo " > Re-requesting template from Elasticsearch"
ES_RESPONSE=`curl -s -XGET http://127.0.0.1:${ES_PORT}/_template/template`
fi
# Upload template to ElasticSearch
if [[ "${ES_RESPONSE}" == "{}" ]]; then
echo " >> Uploading MMS Mapping Template File to Elasticsearch"
ES_RESPONSE=`curl -XPUT http://127.0.0.1:${ES_PORT}/_template/template -H 'Content-Type: application/json' -d @${ES_MAPPING_TEMPLATE_FILE}`
if [[ "${ES_RESPONSE}" == "{}" ]]; then
echo ""
echo ">>> Failed to upload the MMS Template to Elasticsearch"
elif [[ "${ES_RESPONSE}" == "{\"acknowledged\":true}" ]]; then
echo ""
echo ">>> Sucessfully uploaded the MMS Template to Elasticsearch"
else
echo ""
echo ">>> Error uploading the MMS Template to Elasticsearch: ${ES_RESPONSE}"
fi
fi
# Modify ElasticSearch maxClauseCount to handle queries with large number of elements
echo " >> Modifying ElasticSearch's default maxClauseCount of 1024 to 999999..."
docker exec -i openmbee-elasticsearch sh -c "echo \"indices.query.bool.max_clause_count: 999999\" >> /usr/share/elasticsearch/config/elasticsearch.yml"
docker exec -i openmbee-elasticsearch sh -c "echo \"indices.query.bool.max_clause_count: 999999\" >> /config/elasticsearch.yml"
docker exec -i openmbee-elasticsearch sh -c "echo \"indices.query.bool.max_clause_count: 999999\" >> /etc/elasticsearch/elasticsearch.yml"
echo " >>> Done. Restarting ElasticSearch"
docker restart openmbee-elasticsearch
}
initialize_apache_jena_fuseki() {
# function loads and runs the Apache Jena's Fuseki webapp into Tomcat (running in MMS docker container)
echo -e "\n>> Downloading and extracting Apache Jena Fuseki files.... \n"
jena_filename="apache-jena-fuseki-${JENA_VERSION}"
wget -q "https://archive.apache.org/dist/jena/binaries/${jena_filename}.tar.gz"
tar -xzf $jena_filename.tar.gz
echo -e "\n>> Uploading Apache Jena Fuseki files to Tomcat.... \n"
docker cp $jena_filename/fuseki.war openmbee-mms:"/usr/local/tomcat/webapps/fuseki##${JENA_VERSION}.war"
echo -e "\n>> Configuring Apache Tomcat to run Jena Fuseki.... \n"
docker exec -i openmbee-mms sh -c "mkdir /etc/fuseki"
docker exec -i openmbee-mms sh -c "chown -R tomcat:tomcat /etc/fuseki"
docker cp /vagrant/shiro.ini openmbee-mms:/etc/fuseki/shiro.ini
docker exec -it openmbee-mms sh -c "wget https://raw.githubusercontent.com/apache/jena/master/jena-fuseki2/apache-jena-fuseki/log4j2.properties -P /etc/fuseki"
echo -e "\n>> Complete! To run Jena Fuseki, visit http://localhost:${MMS_EXTERNAL_PORT}/manager/html/list and click 'start'"
}
initialize_webprotege() {
# function loads and runs the Web Protege Docker container
echo -e "\n>> Downloading, extracting, and launching WebProtege.... \n"
#copy WebProtege files
wp_version=4.0.2
wget -q "https://github.com/protegeproject/webprotege/archive/v${wp_version}.zip"
#extract
unzip -qq "v${wp_version}.zip"
#replace docker-compose file
cd "webprotege-${wp_version}"
cp /vagrant/webprotege-docker-compose.yml docker-compose.yml
#launch containers
${DOCKER_COMPOSE_LOCATION} up -d
#some configurating
docker exec -it webprotege sh -c "mkdir /var/log/webprotege" #ensure logging dir exists
docker cp /vagrant/webprotege_web.xml webprotege:/usr/local/tomcat/webapps/ROOT/WEB-INF/web.xml #increase max file upload size
docker container restart webprotege
#update the dc alias to include the new docker-compose file
alias dc="${DOCKER_COMPOSE_LOCATION} -f /vagrant/docker-compose.yml -f /home/vagrant/webprotege-${wp_version}/docker-compose.yml --project-directory /vagrant"
echo -e "\n>> Complete! To run WebProtege, \n
\t\t 1) run the following commands and follow the prompts to create the admin account: \n
\t\t\t $ vagrant ssh \n
\t\t\t $ docker exec -it webprotege java -jar /webprotege-cli.jar create-admin-account \n
\t\t\t $ exit #to exit the Vagrant VM shell \n
\t\t 2) visit http://localhost:8090/#application/settings and fill out the form to finalize the initialization of the WebProtege server. \n
>> WebProtege is now fully accessible at http://localhost:8090/"
}