Thursday, May 3, 2012

Graphite In A virtualenv In A Jail

I am attempting to put Graphite in a virtualenv in a FreeBSD 8.2 jail. It is not that straight-forward. However, I have things working!

Follow for more.

Tricky Prerequisites

I found that I did not have sqlite3 installed and pip was not being nice about it. So, here are the steps that finally got it working for me. I had to install it on the host machine and then link the library to the virtual environment.

EDIT: By using the --system-site-packages option, the sqlite3 and cairo steps change dramatically. I kept the original steps in tact, just in case.

With --system-site-packages

$ sudo portmaster databases/py-sqlite3 graphics/py-cairo
$ virtualenv --system-site-packages --distribute graphite
$ cd graphite
$ source bin/activate

Without

$ sudo portmaster databases/py-sqlite3
$ virtualenv --distribute graphite
$ ln -s /usr/local/lib/python2.7/site-packages/_sqlite3.so graphite/lib/python2.7/
$ cd graphite

That should do it for sqlite3. Now, let's talk about cairo. At some point, it seems, cairo split its packages based on the version of Python (2 vs 3). pip will grab the Python 3 version. Because of this, version 1.8.8 must be used to get pycairo to install properly. However, I still had problems and ended up installing it on the host system and copying files around.

$ sudo portmaster graphics/py-cairo
$ source bin/activate
$ pip install pycairo=1.8.8
$ cp /usr/local/lib/python2.7/site-packages/cairo/{__init__.py, _cairo.la} lib/python2.7/site-packages/cairo/

Simple Pieces

Django and whisper.

$ pip install django tagging django-tagging Twisted gunicorn whisper

Break Out The Editor

Things are going to break. The reason is that Graphite expects and wants to install into /opt/graphite. However, I am just as stubborn and would like to make this as unprivileged as possible. This path is hardcoded in the setup.py file for both carbon and graphite-web. The solution is to edit this file and then re-run the install process.

$ pip install carbon
$ vi build/carbon/setup.py
( change prefix, example: '/home/someuser/devel/graphite/' )
$ pip install carbon --no-download
$ cp conf/carbon.conf.example conf/carbon.conf
$ cp conf/storage-schemas.conf.example conf/storage-schemas.conf
$ pip install graphite-web
$ vi build/graphite-web/setup.py
$ pip install graphite-web --no-download

Do not look at pip freeze. It never looks right at this point. At least, not for me.

Configuration settings. Recommendation from Graphite is to just monkey with the local_settings.py file.

$ cd webapp/graphite
$ cp local_settings.py.example local_settings.py
$ vi local_settings.py

Unfortunately, I could not find a way to get DATABASES to work without modifying settings.py. First, I added DATABASES to the top and set it to None. Then I added a section at the bottom, after it imports local_settings, to translate DATABASE_* variables into the DATABASES format. This allows me to change options in local_settings just fine.

$ vi settings.py

DATABASES = None
...
if not DATABASES:
  DATABASES = {
    'default': {
      'NAME': DATABASE_NAME,
      'ENGINE': DATABASE_ENGINE,
      'USER': DATABASE_USER,
      'PASSWORD': DATABASE_PASSWORD,
      'HOST': DATABASE_HOST,
      'PORT': DATABASE_PORT,
  }
}

There is a chance that the next command will blow-up due to a locale function. Please read the locale documentation and "Using Localization" in FreeBSD handbook. I added the environment variable LANG to the bin/activate script and was able to continue after re-activating.

Almost done! Create database and super user. If the super user fails, check manage.py for how to create it again.

$ python manage.py syncdb

Run the development server.

$ cd ../..
$ bin/run-graphite-devel-server.py --libs=`pwd`/webapp/ .

Point a web browser to the URL provided from the step above.

1 comment:

  1. For cairo, I thin you can do:

    wget http://cairographics.org/releases/py2cairo-1.10.0.tar.bz2
    tar xvjf py2cairo-1.10.0.tar.bz2 && cd py2cairo-1.10.0
    ./waf configure --prefix=/path/to/virtualenv
    ./waf build
    ./waf install

    It worked for me in a virtualenv on Ubuntu.

    ReplyDelete