turn database initialization into a manage.py command

This commit is contained in:
j 2015-01-19 16:34:21 +01:00
parent b3d1a8d04c
commit bf65abae55
3 changed files with 48 additions and 26 deletions

29
README
View file

@ -15,7 +15,8 @@ To run pan.do/ra you need to install and setup:
additinal video packages additinal video packages
* Installing required packages === Installing required packages ===
1) add pandora ppa to get all packages in the required version 1) add pandora ppa to get all packages in the required version
apt-get install software-properties-common apt-get install software-properties-common
@ -31,7 +32,8 @@ To run pan.do/ra you need to install and setup:
poppler-utils mkvtoolnix gpac imagemagick \ poppler-utils mkvtoolnix gpac imagemagick \
python-ox oxframe ffmpeg python-ox oxframe ffmpeg
* Prepare Environment === Prepare Environment ===
1) add pandora user and set permissions 1) add pandora user and set permissions
adduser pandora --disabled-login --disabled-password adduser pandora --disabled-login --disabled-password
@ -50,7 +52,8 @@ Important: "use_your_own" is a password and you have to use the same value here
rabbitmqctl set_permissions -p /pandora pandora ".*" ".*" ".*" rabbitmqctl set_permissions -p /pandora pandora ".*" ".*" ".*"
* Install Pan.do/ra === Install Pan.do/ra ===
1) Get code from bazzar 1) Get code from bazzar
cd /srv/ cd /srv/
bzr branch http://code.0x2620.org/pandora pandora bzr branch http://code.0x2620.org/pandora pandora
@ -66,7 +69,7 @@ Important: "use_your_own" is a password and you have to use the same value here
2) create local_settings.py and config.jsonc 2) create local_settings.py and config.jsonc
1) create file /srv/pandora/pandora/local_settings.py with the following content: 2.1) create file /srv/pandora/pandora/local_settings.py with the following content:
DATABASES = { DATABASES = {
'default': { 'default': {
'NAME': 'pandora', 'NAME': 'pandora',
@ -84,7 +87,7 @@ Important: "use_your_own" is a password and you have to use the same value here
#with nginx X-Accel-Redirect set this to True #with nginx X-Accel-Redirect set this to True
XACCELREDIRECT = True XACCELREDIRECT = True
2) create config.jsonc 2.2) create config.jsonc
config.jsonc holds the configuration for your site. config.jsonc holds the configuration for your site.
To start you can copy /srv/pandora/pandora/config.pandora.jsonc To start you can copy /srv/pandora/pandora/config.pandora.jsonc
to /srv/pandora/pandora/config.jsonc but have a look at to /srv/pandora/pandora/config.jsonc but have a look at
@ -94,15 +97,7 @@ Important: "use_your_own" is a password and you have to use the same value here
3) initialize database 3) initialize database
su pandora su pandora
cd /srv/pandora/pandora cd /srv/pandora/pandora
./manage.py syncdb --noinput ./manage.py init_db
./manage.py migrate item
./manage.py migrate annotation
./manage.py migrate
./manage.py sqlfindindex
./manage.py sync_itemsort
./manage.py collectstatic -l --noinput
./manage.py update_static
./manage.py compile_pyc
4) install init scripts and start daemons 4) install init scripts and start daemons
cp /srv/pandora/etc/init/*.conf /etc/init/ cp /srv/pandora/etc/init/*.conf /etc/init/
@ -136,7 +131,7 @@ b) apache2 (if you need it for other sites on the same server)
Now you can open pandora in your browser, the first user to sign up will become admin. Now you can open pandora in your browser, the first user to sign up will become admin.
=== Updating === == Updating ==
To update a pandora installation get the latest version from bzr by running To update a pandora installation get the latest version from bzr by running
su pandora su pandora
cd /srv/pandora cd /srv/pandora
@ -149,7 +144,7 @@ to update your database run:
cd /srv/pandora cd /srv/pandora
./update.py db ./update.py db
=== Development === == Development ==
in one terminal: in one terminal:
./manage.py runserver 2620 ./manage.py runserver 2620
@ -158,5 +153,5 @@ to update your database run:
now you can access your local pandora instace at http://127.0.0.1:8000/ now you can access your local pandora instace at http://127.0.0.1:8000/
we use virtual machines for development, you can get a vm from our site we use virtual machines/lxc for development, you can get a vm from our site
or use the script in vm/build.sh to create one. or use the script in vm/build.sh to create one.

View file

@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
from django.core.management.base import BaseCommand
from django.conf import settings
import os
import subprocess
import sys
def run(cmd):
r = subprocess.call(cmd)
if r != 0:
sys.exit(r)
class Command(BaseCommand):
"""
"""
help = 'initialize pan.do/ra db'
args = ''
def handle(self, **options):
manage_py = sys.argv[0]
for cmd in [
[manage_py, 'syncdb', '--noinput'],
[manage_py, 'migrate', 'item'],
[manage_py, 'migrate', 'annotation'],
[manage_py, 'migrate'],
[manage_py, 'sqlfindindex'],
[manage_py, 'sync_itemsort'],
[manage_py, 'update_static'],
[manage_py, 'compile_pyc'],
]:
run(cmd)
if not os.path.exists(os.path.join(settings.STATIC_ROOT, 'admin')):
run([manage_py, 'collectstatic', '-l', '--noinput'])

View file

@ -110,24 +110,17 @@ XACCELREDIRECT = True
DEBUG = False DEBUG = False
TEMPLATE_DEBUG = DEBUG TEMPLATE_DEBUG = DEBUG
JSON_DEBUG = False JSON_DEBUG = False
DB_GIN_TRGM = True
EOF EOF
MANAGE="sudo -H -u pandora python manage.py" MANAGE="sudo -H -u pandora python manage.py"
cd /srv/pandora/pandora cd /srv/pandora/pandora
$MANAGE syncdb --noinput $MANAGE init_db
$MANAGE migrate item
$MANAGE migrate annotation
$MANAGE migrate
echo "DB_GIN_TRGM = True" >> /srv/pandora/pandora/local_settings.py
$MANAGE sqlfindindex
$MANAGE sync_itemsort
echo "UPDATE django_site SET domain = '$HOST.local', name = '$HOST.local' WHERE 1=1;" | $MANAGE dbshell echo "UPDATE django_site SET domain = '$HOST.local', name = '$HOST.local' WHERE 1=1;" | $MANAGE dbshell
mkdir /srv/pandora/data mkdir /srv/pandora/data
chown -R pandora:pandora /srv/pandora chown -R pandora:pandora /srv/pandora
$MANAGE update_static
$MANAGE collectstatic -l --noinput
if [ "$SYSTEMD" == "yes" ]; then if [ "$SYSTEMD" == "yes" ]; then
cp /srv/pandora/etc/systemd/*.service /lib/systemd/system/ cp /srv/pandora/etc/systemd/*.service /lib/systemd/system/