From b47df1d71d83de53db20c5590021df8542d67eb7 Mon Sep 17 00:00:00 2001 From: Disassembler Date: Thu, 13 Sep 2018 22:09:01 +0200 Subject: [PATCH] LXCize Sahana setup --- sahana/lxcfile | 2 +- sahana/setup.sh | 21 +++++++++------------ sahana/setup/etc/init.d/sahana | 17 ++++------------- 3 files changed, 14 insertions(+), 26 deletions(-) diff --git a/sahana/lxcfile b/sahana/lxcfile index 41ddfed..422b40d 100644 --- a/sahana/lxcfile +++ b/sahana/lxcfile @@ -49,7 +49,7 @@ COPY lxc RUN EOF # Create OS user addgroup -S -g 8001 sahana - adduser -S -u 8001 -h /srv/web2py -s /bin/sh -g sahana -G sahana sahana + adduser -S -u 8001 -h /srv/web2py -s /bin/false -g sahana -G sahana sahana chown -R sahana:sahana /srv/web2py # Cleanup diff --git a/sahana/setup.sh b/sahana/setup.sh index 938ac10..e648d2e 100755 --- a/sahana/setup.sh +++ b/sahana/setup.sh @@ -1,21 +1,14 @@ #!/bin/sh set -e -SOURCE_DIR=$(realpath $(dirname "${0}"))/sahana +SOURCE_DIR=$(realpath $(dirname "${0}"))/setup # Check prerequisites -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 sahana ${SOURCE_DIR} -cp ${SOURCE_DIR}/etc/init.d/sahana /etc/init.d/sahana -rc-update -u +[ ! -e /run/openrc/started/postgres ] && service postgres start && STOP_POSTGRES=1 # Create PostgreSQL user and database export SAHANA_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 # Prepare persistent directory structure mkdir -p /srv/sahana/conf /srv/sahana/data/databases /srv/sahana/data/uploads @@ -36,7 +29,7 @@ cp ${SOURCE_DIR}/srv/sahana/conf/00_settings.py /srv/sahana/conf/00_settings.py vmmgr update-login sahana "${SAHANA_ADMIN_USER}" "${SAHANA_ADMIN_PWD}" # Populate database -docker run --rm -h sahana --link postgres -v /srv/sahana/conf:/srv/web2py/applications/eden/models -v /srv/sahana/data/Spotter:/srv/web2py/applications/eden/modules/templates/Spotter -v /srv/sahana/data/databases:/srv/web2py/applications/eden/databases sahana su - sahana -c "./web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py" +lxc-execute -u 8001 -g 8001 sahana -- sh -c 'cd /srv/web2py; ./web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py' # Set "production values" (increases performance) only if the DEBUG environment variable is not set if [ ${DEBUG:-0} -eq 0 ]; then @@ -45,5 +38,9 @@ if [ ${DEBUG:-0} -eq 0 ]; then sed -i 's/#settings.base.prepopulate = 0/settings.base.prepopulate = 0/' /srv/sahana/conf/000_config.py fi +# Install service +cp ${SOURCE_DIR}/etc/init.d/sahana /etc/init.d/sahana +rc-update -u + # Stop services required for build -service postgres stop +[ ! -z ${STOP_POSTGRES} ] && service postgres stop diff --git a/sahana/setup/etc/init.d/sahana b/sahana/setup/etc/init.d/sahana index 804a7ab..a8f8c7a 100755 --- a/sahana/setup/etc/init.d/sahana +++ b/sahana/setup/etc/init.d/sahana @@ -1,22 +1,13 @@ #!/sbin/openrc-run -description="Sahana Eden docker container" +description="Sahana Eden container" depend() { - need docker postfix postgres + need cgroups postgres } start() { - /usr/bin/docker run -d --rm \ - --name sahana \ - -h sahana \ - --link postfix \ - --link postgres \ - -v /srv/sahana/conf:/srv/web2py/applications/eden/models \ - -v /srv/sahana/data/Spotter:/srv/web2py/applications/eden/modules/templates/Spotter \ - -v /srv/sahana/data/databases:/srv/web2py/applications/eden/databases \ - -v /srv/sahana/data/uploads:/srv/web2py/applications/eden/uploads \ - sahana + lxc-start sahana } start_post() { @@ -28,5 +19,5 @@ stop_pre() { } stop() { - /usr/bin/docker stop sahana + lxc-stop sahana }