Installation and Setup

Hubert Hesse edited this page Mar 3, 2014 · 7 revisions
Clone this wiki locally

Requirements

First you'll need to have Python, pip and virtual_env on your device. If you don't have them you should install this. Please Google it, it's not that hard ;)

Clone the repository

git clone https://github.com/Piratenfraktion-Berlin
cd OwnTube
git submodule init
git submodule update

Setup your virtualenv

Virtualenv is used to have a environment where you can install all the required Python packages (eggs in Python) without side effects on your system. To do so just enter these commands:

virtualenv .venv
source .venv/bin/activate

Now you should see a (.venv) in front of you command prompt. This tells you that the virtalenv is activated

Install the required Python eggs

There is a dependencies.txt file where all needed Python eggs are listed. But don't worry, you don't need to install them by hand. Just do a

pip install -r dependencies.txt

Make your settings

First copy your the example settings file to make it your "real" settings file

cp owntube/settings.example.py owntube/settings.py

Second edit your settings file with your favorite text editor

vi owntube/settings.py

You probably want to set Debug to True and you will need to edit your virtualenv path (In my case /Users/pbrechler/Desktop/OwnTube/.venv) and the STATIC_ROOT and TEMPLATE_DIRS settings accordantly. Most important: Change your SECRET_KEY to something unique and random (maybe you want to use something like pwgen 128 1)

Initialize your database

To get the data structure into your new database (a sqlitefile in our case) you need to run

python manage.py syncdb
python manage.py migrate

This should ask you for your admin crendentials (if you answer 'yes' (you should)) and then migrate all database settings.

Run your test server

Now you can run a local test server with the command

python manage.py runserver

ffmpeg

To run the transcoding yourself you would need to install ffmpeg, since it contains h.264 it is not redistributable and you need to compile it yourself. There is a rather good guide here.

Deployment

Of course the runserver command is not mend for deployment. To deploy the service I recommend using an Apache2 web server with mod_wsgi. To do so you will also need to install the wsgiref for Python. There is a wsgi file in the apache directory. This is an example for a apache2 config file:

 <VirtualHost owntube.example.com:80>
        ServerName owntube.pltzchn.de
    WSGIDaemonProcess owntube-wsgi user=www-data processes=2 maximum-requests=500 threads=1
        WSGIScriptAlias / /opt/OwnTube/apache/django.wsgi
        Alias /static /opt/OwnTube/static_files
    Alias /media /opt/OwnTube/media

        <Directory />
                AllowOverride None
        </Directory>

        <Directory /opt/OwnTube/>

                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        <Directory /opt/OwnTube/static_folder>
                Order deny,allow
                Allow from all
        </Directory>

        ErrorLog /var/log/apache2/error_owntube.log
        LogLevel debug
    CustomLog /var/log/apache2/access_owntube.log combine
</VirtualHost>

To deploy OwnTube you need to run the commands above but you shuld enter a MySQL or PostgreSQL Server in your settings file. For this you will need to install the mysql egg for python (or PostgreSQL), on Debian or Ubuntu this is made by:

apt-get install python-mysqldb
pip install MySQL-python

Please note that there was an reported issue with Mysql's transaction management and django-tasks see To avoid that issue change the Transaction Isolation Level in your DATABASES configuration.

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        ...
        'OPTIONS': { "init_command": "SET storage_engine=INNODB, SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED", }  
    }
}

Before you can run your Apache Server you will need to run the collectstatic command

python manage.py collectstatic

Tasks

Django tasks needs a deamon to run which is then used to execute the python commands. The Problem there is, that this user needs to be the web server user (so in the Debian case thats www-data). To do so:

sudo su www-data
cd /path/to/owntube
source .venv/bin/activate
python manage.py taskd start
exit

Please note that the user that runs this commands needs to have the right to write to /tmp for logging