A more comprehensive (but not always up to date!) install guide can be found at
http://en.flossmanuals.net/Plumi/Introduction


Before you start
================

 * install gcc/g++ dev tools
    e.g. sudo apt-get install build-essential pkg-config
 * install git
    e.g. sudo apt-get install git-core
 * install python and header files (tested with python 2.6 and 2.7)
    e.g. sudo apt-get install python-dev
 * install libjpeg, zlib, libpcre, libxslt header files
    e.g. sudo apt-get install libjpeg62-dev zlib1g-dev, libxslt1-dev
    or for Ubuntu 11.04 jpeg support: sudo apt-get install libjpeg8-dev
    for png support in Ubuntu 11.04 you may have to install zlib from source
 * install groff-base
    e.g. sudo apt-get install groff-base


Creating a Python Virtual Environment
=====================================
If you are running other applications and web sites on your server, 
it may be worth while creating a python virtual environment for developing
in - this can avoid problems between python packages installed by your 
operating system and those installed by easy_install. 
You will need to have the virtualenv package installed first - in Debian and
Ubuntu systems you can apt-get install python-virtualenv, then:

  virtualenv -p /usr/bin/python --no-site-packages pyvirt
  . pyvirt/bin/activate
  easy_install http://dist.repoze.org/PIL-1.1.6.tar.gz

This will install the virtual env into pyvirt, activate it and then 
install the (required) Python Imaging Library into the virtual env.


Initial configuration
======================
This step is optional for testing/development builds. However, even in those 
cases you may wish to customize some of the options inside site.cfg, especially 
if ports 8080, 8888, 8021, 8000, 8100 or 8890 are already used by other apps in 
your system. 

If you're deploying for production you should have 2 different hostnames 
available, one for your Plumi site (e.g. new.plumi.org) and another for the 
transcoder/videoserver (e.g.newvideos.plumi.org), both pointing to your public 
ip address. You could also install the transcoding server in a different 
machine or even have multiple transcoding servers with load balancing, but this 
setup will not be covered in this guide. Please ensure that these hostnames are 
set up in advance of your site installation and have had sufficient time to 
propagate through the Internet (eg: 24-48 hours). If you server is not going to 
be accessed from the Internet, you still need to set up the domains within your 
private network (eg: internal DNS server, /etc/hosts files on all workstations, 
etc).

Before running buildout, you should customize the options inside site.cfg. 
At the very least you should change the following:

  * secret: a shared secret key for encrypted communication between Plumi and
      transcodedaemon. Just enter a random string of 4, 8, 16 or 32 characters.
  * www-server-name: the hostname of your Plumi site (e.g. www.engagemedia.org)
  * www-videoserver-name: the hostname of your transcoder & videoserver
      (e.g. videos.engagemedia.org)

If you decided not to change the default user for zope, zeo and transcode in 
site.cfg make sure that it exists in your system. If not, add it:

   sudo useradd zope
   

Install Plumi 4.x 
=================

Once you're ready with the initial configuration execute the following two 
commands. Do it as your regular user for testing/dev builds but make sure you 
are root for production builds:

  cd ffmpeg
  python bootstrap.py
  ./bin/buildout

After the ffmpeg buildout is finished you should run the plumi buildout:

  cd ..
  python bootstrap.py 
  ./bin/buildout

That should take some time, so feel free to get some cofee or fresh air while
buildout is downloading, compiling and installing dependencies (Zope, Plone,
ffmpeg, etc). If all goes well your Plumi instance will be ready after that
point.


Running Plumi 4.x 
==================

Supervisor will be managing the internal ZEO server, the transcodedaemon, 
the async worker instance, the varnish cache server, the uwsgi WSGI web 
server, as well as the externally facing ploneFTP server and the nginx web 
server in production builds.

Start supervisor like this:

  ./bin/supervisord

Confirm that zeo, uwsgi and transcodedaemon are up and running:

  ./bin/supevisorctl status
  
If you ran buildout as a regular (non root) user and you did not change the 
default ports for nginx and ploneftp in site.cfg (www-address & plumiftp-address 
respectively) you'll see that both ploneftp and nginx failed to start because
you don't have permission to bind on to the priviledged ports 80 and 21. 
Nothing to worry about if you're just evaluating Plumi, you can still use it
without nginx. Just go to port 8000 on localhost to access directly the uwsgi
web server. 

Run the plumisite command to create a new Plumi site

  ./bin/plumisite
  
Alternatively, if you can create the Plumi site through the web, using the ZMI. 

After that step you're ready to roll! Your new Plumi site will be available
at http://localhost:8000/Plone or at http://{www-server-name} for production
builds.

If you want to do some development, you can use Paster instead of uwsgi 
since the latter is more suited for production. Stop uwsgi and start paster 
as shown below:

  ./bin/supervisorctl stop uwsgi

  ./bin/paster serve development.ini --reload 

The --reload option will consume more resources but it's very handy for dev
since it will automatically reload any python modules that you edit.

If you have changed the default port, hostname, or the secret encryption key
for the transcode daemon in site.cfg, you should go to the transcode settings
panel (e.g. http://localhost:8000/Plone/@@transcode-controlpanel ) and enter
the same host, port and key there.

Add a new user to your Plumi site for testing and start publishing videos!


In order to shutdown all Plumi related services, use the following command:

  ./bin/supervisorctl shutdown

If you want to ensure that Plumi will start automatically whenever your server
is turned on, add the following lines to your /etc/rc.local file replacing
PATH_TO_PLUMI with the actual absolute path of your plumi setup:

  PATH_TO_PLUMI/bin/supervisord


Configuring Video statistics
=========================================
To record and show video views and downloads you'll need a working Piwik
installation. Add the tracking tag in Site-Setup->Site and fill the form in
Site-Setup-> Piwik Settings with the piwik url, the site id on piwik and the
api key (if you have anonymous access on piwik for your site you can leave
anonymous instead of the API key).


Configuring subtitles and downloads
==========================================
By default, subtitle support through Universal Subtitles is enabled. You can 
disable it through Site Setup->Transcode Settings. You can also disable 
downloads through embedded videos there.
