Unhelpful Graphite Tip #4 - Bootstrap the Django DB

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

Comments

at 2012-07-16 22:00:25, bwhaley wrote in to say...

Nice. My puppet version looks like this

exec {

'syncdb':

command => '/usr/bin/python /opt/graphite/webapp/graphite/manage.py syncdb --noinput',

unless => '/usr/bin/python /opt/graphite/webapp/graphite/manage.py inspectdb | grep account_mygraph',

require => Package['graphite-web'],

;

}

at 2014-01-16 10:58:26, James wrote in to say...

Just wanted to thank you for the post about --noinput. Trying to automate a graphite install using Ansible, and the initial DB creation step was a major roadblack for me! This post helped immensely. So thanks!

at 2015-01-07 05:37:11, Mariiusz wrote in to say...

You may setup password:

echo "from django.contrib.auth.models import User; User.objects.create_superuser('admin', '[email protected]', 'pass')" | python manage.py shell

at 2015-06-09 12:36:15, guillaume wrote in to say...

amazing. Thank you.

at 2015-07-08 07:58:01, Vinayak wrote in to say...

This post was of tremendous help! Thank you so much!

at 2017-03-31 21:36:33, tschaller wrote in to say...

THIS!

Thank you so much. You need a "Buy me a beer." button. :)

Add a comment:

  name

  email

  url

max length 4000 chars