LXCize CTS setup

This commit is contained in:
Disassembler 2018-09-13 19:27:23 +02:00
parent 4c5568f807
commit 7dbfe8533c
Signed by: Disassembler
GPG Key ID: 524BD33A0EE29499
3 changed files with 24 additions and 26 deletions

View File

@ -1,24 +1,21 @@
#!/bin/sh #!/bin/sh
set -e set -e
SOURCE_DIR=$(realpath $(dirname "${0}"))/cts SOURCE_DIR=$(realpath $(dirname "${0}"))/setup
# Check prerequisites # Check prerequisites
lxc-ls | grep -q postgres || $(realpath $(dirname "${0}"))/postgres.sh # TODO: Have setup prereqs in a manifest file
service postgres start for SERVICE in postgres; do
[ ! -e /run/openrc/started/${SERVICE} ] && service ${SERVICE} start && STOP_SERVICES="${STOP_SERVICES} ${SERVICE}"
# Build Docker container done
docker build -t cts ${SOURCE_DIR}
cp ${SOURCE_DIR}/etc/init.d/cts /etc/init.d/cts
rc-update -u
# Create database # Create database
export CTS_PWD=$(head -c 18 /dev/urandom | base64) export CTS_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
# Copy existing config files into persistent storage # Copy existing config files into persistent storage
mkdir -p /srv/cts/conf mkdir -p /srv/cts/conf
docker run --rm -v /srv/cts/conf:/mnt/conf cts cp /srv/cts/cts/settings/base.py /mnt/conf/ cp /var/lib/lxc/cts/cts/srv/cts/cts/settings/base.py /srv/cts/conf
# Configure CTS # Configure CTS
export CTS_SECRET=$(head -c 26 /dev/urandom | base64) export CTS_SECRET=$(head -c 26 /dev/urandom | base64)
@ -31,15 +28,21 @@ if [ ${DEBUG:-0} -eq 0 ]; then
fi fi
# Populate database # Populate database
docker run --rm -h cts --link postgres -v /srv/cts/conf:/srv/cts/cts/settings cts manage.py migrate lxc-execute cts -- manage.py migrate
# Create admin account # Create admin account
export CTS_ADMIN_EMAIL=admin@example.com export CTS_ADMIN_EMAIL=admin@example.com
export CTS_ADMIN_PWD=$(head -c 12 /dev/urandom | base64) export CTS_ADMIN_PWD=$(head -c 12 /dev/urandom | base64)
export CTS_ADMIN_HASH=$(docker run --rm -h cts -v /srv/cts/conf:/srv/cts/cts/settings cts python -c "from django.contrib.auth.hashers import make_password; print make_password('${CTS_ADMIN_PWD}')") export CTS_ADMIN_HASH=$(lxc-execute cts -- python -c "from django.contrib.auth.hashers import make_password; print make_password('${CTS_ADMIN_PWD}')")
export CTS_ADMIN_SECRET=$(head -c 12 /dev/urandom | sha256sum | cut -c1-13) export CTS_ADMIN_SECRET=$(head -c 12 /dev/urandom | sha256sum | cut -c1-13)
envsubst <${SOURCE_DIR}/adminpwd.sql | docker exec -i postgres psql cts envsubst <${SOURCE_DIR}/adminpwd.sql | lxc-attach -u 5432 -g 5432 postgres -- psql cts
vmmgr update-login cts "${CTS_ADMIN_EMAIL}" "${CTS_ADMIN_PWD}" vmmgr update-login cts "${CTS_ADMIN_EMAIL}" "${CTS_ADMIN_PWD}"
# Stop services required for build # Install service
service postgres stop cp ${SOURCE_DIR}/etc/init.d/cts /etc/init.d/cts
rc-update -u
# Stop services required for setup
for SERVICE in ${STOP_SERVICES}; do
service ${SERVICE} stop
done

View File

@ -1,18 +1,13 @@
#!/sbin/openrc-run #!/sbin/openrc-run
description="CTS docker container" description="CTS container"
depend() { depend() {
need docker postgres need cgroups postgres
} }
start() { start() {
/usr/bin/docker run -d --rm \ lxc-start cts
--name cts \
-h cts \
--link postgres \
-v /srv/cts/conf:/srv/cts/cts/settings \
cts
} }
start_post() { start_post() {
@ -24,5 +19,5 @@ stop_pre() {
} }
stop() { stop() {
/usr/bin/docker stop cts lxc-stop cts
} }

View File

@ -14,8 +14,8 @@ ${SOURCE_DIR}/solr/setup.sh
# Setup applications # Setup applications
${SOURCE_DIR}/ckan/setup.sh ${SOURCE_DIR}/ckan/setup.sh
#${SOURCE_DIR}/crisiscleanup/setup.sh ${SOURCE_DIR}/crisiscleanup/setup.sh
#${SOURCE_DIR}/cts/setup.sh ${SOURCE_DIR}/cts/setup.sh
#${SOURCE_DIR}/frontlinesms/setup.sh #${SOURCE_DIR}/frontlinesms/setup.sh
#${SOURCE_DIR}/gnuhealth/setup.sh #${SOURCE_DIR}/gnuhealth/setup.sh
#${SOURCE_DIR}/kanboard/setup.sh #${SOURCE_DIR}/kanboard/setup.sh