Make Motech SPOC-compatible

This commit is contained in:
Disassembler 2020-03-20 14:51:12 +01:00
parent 35345dc529
commit 40e26e4407
Signed by: Disassembler
GPG Key ID: 524BD33A0EE29499
5 changed files with 71 additions and 68 deletions

34
lxc-apps/motech/app Normal file
View File

@ -0,0 +1,34 @@
{
"version": "1.3.0-200313",
"meta": {
"title": "Motech",
"desc-cs": "Automatizace komunikace",
"desc-en": "Communication automation",
"license": "GPL"
},
"containers": {
"motech": {
"image": "motech_1.3.0-200313",
"depends": [
"motech-activemq",
"motech-postgres"
],
"mounts": {
"motech/motech_conf": "srv/tomcat/.motech"
}
},
"motech-activemq": {
"image": "activemq_5.15.9-200313",
"mounts": {
"motech/activemq_conf/activemq.xml": "srv/activemq/conf/activemq.xml:file",
"motech/activemq_data": "srv/activemq/data"
}
},
"motech-postgres": {
"image": "postgres_12.2.0-200313",
"mounts": {
"motech/postgres_data": "var/lib/postgresql"
}
}
}
}

View File

@ -1,5 +1,5 @@
IMAGE motech_1.3.0-190620 IMAGE motech_1.3.0-200313
FROM alpine3.9-tomcat7_7.0.94-190620 FROM alpine3.11-tomcat7_7.0.99-200313
RUN EOF RUN EOF
# Download Motech # Download Motech
@ -9,8 +9,8 @@ RUN EOF
# Update Postgres JDBC driver # Update Postgres JDBC driver
rm -f /srv/tomcat/webapps/ROOT/WEB-INF/lib/postgresql-9.1-901.jdbc4.jar /srv/tomcat/webapps/ROOT/WEB-INF/bundles/postgresql-9.1-901.jdbc4.jar rm -f /srv/tomcat/webapps/ROOT/WEB-INF/lib/postgresql-9.1-901.jdbc4.jar /srv/tomcat/webapps/ROOT/WEB-INF/bundles/postgresql-9.1-901.jdbc4.jar
wget https://jdbc.postgresql.org/download/postgresql-42.2.5.jar -O /srv/tomcat/webapps/ROOT/WEB-INF/lib/postgresql-42.2.5.jar wget https://jdbc.postgresql.org/download/postgresql-42.2.11.jar -O /srv/tomcat/webapps/ROOT/WEB-INF/lib/postgresql-42.2.11.jar
cp /srv/tomcat/webapps/ROOT/WEB-INF/lib/postgresql-42.2.5.jar /srv/tomcat/webapps/ROOT/WEB-INF/bundles/postgresql-42.2.5.jar cp /srv/tomcat/webapps/ROOT/WEB-INF/lib/postgresql-42.2.11.jar /srv/tomcat/webapps/ROOT/WEB-INF/bundles/postgresql-42.2.11.jar
# Change webapps ownership # Change webapps ownership
chown -R tomcat:tomcat /srv/tomcat/webapps chown -R tomcat:tomcat /srv/tomcat/webapps
@ -19,6 +19,6 @@ RUN EOF
rm -f /tmp/motech.war rm -f /tmp/motech.war
EOF EOF
USER 8080 8080 USER tomcat
WORKDIR /srv/tomcat WORKDIR /srv/tomcat
CMD catalina.sh run CMD /usr/bin/catalina.sh run

View File

@ -1,52 +1,55 @@
#!/bin/sh #!/bin/sh
set -ev set -ev
# Volumes
POSTGRES_DATA="${VOLUMES_DIR}/motech/postgres_data"
ACTIVEMQ_CONF="${VOLUMES_DIR}/motech/activemq_conf"
ACTIVEMQ_DATA="${VOLUMES_DIR}/motech/activemq_data"
MOTECH_CONF="${VOLUMES_DIR}/motech/motech_conf"
# Create Postgres instance # Create Postgres instance
mkdir -p /srv/motech/postgres_data install -o 105432 -g 105432 -m 700 -d ${POSTGRES_DATA}
chown -R 105432:105432 /srv/motech/postgres_data spoc-container exec motech-postgres -- initdb -D /var/lib/postgresql
chmod 700 /srv/motech/postgres_data
lxc-execute -n motech-postgres -- initdb -D /var/lib/postgresql
# Configure Postgres # Configure Postgres
cp postgres_data/postgresql.conf /srv/motech/postgres_data/postgresql.conf install -o 105432 -g 105432 -m 600 postgres_data/postgresql.conf ${POSTGRES_DATA}/postgresql.conf
cp postgres_data/pg_hba.conf /srv/motech/postgres_data/pg_hba.conf install -o 105432 -g 105432 -m 600 postgres_data/pg_hba.conf ${POSTGRES_DATA}/pg_hba.conf
# Configure ActiveMQ # Configure ActiveMQ
mkdir -p /srv/motech/activemq_conf /srv/motech/activemq_data install -o 161616 -g 161616 -m 750 -d ${ACTIVEMQ_CONF}
cp activemq_conf/activemq.xml /srv/motech/activemq_conf/activemq.xml install -o 161616 -g 161616 -m 750 -d ${ACTIVEMQ_DATA}
chown -R 161616:161616 /srv/motech/activemq_conf /srv/motech/activemq_data install -o 161616 -g 161616 -m 640 activemq_conf/activemq.xml ${ACTIVEMQ_CONF}/activemq.xml
# Create database # Create database
export MOTECH_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=') export MOTECH_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
service lxc-motech-postgres start spoc-container start motech-postgres
envsubst <createdb.sql | lxc-attach -u 5432 -g 5432 motech-postgres -- psql envsubst <createdb.sql | spoc-container exec motech-postgres -- psql
# Configure Motech # Configure Motech
mkdir -p /srv/motech/motech_conf/config/org.motechproject.motech-platform-email install -o 108080 -g 108080 -m 750 -d ${MOTECH_CONF}
envsubst <motech_conf/config/bootstrap.properties >/srv/motech/motech_conf/config/bootstrap.properties install -o 108080 -g 108080 -m 750 -d ${MOTECH_CONF}/config
cp motech_conf/config-locations.properties /srv/motech/motech_conf/config-locations.properties install -o 108080 -g 108080 -m 750 -d ${MOTECH_CONF}/config/org.motechproject.motech-platform-email
cp motech_conf/config/motech-settings.properties /srv/motech/motech_conf/config/motech-settings.properties envsubst <motech_conf/config/bootstrap.properties | install -o 108080 -g 108080 -m 640 /dev/stdin ${MOTECH_CONF}/config/bootstrap.properties
cp motech_conf/config/org.motechproject.motech-platform-email/motech-email.properties /srv/motech/motech_conf/config/org.motechproject.motech-platform-email/motech-email.properties install -o 108080 -g 108080 -m 640 motech_conf/config-locations.properties ${MOTECH_CONF}/config-locations.properties
chown -R 108080:108080 /srv/motech/motech_conf install -o 108080 -g 108080 -m 640 motech_conf/config/motech-settings.properties ${MOTECH_CONF}/config/motech-settings.properties
install -o 108080 -g 108080 -m 640 motech_conf/config/org.motechproject.motech-platform-email/motech-email.properties ${MOTECH_CONF}/config/org.motechproject.motech-platform-email/motech-email.properties
# Populate database and create admin account # Populate database and create admin account
service lxc-motech-activemq start spoc-container start motech-activemq
service lxc-motech start spoc-container start motech
until curl -s "http://motech:8080/module/server/startup/" | grep -q adminLogin; do MOTECH_IP=$(grep ' motech$' /var/lib/spoc/hosts | cut -d' ' -f0)
until curl -s "http://${MOTECH_IP}:8080/module/server/startup/" | grep -q adminLogin; do
sleep 1 sleep 1
done done
export MOTECH_ADMIN_USER="admin" export MOTECH_ADMIN_USER="admin"
export MOTECH_ADMIN_EMAIL="admin@example.com" export MOTECH_ADMIN_EMAIL="admin@example.com"
export MOTECH_ADMIN_PWD=$(head -c 12 /dev/urandom | base64 | tr -d '+/=') export MOTECH_ADMIN_PWD=$(head -c 12 /dev/urandom | base64 | tr -d '+/=')
curl -H "Content-Type: application/json" -X POST -d "{\"adminLogin\":\"${MOTECH_ADMIN_USER}\",\"adminEmail\":\"${MOTECH_ADMIN_EMAIL}\",\"adminPassword\":\"${MOTECH_ADMIN_PWD}\",\"adminConfirmPassword\":\"${MOTECH_ADMIN_PWD}\",\"language\":\"cs\",\"providerName\":\"\",\"providerUrl\":\"\",\"schedulerUrl\":\"\"}" http://motech:8080/module/server/startup/ curl -H "Content-Type: application/json" -X POST -d "{\"adminLogin\":\"${MOTECH_ADMIN_USER}\",\"adminEmail\":\"${MOTECH_ADMIN_EMAIL}\",\"adminPassword\":\"${MOTECH_ADMIN_PWD}\",\"adminConfirmPassword\":\"${MOTECH_ADMIN_PWD}\",\"language\":\"cs\",\"providerName\":\"\",\"providerUrl\":\"\",\"schedulerUrl\":\"\"}" "http://${MOTECH_IP}:8080/module/server/startup/"
service lxc-motech stop spoc-container stop motech
# Install config update script
cp update-conf.sh /srv/motech/update-conf.sh
# Stop services required for setup # Stop services required for setup
service lxc-motech-activemq stop spoc-container stop motech-activemq
service lxc-motech-postgres stop spoc-container stop motech-postgres
# Register application # Register application
vmmgr register-app motech motech "${MOTECH_ADMIN_USER}" "${MOTECH_ADMIN_PWD}" vmmgr register-app motech motech "${MOTECH_ADMIN_USER}" "${MOTECH_ADMIN_PWD}"

View File

@ -1,34 +0,0 @@
{
"version": "1.3.0-190620",
"meta": {
"title": "Motech",
"desc-cs": "Automatizace komunikace",
"desc-en": "Communication automation",
"license": "GPL"
},
"containers": {
"motech": {
"image": "motech_1.3.0-190620",
"depends": [
"motech-activemq",
"motech-postgres"
],
"mounts": [
["DIR", "/srv/motech/motech_conf", "/srv/tomcat/.motech"]
]
},
"motech-activemq": {
"image": "activemq_5.15.9-190620",
"mounts": [
["FILE", "/srv/motech/activemq_conf/activemq.xml", "/srv/activemq/conf/activemq.xml"],
["DIR", "/srv/motech/activemq_data", "/srv/activemq/data"]
]
},
"motech-postgres": {
"image": "postgres_11.3.0-190620",
"mounts": [
["DIR", "/srv/motech/postgres_data", "/var/lib/postgresql"]
]
}
}
}

View File

@ -2,7 +2,7 @@
set -ev set -ev
# Remove persistent data # Remove persistent data
rm -rf /srv/motech rm -rf "${VOLUMES_DIR}/motech"
# Unregister application # Unregister application
vmmgr unregister-app motech vmmgr unregister-app motech