Merge branch pandora

This commit is contained in:
Disassembler 2017-09-11 16:20:44 +02:00
commit 822dd1552f
5 changed files with 170 additions and 0 deletions

67
50-pandora.sh Normal file
View File

@ -0,0 +1,67 @@
#!/bin/bash
SOURCE_DIR=$(realpath $(dirname "${0}"))
# Add pandora repository
echo "deb http://ppa.launchpad.net/j/pandora/ubuntu zesty main" > /etc/apt/sources.list.d/pandora.list
apt-key add ${SOURCE_DIR}/pandora/pandora.gpg
# Install packages
apt-get -y update
apt-get -y --no-install-recommends install gpac poppler-utils rabbitmq-server python3-setuptools python3-pip virtualenv python3-virtualenv python3-pil python3-numpy python3-psycopg2 python3-pyinotify python3-simplejson python3-lxml python3-html5lib python3-ox oxframe ffmpeg mkvtoolnix youtube-dl
# python3-dev imagemagick
# Clone git repositories
git clone --depth 1 https://git.0x2620.org/pandora.git /srv/pandora
git clone --depth 1 https://git.0x2620.org/oxjs.git /srv/pandora/static/oxjs
git clone --depth 1 https://git.0x2620.org/oxtimelines.git /srv/pandora/src/oxtimelines
git clone --depth 1 https://git.0x2620.org/python-ox.git /srv/pandora/src/python-ox
# Create python virtualenv
virtualenv --system-site-packages -p /usr/bin/python3 /srv/pandora
cd /srv/pandora/src/oxtimelines && /srv/pandora/bin/python setup.py develop
cd /srv/pandora/src/python-ox && /srv/pandora/bin/python setup.py develop
/srv/pandora/bin/pip install -r /srv/pandora/requirements.txt
# Create PostgreSQL user and database
export PANDORA_PWD=$(head -c 260 /dev/urandom | tr -cd '[:alnum:]' | head -c 26)
envsubst <${SOURCE_DIR}/pandora/tmp/pandora-createdb.sql >/tmp/pandora-createdb.sql
sudo -u postgres psql -f /tmp/pandora-createdb.sql
rm -f /tmp/pandora-createdb.sql
# Configure RabbitMQ
export PANDORA_RABBIT_PWD=$(head -c 260 /dev/urandom | tr -cd '[:alnum:]' | head -c 26)
rabbitmqctl add_user pandora ${PANDORA_RABBIT_PWD}
rabbitmqctl add_vhost /pandora
rabbitmqctl set_permissions -p /pandora pandora ".*" ".*" ".*"
export PANDORA_BROKER_URL="amqp://pandora:${PANDORA_RABBIT_PWD}@localhost:5672//pandora"
# Configure Pandora
mkdir /srv/pandora/data
cp /srv/pandora/pandora/config.pandora.jsonc /srv/pandora/pandora/config.jsonc
cp /srv/pandora/pandora/gunicorn_config.py.in /srv/pandora/pandora/gunicorn_config.py
envsubst <${SOURCE_DIR}/pandora/srv/pandora/pandora/local_settings.py >/srv/pandora/pandora/local_settings.py
# Create OS user
adduser --system --group --home /srv/pandora --shell /bin/false pandora
chown -R pandora:pandora /srv/pandora
# Populate database
sudo -u pandora /srv/pandora/pandora/manage.py init_db
# Install systemd services
cp /srv/pandora/etc/systemd/system/*.service /etc/systemd/system/
cp /srv/pandora/etc/tmpfiles.d/pandora.conf /etc/tmpfiles.d/
systemd-tmpfiles --create /etc/tmpfiles.d/pandora.conf
systemctl daemon-reload
# Create nginx site definition
cp ${SOURCE_DIR}/pandora/etc/nginx/sites-available/pandora /etc/nginx/sites-available/pandora
ln -s /etc/nginx/sites-available/pandora /etc/nginx/sites-enabled/pandora
# Start services
for SERVICE in "pandora pandora-tasks pandora-encoding pandora-cron pandora-websocketd"; do
systemctl enable ${SERVICE}
systemctl start ${SERVICE}
done
systemctl restart nginx

View File

@ -0,0 +1,69 @@
server {
listen 8001 ssl http2;
listen [::]:8001 ssl http2;
ssl_certificate /etc/ssl/certs/services.pem;
ssl_certificate_key /etc/ssl/private/services.key;
ssl_protocols TLSv1.2;
ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 1d;
ssl_session_tickets off;
access_log /var/log/nginx/pandora.access.log;
error_log /var/log/nginx/pandora.error.log;
location /favicon.ico {
root /srv/pandora/static;
}
location /static/ {
root /srv/pandora;
autoindex off;
}
location /data/ {
internal;
root /srv/pandora;
}
location /api/ws/ {
proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Proxy "";
proxy_redirect off;
proxy_buffering off;
proxy_read_timeout 999999999;
proxy_pass http://127.0.0.1:2622/;
}
location / {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto http;
proxy_set_header Host $http_host;
proxy_set_header Proxy "";
proxy_redirect off;
proxy_buffering off;
proxy_read_timeout 90;
proxy_connect_timeout 90;
if (!-f $request_filename) {
proxy_pass http://127.0.0.1:2620;
break;
}
client_max_body_size 32m;
}
error_page 400 /;
error_page 404 /404.html;
location /404.html {
root /srv/pandora/static/html;
}
error_page 500 502 503 504 /50x.html;
location /50x.html {
root /srv/pandora/static/html;
}
}

13
pandora/pandora.gpg Normal file
View File

@ -0,0 +1,13 @@
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1
mI0ESXYhEgEEALl9jDTdmgpApPbjN+7b85dC92HisPUp56ifEkKJOBj0X5HhRqxs
Wjx/zlP4/XJGrHnxJyrdPxjSwAXz7bNdeggkN4JWdusTkr5GOXvggQnng0X7f/rX
oJwoEGtYOCODLPs6PC0qjh5yPzJVeiRsKUOZ7YVNnwNwdfS4D8RZvtCrABEBAAG0
FExhdW5jaHBhZCBQUEEgZm9yIGpeiLYEEwECACAFAkl2IRICGwMGCwkIBwMCBBUC
CAMEFgIDAQIeAQIXgAAKCRAohRM8AZde82FfA/9OB/64/YLaCpizHZ8f6DK3rGgF
e6mX3rFK8yOKGGL06316VhDzfzMiZSauUZ0t+lKHR/KZYeSaFwEoUoblTG/s4IIo
9aBMHWhVXJW6eifKUmTGqEn2/0UxoWQq2C3F6njMkCaP+ALOD5uzaSYGdjqAUAwS
pAAGSEQ4uz6bYSeM4Q==
=SM2a
-----END PGP PUBLIC KEY BLOCK-----

View File

@ -0,0 +1,15 @@
DATABASES = {
'default': {
'NAME': 'pandora',
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'USER': 'pandora',
'PASSWORD': '${PANDORA_PWD}',
}
}
BROKER_URL = '${PANDORA_BROKER_URL}'
DB_GIN_TRGM = True
XACCELREDIRECT = True
DEBUG = False
TEMPLATE_DEBUG = DEBUG
JSON_DEBUG = False

View File

@ -0,0 +1,6 @@
CREATE ROLE pandora NOSUPERUSER NOCREATEDB NOCREATEROLE NOINHERIT LOGIN ENCRYPTED PASSWORD '${PANDORA_PWD}';
CREATE DATABASE pandora;
REVOKE ALL ON DATABASE pandora FROM public;
ALTER DATABASE pandora OWNER TO pandora;
\c pandora;
CREATE EXTENSION pg_trgm;