Rework Pan.do/ra

This commit is contained in:
Disassembler 2019-10-05 15:18:36 +02:00
parent eac6129fb3
commit 826b244bae
Signed by: Disassembler
GPG Key ID: 524BD33A0EE29499
9 changed files with 68 additions and 69 deletions

View File

@ -3,37 +3,44 @@ set -ev
cd $(realpath $(dirname "${0}"))/install
# Check prerequisites
[ ! -e /run/openrc/started/postgres ] && service postgres start && STOP_POSTGRES=1
[ ! -e /run/openrc/started/rabbitmq ] && service rabbitmq start && STOP_RABBITMQ=1
# Create Postgres instance
mkdir -p /srv/pandora/postgres_data
chown -R 105432:105432 /srv/pandora/postgres_data
chmod 700 /srv/pandora/postgres_data
lxc-execute -n pandora-postgres -- initdb -D /var/lib/postgresql
# Configure Postgres
cp postgres_data/postgresql.conf /srv/pandora/postgres_data/postgresql.conf
cp postgres_data/pg_hba.conf /srv/pandora/postgres_data/pg_hba.conf
# Create PostgreSQL user and database
export PANDORA_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
envsubst <createdb.sql | lxc-attach -u 5432 -g 5432 postgres -- psql
service pandora-postgres start
envsubst <createdb.sql | lxc-attach -u 5432 -g 5432 pandora-postgres -- psql
# Create RabbitMQ directory structure
mkdir -p /srv/pandora/rabbitmq_data
chown 105672:105672 /srv/pandora/rabbitmq_data
# Configure RabbitMQ
export PANDORA_RABBIT_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
lxc-attach rabbitmq -- rabbitmqctl add_user pandora ${PANDORA_RABBIT_PWD}
lxc-attach rabbitmq -- rabbitmqctl add_vhost /pandora
lxc-attach rabbitmq -- rabbitmqctl set_permissions -p /pandora pandora ".*" ".*" ".*"
service pandora-rabbitmq start
lxc-attach pandora-rabbitmq -- rabbitmqctl add_user pandora ${PANDORA_RABBIT_PWD}
lxc-attach pandora-rabbitmq -- rabbitmqctl add_vhost /pandora
lxc-attach pandora-rabbitmq -- rabbitmqctl set_permissions -p /pandora pandora ".*" ".*" ".*"
# Configure Pandora
mkdir -p /srv/pandora/conf /srv/pandora/data
chown 8002:8002 /srv/pandora/data
mkdir -p /srv/pandora/pandora_conf /srv/pandora/pandora_data
chown 108002:108002 /srv/pandora/pandora_data
# Copy customized configuration if VANILLA environment variable is not set, else use the default pandora config
if [ ${VANILLA:-0} -eq 0 ]; then
cp srv/pandora/conf/config.jsonc /srv/pandora/conf
cp pandora_conf/config.jsonc /srv/pandora/pandora_conf/config.jsonc
else
chown 8002:8002 /srv/pandora/conf
cp /var/lib/lxc/pandora/pandora/srv/pandora/pandora/config.pandora.jsonc /srv/pandora/conf/config.jsonc
fi
cp srv/pandora/conf/gunicorn_config.py /srv/pandora/conf/gunicorn_config.py
envsubst <srv/pandora/conf/local_settings.py >/srv/pandora/conf/local_settings.py
# Set "production values" (increases performance) only if the DEBUG environment variable is not set
if [ ${DEBUG:-0} -eq 0 ]; then
sed -i 's/DEBUG = True/DEBUG = False/' /srv/pandora/conf/local_settings.py
lxc-execute pandora -- cat /srv/pandora/pandora/config.pandora.jsonc >/srv/pandora/pandora_conf/config.jsonc
fi
cp pandora_conf/gunicorn_config.py /srv/pandora/pandora_conf/gunicorn_config.py
envsubst <pandora_conf/local_settings.py >/srv/pandora/pandora_conf/local_settings.py
chown -R 108002:108002 /srv/pandora/pandora_conf
# Populate database
lxc-execute pandora -- /srv/pandora/pandora/manage.py migrate --noinput
@ -46,18 +53,14 @@ export PANDORA_ADMIN_USER=admin
export PANDORA_ADMIN_EMAIL=admin@example.com
export PANDORA_ADMIN_PWD=$(head -c 12 /dev/urandom | base64 | tr -d '+/=')
export PANDORA_ADMIN_HASH=$(lxc-execute pandora -- sh -c "DJANGO_SETTINGS_MODULE=srv.pandora.pandora.settings python3 -c \"from django.contrib.auth.hashers import make_password; print(make_password('${PANDORA_ADMIN_PWD}'))\"")
envsubst <adminpwd.sql | lxc-attach -u 5432 -g 5432 postgres -- psql pandora
# Install service
cp etc/init.d/pandora /etc/init.d/pandora
rc-update -u
envsubst <adminpwd.sql | lxc-attach -u 5432 -g 5432 pandora-postgres -- psql pandora
# Install config update script
cp srv/pandora/update-conf.sh /srv/pandora/update-conf.sh
cp update-conf.sh /srv/pandora/update-conf.sh
# Stop services required for build
[ ! -z ${STOP_POSTGRES} ] && service postgres stop
[ ! -z ${STOP_RABBITMQ} ] && service rabbitmq stop
# Stop services required for setup
service pandora-postgres stop
service pandora-rabbitmq stop
# Register application
vmmgr register-app pandora pandora "${PANDORA_ADMIN_USER}" "${PANDORA_ADMIN_PWD}"

View File

@ -1,23 +0,0 @@
#!/sbin/openrc-run
description="Pan.do/ra container"
depend() {
need postgres rabbitmq
}
start() {
lxc-start pandora
}
start_post() {
vmmgr register-proxy pandora
}
stop_pre() {
vmmgr unregister-proxy pandora
}
stop() {
lxc-stop pandora
}

View File

@ -17,5 +17,5 @@ XACCELREDIRECT = True
GOOGLE_API_KEY = ''
DEBUG = True
DEBUG = False
JSON_DEBUG = DEBUG

View File

@ -89,7 +89,4 @@ RUN EOF
rm -rf /root/.cache /root/.ox
EOF
MOUNT DIR /srv/pandora/conf srv/pandora/conf
MOUNT DIR /srv/pandora/data srv/pandora/data
CMD s6-svscan /etc/services.d

34
lxc-apps/pandora/meta Normal file
View File

@ -0,0 +1,34 @@
{
"version": "0.0.1-190620",
"meta": {
"title": "Pan.do/ra",
"desc-cs": "Archiv medií",
"desc-en": "Media archive",
"license": "GPL",
},
"containers": {
"pandora": {
"image": "pandora_0.0.1-190620",
"depends": [
"pandora-postgres",
"pandora-rabbitmq"
],
"mounts": [
["DIR", "/srv/pandora/pandora_conf", "/srv/pandora/conf"],
["DIR", "/srv/pandora/pandora_data", "/srv/pandora/data"]
]
},
"pandora-postgres": {
"image": "postgis_11.3.0-190620",
"mounts": [
["DIR", "/srv/pandora/postgres_data", "/var/lib/postgresql"]
]
},
"pandora-rabbitmq": {
"image": "pandora-build_0.3.5-190620",
"mounts": [
["DIR", "/srv/pandora/rabbitmq_data", "/var/lib/rabbitmq/mnesia"]
]
}
}
}

View File

@ -1,20 +1,8 @@
#!/bin/sh
set -ev
# Remove service
rm -f /etc/init.d/pandora
rc-update -u
# Drop database and user
[ ! -e /run/openrc/started/postgres ] && service postgres start && STOP_POSTGRES=1
echo 'DROP DATABASE IF EXISTS pandora; DROP ROLE IF EXISTS pandora;' | lxc-attach -u 5432 -g 5432 postgres -- psql
[ ! -z ${STOP_POSTGRES} ] && service postgres stop
# Remove RabbitMQ vhost and user
[ ! -e /run/openrc/started/rabbitmq ] && service rabbitmq start && STOP_RABBITMQ=1
lxc-attach rabbitmq -- rabbitmqctl delete_vhost /pandora || true
lxc-attach rabbitmq -- rabbitmqctl delete_user pandora || true
[ ! -z ${STOP_RABBITMQ} ] && service rabbitmq stop
# Remove persistent data
rm -rf /srv/pandora
# Unregister application
vmmgr unregister-app pandora