2012-04-12 08:17:43 by jdixon
If you're not already aware, Graphite uses Django as the web framework for its underpinnings. In particular, it relies on Django for all user administration, authentication and authorization facilities. This is convenient for Graphite developers, but can be rather inconvenient for Graphite administrators with little-to-no Django experience.
One of my earliest headaches with automating Graphite installations was trying to workaround the interactive manage.py syncdb step from the installation doc. This is usually something everyone wants to run, since it performs the initial admin user creation.
After digging through the painfully thorough Django documentation I discovered that you can bootstrap the Graphite database with an "initial data" json fixture and running syncdb with the --noinput option.
$ cd /opt/graphite/webapp/graphite $ sudo cp /path/to/initial_data.json . $ sudo python manage.py syncdb --noinput
Of course, this assumes you have the fixture blob available. This can be obtained from an existing Graphite installation with the manage.py dumpdata command.
[ Bonus Tip: use this technique to automate logical backups of your Graphite database. ]
$ cd /opt/graphite/webapp/graphite $ sudo python manage.py dumpdata > /tmp/django-dump.json
Our Chef cookbook ends up containing a few blocks to automate this process, looking something like this:
template "/opt/graphite/webapp/graphite/initial_data.json" do source "initial_data.json.erb" owner "www-data" group "www-data" mode "0644" end execute "syncdb" do cwd "/opt/graphite/webapp/graphite" command "python manage.py syncdb --noinput" end file "/data/db/graphite.db" do owner "www-data" group "www-data" mode "0644" end