From cbaf4d6941152bd34b24c786b7589f9a81587b37 Mon Sep 17 00:00:00 2001 From: Disassembler Date: Fri, 14 Sep 2018 09:43:54 +0200 Subject: [PATCH] LXCize Ushahidi setup --- ushahidi/setup.sh | 26 ++++++++++++-------------- ushahidi/setup/etc/init.d/ushahidi | 16 ++++------------ 2 files changed, 16 insertions(+), 26 deletions(-) diff --git a/ushahidi/setup.sh b/ushahidi/setup.sh index 193fe5b..31af903 100755 --- a/ushahidi/setup.sh +++ b/ushahidi/setup.sh @@ -1,21 +1,14 @@ #!/bin/sh set -e -SOURCE_DIR=$(realpath $(dirname "${0}"))/ushahidi +SOURCE_DIR=$(realpath $(dirname "${0}"))/setup # Check prerequisites -lxc-ls | grep -q mariadb || $(realpath $(dirname "${0}"))/mariadb.sh -lxc-ls | grep -q postfix || $(realpath $(dirname "${0}"))/postfix.sh -service mariadb start - -# Build Docker container -docker build -t ushahidi ${SOURCE_DIR} -cp ${SOURCE_DIR}/etc/init.d/ushahidi /etc/init.d/ushahidi -rc-update -u +[ ! -e /run/openrc/started/mariadb ] && service mariadb start && STOP_MARIADB=1 # Create database export USHAHIDI_PWD=$(head -c 18 /dev/urandom | base64) -envsubst <${SOURCE_DIR}/createdb.sql | docker exec -i mariadb mysql +envsubst <${SOURCE_DIR}/createdb.sql | lxc-attach mariadb -- mysql # Configure Ushahidi mkdir -p /srv/ushahidi/conf /srv/ushahidi/data @@ -24,17 +17,22 @@ envsubst <${SOURCE_DIR}/srv/ushahidi/conf/env >/srv/ushahidi/conf/env cp ${SOURCE_DIR}/srv/ushahidi/conf/config.json /srv/ushahidi/conf/config.json # Populate database -docker run --rm -h ushahidi --link mariadb -v /srv/ushahidi/conf/env:/srv/ushahidi/platform/.env ushahidi /srv/ushahidi/platform/bin/phinx migrate -c /srv/ushahidi/platform/application/phinx.php +lxc-execute ushahidi -- /srv/ushahidi/platform/bin/phinx migrate -c /srv/ushahidi/platform/application/phinx.php # Create admin account export USHAHIDI_ADMIN_USER=admin@example.com export USHAHIDI_ADMIN_PWD=$(head -c 12 /dev/urandom | base64) -export USHAHIDI_ADMIN_HASH=$(docker run --rm ushahidi php -r "echo password_hash('${USHAHIDI_ADMIN_PWD}', PASSWORD_BCRYPT);") -envsubst <${SOURCE_DIR}/adminpwd.sql | docker exec -i mariadb mysql ushahidi +#TODO: python-bcrypt +export USHAHIDI_ADMIN_HASH=$(lxc-execute ushahidi -- php -r "echo password_hash('${USHAHIDI_ADMIN_PWD}', PASSWORD_BCRYPT);") +envsubst <${SOURCE_DIR}/adminpwd.sql | lxc-attach mariadb -- mysql ushahidi vmmgr update-login ushahidi "${USHAHIDI_ADMIN_USER}" "${USHAHIDI_ADMIN_PWD}" +# Install service +cp ${SOURCE_DIR}/etc/init.d/ushahidi /etc/init.d/ushahidi +rc-update -u + # Install cron job cp ${SOURCE_DIR}/etc/periodic/15min/ushahidi /etc/periodic/15min/ushahidi # Stop services required for build -service mariadb stop +[ ! -z ${STOP_MARIADB} ] && service mariadb stop diff --git a/ushahidi/setup/etc/init.d/ushahidi b/ushahidi/setup/etc/init.d/ushahidi index 6faa0de..c7fe9b4 100755 --- a/ushahidi/setup/etc/init.d/ushahidi +++ b/ushahidi/setup/etc/init.d/ushahidi @@ -1,21 +1,13 @@ #!/sbin/openrc-run -description="Ushahidi docker container" +description="Ushahidi container" depend() { - need docker mariadb postfix + need cgroups mariadb } start() { - /usr/bin/docker run -d --rm \ - --name ushahidi \ - -h ushahidi \ - --link mariadb \ - --link postfix \ - -v /srv/ushahidi/conf/env:/srv/ushahidi/platform/.env \ - -v /srv/ushahidi/conf/config.json:/srv/ushahidi/config.json \ - -v /srv/ushahidi/data:/srv/ushahidi/platform/application/media/uploads \ - ushahidi + lxc-start ushahidi } start_post() { @@ -27,5 +19,5 @@ stop_pre() { } stop() { - /usr/bin/docker stop ushahidi + lxc-stop ushahidi }