LXCize Pandora setup

This commit is contained in:
Disassembler 2018-09-13 22:02:25 +02:00
parent f2a9529e29
commit f747b89a5d
Signed by: Disassembler
GPG Key ID: 524BD33A0EE29499
2 changed files with 25 additions and 37 deletions

View File

@ -1,39 +1,31 @@
#!/bin/sh #!/bin/sh
set -e set -e
SOURCE_DIR=$(realpath $(dirname "${0}"))/pandora SOURCE_DIR=$(realpath $(dirname "${0}"))/setup
# Check prerequisites # Check prerequisites
lxc-ls | grep -q postfix || $(realpath $(dirname "${0}"))/postfix.sh [ ! -e /run/openrc/started/postgres ] && service postgres start && STOP_POSTGRES=1
lxc-ls | grep -q postgres || $(realpath $(dirname "${0}"))/postgres.sh [ ! -e /run/openrc/started/rabbitmq ] && service rabbitmq start && STOP_RABBITMQ=1
lxc-ls | grep -q rabbitmq || $(realpath $(dirname "${0}"))/rabbitmq.sh
service postgres start
service rabbitmq start
# Build Docker container
docker build -t pandora ${SOURCE_DIR}
cp ${SOURCE_DIR}/etc/init.d/pandora /etc/init.d/pandora
rc-update -u
# Create PostgreSQL user and database # Create PostgreSQL user and database
export PANDORA_PWD=$(head -c 18 /dev/urandom | base64) export PANDORA_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 RabbitMQ # Configure RabbitMQ
export PANDORA_RABBIT_PWD=$(head -c 18 /dev/urandom | base64 | tr -d "/") export PANDORA_RABBIT_PWD=$(head -c 18 /dev/urandom | base64 | tr -d "/")
docker exec rabbitmq rabbitmqctl add_user pandora ${PANDORA_RABBIT_PWD} lxc-attach rabbitmq -- rabbitmqctl add_user pandora ${PANDORA_RABBIT_PWD}
docker exec rabbitmq rabbitmqctl add_vhost /pandora lxc-attach rabbitmq -- rabbitmqctl add_vhost /pandora
docker exec rabbitmq rabbitmqctl set_permissions -p /pandora pandora ".*" ".*" ".*" lxc-attach rabbitmq -- rabbitmqctl set_permissions -p /pandora pandora ".*" ".*" ".*"
# Configure Pandora # Configure Pandora
mkdir -p /srv/pandora/conf /srv/pandora/data mkdir -p /srv/pandora/conf /srv/pandora/data
chown 8002:8002 /srv/pandora/data chown 8002:8002 /srv/pandora/data
# Copy customized configuration if VANILLA environment variable is not set, else use the default pandora config # Copy customized configuration if VANILLA environment variable is not set, else use the default pandora config
if [ ${VANILLA:-0} -eq 0 ]; then if [ ${VANILLA:-0} -eq 0 ]; then
cp ${SOURCE_DIR}/srv/pandora/conf/config.jsonc /srv/pandora/conf/config.jsonc cp ${SOURCE_DIR}/srv/pandora/conf/config.jsonc /srv/pandora/conf
else else
chown 8002:8002 /srv/pandora/conf chown 8002:8002 /srv/pandora/conf
docker run --rm -v /srv/pandora/conf:/srv/pandora/conf pandora cp /srv/pandora/pandora/config.pandora.jsonc /srv/pandora/conf/config.jsonc cp /var/lib/lxc/pandora/pandora/srv/pandora/pandora/config.pandora.jsonc /srv/pandora/conf
fi fi
cp ${SOURCE_DIR}/srv/pandora/conf/gunicorn_config.py /srv/pandora/conf/gunicorn_config.py cp ${SOURCE_DIR}/srv/pandora/conf/gunicorn_config.py /srv/pandora/conf/gunicorn_config.py
envsubst <${SOURCE_DIR}/srv/pandora/conf/local_settings.py >/srv/pandora/conf/local_settings.py envsubst <${SOURCE_DIR}/srv/pandora/conf/local_settings.py >/srv/pandora/conf/local_settings.py
@ -44,19 +36,23 @@ if [ ${DEBUG:-0} -eq 0 ]; then
fi fi
# Populate database # Populate database
docker run --rm -h pandora --link postgres -v /srv/pandora/conf:/srv/pandora/conf pandora /srv/pandora/pandora/manage.py migrate --noinput lxc-execute pandora -- /srv/pandora/pandora/manage.py migrate --noinput
docker run --rm -h pandora --link postgres -v /srv/pandora/conf:/srv/pandora/conf pandora /srv/pandora/pandora/manage.py sqlfindindex lxc-execute pandora -- /srv/pandora/pandora/manage.py sqlfindindex
docker run --rm -h pandora --link postgres -v /srv/pandora/conf:/srv/pandora/conf pandora /srv/pandora/pandora/manage.py sync_itemsort lxc-execute pandora -- /srv/pandora/pandora/manage.py sync_itemsort
docker run --rm -h pandora --link postgres -v /srv/pandora/conf:/srv/pandora/conf pandora /srv/pandora/pandora/manage.py sync_documentsort lxc-execute pandora -- /srv/pandora/pandora/manage.py sync_documentsort
# Create admin account # Create admin account
export PANDORA_ADMIN_USER=admin export PANDORA_ADMIN_USER=admin
export PANDORA_ADMIN_EMAIL=admin@example.com export PANDORA_ADMIN_EMAIL=admin@example.com
export PANDORA_ADMIN_PWD=$(head -c 12 /dev/urandom | base64) export PANDORA_ADMIN_PWD=$(head -c 12 /dev/urandom | base64)
export PANDORA_ADMIN_HASH=$(docker run --rm -h pandora -e DJANGO_SETTINGS_MODULE=pandora.settings -v /srv/pandora/conf:/srv/pandora/conf pandora python3 -c "from django.contrib.auth.hashers import make_password; print(make_password('${PANDORA_ADMIN_PWD}'))") export PANDORA_ADMIN_HASH=$(lxc-execute pandora -- sh -c "DJANGO_SETTINGS_MODULE=pandora.settings python3 -c \"from django.contrib.auth.hashers import make_password; print(make_password('${PANDORA_ADMIN_PWD}'))\"")
envsubst <${SOURCE_DIR}/adminpwd.sql | docker exec -i postgres psql pandora envsubst <${SOURCE_DIR}/adminpwd.sql | lxc-attach -u 5432 -g 5432 postgres -- psql pandora
vmmgr update-login pandora "${PANDORA_ADMIN_USER}" "${PANDORA_ADMIN_PWD}" vmmgr update-login pandora "${PANDORA_ADMIN_USER}" "${PANDORA_ADMIN_PWD}"
# Install service
cp ${SOURCE_DIR}/etc/init.d/pandora /etc/init.d/pandora
rc-update -u
# Stop services required for build # Stop services required for build
service rabbitmq stop [ ! -z ${STOP_POSTGRES} ] && service postgres stop
service postgres stop [ ! -z ${STOP_RABBITMQ} ] && service rabbitmq stop

View File

@ -1,21 +1,13 @@
#!/sbin/openrc-run #!/sbin/openrc-run
description="Pan.do/ra docker container" description="Pan.do/ra container"
depend() { depend() {
need docker postfix postgres rabbitmq need cgroups postgres rabbitmq
} }
start() { start() {
/usr/bin/docker run -d --rm \ lxc-start pandora
--name pandora \
-h pandora \
--link postfix \
--link postgres \
--link rabbitmq \
-v /srv/pandora/conf:/srv/pandora/conf \
-v /srv/pandora/data:/srv/pandora/data \
pandora
} }
start_post() { start_post() {
@ -27,5 +19,5 @@ stop_pre() {
} }
stop() { stop() {
/usr/bin/docker stop pandora lxc-stop pandora
} }