From 365f983c2d9adb420c2aeba7ebc873c1d0966dd4 Mon Sep 17 00:00:00 2001 From: Disassembler Date: Thu, 13 Sep 2018 21:14:53 +0200 Subject: [PATCH] LXCize Motech setup --- kanboard/setup.sh | 2 +- mifosx/setup.sh | 2 +- motech/setup.sh | 25 +++++++++++-------------- motech/setup/etc/init.d/motech | 15 ++++----------- 4 files changed, 17 insertions(+), 27 deletions(-) diff --git a/kanboard/setup.sh b/kanboard/setup.sh index 5d819fe..a44a6e3 100755 --- a/kanboard/setup.sh +++ b/kanboard/setup.sh @@ -1,7 +1,7 @@ #!/bin/sh set -e -SOURCE_DIR=$(realpath $(dirname "${0}"))/kanboard +SOURCE_DIR=$(realpath $(dirname "${0}"))/setup # Check prerequisites [ ! -e /run/openrc/started/postgres ] && service postgres start && STOP_POSTGRES=1 diff --git a/mifosx/setup.sh b/mifosx/setup.sh index d4103a7..870fafe 100755 --- a/mifosx/setup.sh +++ b/mifosx/setup.sh @@ -1,7 +1,7 @@ #!/bin/sh set -e -SOURCE_DIR=$(realpath $(dirname "${0}"))/mifosx +SOURCE_DIR=$(realpath $(dirname "${0}"))/setup # Check prerequisites [ ! -e /run/openrc/started/mariadb ] && service mariadb start && STOP_MARIADB=1 diff --git a/motech/setup.sh b/motech/setup.sh index 659d525..0a02aaf 100755 --- a/motech/setup.sh +++ b/motech/setup.sh @@ -1,22 +1,15 @@ #!/bin/sh set -e -SOURCE_DIR=$(realpath $(dirname "${0}"))/motech +SOURCE_DIR=$(realpath $(dirname "${0}"))/setup # Check prerequisites -lxc-ls | grep -q activemq || $(realpath $(dirname "${0}"))/activemq.sh -lxc-ls | grep -q postfix || $(realpath $(dirname "${0}"))/postfix.sh -lxc-ls | grep -q postgres || $(realpath $(dirname "${0}"))/postgres.sh -service postgres start - -# Build Docker container -docker build -t motech ${SOURCE_DIR} -cp ${SOURCE_DIR}/etc/init.d/motech /etc/init.d/motech -rc-update -u +[ ! -e /run/openrc/started/activemq ] && service activemq start && STOP_ACTIVEMQ=1 +[ ! -e /run/openrc/started/postgres ] && service postgres start && STOP_POSTGRES=1 # Create database export MOTECH_PWD=$(head -c 18 /dev/urandom | base64) -envsubst <${SOURCE_DIR}/createdb.sql | docker exec -i postgres psql +envsubst <${SOURCE_DIR}/createdb.sql | lxc-attach -u 5432 -g 5432 postgres -- psql # Configure Motech mkdir -p /srv/motech/conf/config/org.motechproject.motech-platform-email @@ -26,10 +19,14 @@ cp ${SOURCE_DIR}/srv/motech/conf/config/motech-settings.properties /srv/motech/c cp ${SOURCE_DIR}/srv/motech/conf/config/org.motechproject.motech-platform-email/motech-email.properties /srv/motech/conf/config/org.motechproject.motech-platform-email/motech-email.properties chown -R 8013:8013 /srv/motech/conf +# Install service +cp ${SOURCE_DIR}/etc/init.d/motech /etc/init.d/motech +rc-update -u + # Populate database and create admin account service motech start echo `date` '- Waiting for database to be populated. This should take about a minute.' -MOTECH_IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' motech) +MOTECH_IP=$(awk '/ motech/ {print $1}' /etc/hosts) until curl -s "http://${MOTECH_IP}:8080/module/server/startup/" | grep -q adminLogin; do sleep 1 done @@ -41,5 +38,5 @@ service motech stop vmmgr update-login motech "${MOTECH_ADMIN_USER}" "${MOTECH_ADMIN_PWD}" # Stop services required for build -service activemq stop -service postgres stop +[ ! -z ${STOP_ACTIVEMQ} ] && service activemq stop +[ ! -z ${STOP_POSTGRES} ] && service postgres stop diff --git a/motech/setup/etc/init.d/motech b/motech/setup/etc/init.d/motech index 11fb84c..5a083df 100755 --- a/motech/setup/etc/init.d/motech +++ b/motech/setup/etc/init.d/motech @@ -1,20 +1,13 @@ #!/sbin/openrc-run -description="Motech docker container" +description="Motech container" depend() { - need docker activemq postfix postgres + need cgroups activemq postgres } start() { - /usr/bin/docker run -d --rm \ - --name motech \ - -h motech \ - --link activemq \ - --link postfix \ - --link postgres \ - -v /srv/motech/conf:/srv/tomcat/.motech \ - motech + lxc-start motech } start_post() { @@ -26,5 +19,5 @@ stop_pre() { } stop() { - /usr/bin/docker stop motech + lxc-stop motech }