print local name and ip in vm terminal, document trigram index

This commit is contained in:
j 2012-03-30 16:57:07 +02:00
parent 82d939e6e3
commit 0042546d6c
5 changed files with 90 additions and 10 deletions

39
README
View file

@ -41,19 +41,38 @@ create / update static files
./manage.py update_static ./manage.py update_static
./manage.py compile_pyc ./manage.py compile_pyc
* Database * Database
We use postgresql but other databases might also work We use postgresql but other databases might also work
(make sure you have the python bindings installed). (make sure you have the python bindings installed).
create a postgresql database and adjust settings in local_settings.py create a postgresql database
and run ./manage.py syncdb to populate the database.
createdb -T template0 --locale=C --encoding=UTF8 -O pandora pandora sudo -u postgres createdb -T template0 --locale=C --encoding=UTF8 -O pandora pandora
(setting locale to C is required to fix a bug in sort if set to UTF8) (setting locale to C is required to fix a bug in sort if set to UTF8)
now add settings to local_settings.py:
DATABASES = {
'default': {
'NAME': 'pandora',
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'USER': 'pandora',
}
}
and run ./manage.py syncdb to populate the database.
Optionaly use pg_trgm to improve find speed (requires postgres 9.1 and postgresql-contrib)
echo "CREATE EXTENSION pg_trgm;" | sudo -u postgres psql pandora
./manage.py sqlfindindex | ./manage.py dbshell
echo "DB_GIN_TRGM = True" >> local_settings.py
* RabbitMQ * RabbitMQ
For background tasks we use RabbitMQ, to install rabbitmq: For background tasks RabbitMQ is required, to install rabbitmq:
sudo apt-get install rabbitmq-server sudo apt-get install rabbitmq-server
and create permissions according to BROKER_* in local_settings.py i.e.: and create permissions according to BROKER_* in local_settings.py i.e.:
@ -62,10 +81,12 @@ create / update static files
sudo rabbitmqctl add_vhost /pandora sudo rabbitmqctl add_vhost /pandora
sudo rabbitmqctl set_permissions -p /pandora pandora ".*" ".*" ".*" sudo rabbitmqctl set_permissions -p /pandora pandora ".*" ".*" ".*"
* H264 * H264
to support h264 videos, install ffmpeg with x264 enabled, for h264 videos, you need to compile ffmpeg with x264 and libfaac enabled,
install qt-faststart from (ffmpeg/tools) you also need to install qt-faststart (from ffmpeg/tools)
to enable add "mp4" to video.formats in your config.jsonc to enable h264 derivatives add "mp4" to video.formats in your config.jsonc
== Deployment == == Deployment ==
* Install upstart scripts * Install upstart scripts
@ -104,3 +125,7 @@ to apply them.
=== Development === === Development ===
in one terminal: in one terminal:
./manage.py runserver ./manage.py runserver
and background task in another:
./manage.py celeryd -B -Q default,encoding

View file

@ -132,7 +132,6 @@ attrs = {
'volume': models.FloatField(default=0, null=True, db_index=True), 'volume': models.FloatField(default=0, null=True, db_index=True),
'sortvalue': models.CharField(max_length=1000, null=True, db_index=True), 'sortvalue': models.CharField(max_length=1000, null=True, db_index=True),
#run this CREATE INDEX clip_clip_findvalue_idx ON clip_clip USING gin (findvalue gin_trgm_ops);
'findvalue': models.TextField(null=True, db_index=settings.DB_GIN_TRGM), 'findvalue': models.TextField(null=True, db_index=settings.DB_GIN_TRGM),
} }
for name in settings.CONFIG['clipLayers']: for name in settings.CONFIG['clipLayers']:

View file

@ -0,0 +1,21 @@
# -*- 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 monkey_patch.models
from ... import models
class Command(BaseCommand):
"""
print sql statement to add trigram
"""
help = 'sql create statements for find tables to use trigram index'
args = ''
def handle(self, **options):
print 'CREATE INDEX item_itemfind_value_idx ON item_itemfind USING gin (value gin_trgm_ops);'
print ''
print 'CREATE INDEX clip_clip_findvalue_idx ON clip_clip USING gin (findvalue gin_trgm_ops);'

View file

@ -1297,7 +1297,6 @@ class ItemFind(models.Model):
item = models.ForeignKey('Item', related_name='find', db_index=True) item = models.ForeignKey('Item', related_name='find', db_index=True)
key = models.CharField(max_length=200, db_index=True) key = models.CharField(max_length=200, db_index=True)
#CREATE INDEX item_itemfind_value_idx ON item_itemfind USING gin (value gin_trgm_ops);
value = models.TextField(blank=True, db_index=settings.DB_GIN_TRGM) value = models.TextField(blank=True, db_index=settings.DB_GIN_TRGM)
def __unicode__(self): def __unicode__(self):

View file

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
#fails in bootstrap #fails in bootstrap
apt-get -y install ipython apt-get -y install ipython ntp
#ffmpeg #ffmpeg
wget http://firefogg.org/nightly/ffmpeg.linux -O /usr/local/bin/ffmpeg wget http://firefogg.org/nightly/ffmpeg.linux -O /usr/local/bin/ffmpeg
@ -13,6 +13,7 @@ chmod 755 /usr/local/bin/ffmpeg2theora
apt-get -y install postgresql postgresql-contrib apt-get -y install postgresql postgresql-contrib
sudo -u postgres createuser -S -D -R pandora sudo -u postgres createuser -S -D -R pandora
sudo -u postgres createdb -T template0 --locale=C --encoding=UTF8 -O pandora pandora sudo -u postgres createdb -T template0 --locale=C --encoding=UTF8 -O pandora pandora
echo "CREATE EXTENSION pg_trgm;" | sudo -u postgres psql pandora
#rabbitmq #rabbitmq
RABBITPWD=$(pwgen -n 16 -1) RABBITPWD=$(pwgen -n 16 -1)
@ -38,10 +39,12 @@ DATA_SERVICE = ""
SITE_CONFIG = '$SITE_CONFIG' SITE_CONFIG = '$SITE_CONFIG'
BROKER_PASSWORD = "$RABBITPWD" BROKER_PASSWORD = "$RABBITPWD"
XACCELREDIRECT = True XACCELREDIRECT = True
DB_GIN_TRGM = True
EOF EOF
cd /srv/pandora/pandora cd /srv/pandora/pandora
sudo -u pandora python manage.py syncdb --noinput sudo -u pandora python manage.py syncdb --noinput
sudo -u pandora python manage.py sqlfindindex | sudo -u pandora python manage.py dbshell
echo "UPDATE django_site SET domain = '$HOST.local', name = '$HOST.local' WHERE 1=1;" | sudo -u pandora python manage.py dbshell echo "UPDATE django_site SET domain = '$HOST.local', name = '$HOST.local' WHERE 1=1;" | sudo -u pandora python manage.py dbshell
@ -59,3 +62,36 @@ service pandora start
sed "s/__PREFIX__/\/srv\/pandora/g" "/srv/pandora/etc/nginx/vhost.in" > "/etc/nginx/sites-available/default" sed "s/__PREFIX__/\/srv\/pandora/g" "/srv/pandora/etc/nginx/vhost.in" > "/etc/nginx/sites-available/default"
service nginx restart service nginx restart
cat > /usr/local/bin/fixtime <<EOF
#!/bin/bash
while [ 1 ]; do
/usr/sbin/ntpdate pool.ntp.org >/dev/null
sleep 600
done
EOF
chmod +x /usr/local/bin/fixtime
cat > /usr/local/bin/genissue <<EOF
#!/bin/bash
HOST=\$(rgrep .local /var/log/syslog | grep "Host name is" | tail -n 1 | awk '{print \$12}' | sed 's/\.$//')
echo Welcome to pan.do/ra - connect via one of those urls:
echo
echo " http://\$HOST/"
for ip in \$(ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print \$1 }'); do
echo " http://\$ip/"
done
echo
EOF
chmod +x /usr/local/bin/genissue
cat > /etc/rc.local << EOF
#!/bin/sh -e
#vm has one network interface and that might change, make it not persistent
rm -f /etc/udev/rules.d/70-persistent-net.rules
#vm can be suspended, this help to keep the time in sync
/usr/local/bin/fixtime &
#update issue
/usr/local/bin/genissue > /etc/issue
EOF
chmod +x /etc/rc.local