diff --git a/Modulefile b/Modulefile index 3579cc5..d7e4954 100644 --- a/Modulefile +++ b/Modulefile @@ -5,4 +5,6 @@ license 'MIT' summary 'Module to manage the Graphite monitoring tool' source 'https://github.com/gds-operations/puppet-graphite' project_page 'https://github.com/gds-operations/puppet-graphite' + dependency 'puppetlabs/stdlib', '>= 2.5.0' +dependency 'stankevich/python', '>= 1.2.0' diff --git a/README.md b/README.md index 15274e7..32a9bab 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,23 @@ Status](https://secure.travis-ci.org/gds-operations/puppet-graphite.png)](http:/ # Usage -Nice and simple, mainly because it's not yet very configurable. +You will need Python, Python's development headers/libs, pip and virtualenv +installed. If you're not already managing these you can use the `python` +module, which is included as a dependency: - include graphite +```puppet +class { 'python': + pip => true, + dev => true, + virtualenv => true, +} +``` + +Then for the simplest possible configuration: + +```puppet +include graphite +``` ## Configuration diff --git a/Vagrantfile b/Vagrantfile index e677c74..d80494a 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -9,9 +9,19 @@ DEBIAN_FRONTEND=noninteractive apt-get -qy update if [ ! -e /etc/puppet/modules/stdlib ]; then puppet module install puppetlabs-stdlib --modulepath /etc/puppet/modules fi +if [ ! -e /etc/puppet/modules/python ]; then + puppet module install stankevich-python --modulepath /etc/puppet/modules +fi puppet apply --verbose -e "node default { \ - class { 'graphite': root_dir => '/var/lib/graphite' } \ + class { 'python': \ + pip => true, \ + dev => true, \ + virtualenv => true, \ + } \ + class { 'graphite': \ + root_dir => '/var/lib/graphite', \ + } \ }" EOM diff --git a/manifests/config.pp b/manifests/config.pp index 19d7868..b52b083 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -100,7 +100,7 @@ } exec { 'init-db': - command => '/usr/bin/python manage.py syncdb --noinput', + command => "${root_dir}/bin/python manage.py syncdb --noinput", cwd => "${root_dir}/webapp/graphite", creates => "${root_dir}/storage/graphite.db", subscribe => File["${root_dir}/storage"], diff --git a/manifests/deps.pp b/manifests/deps.pp index ec91bbc..dae2a4b 100644 --- a/manifests/deps.pp +++ b/manifests/deps.pp @@ -1,21 +1,36 @@ # == Class: graphite::deps # -# Class to install all graphite dependency packages +# Class to create a Python virtualenv and install all graphite dependencies +# within that sandbox. +# +# With the exception of pycairo which can't be installed by pip. It is +# installed as a system package and symlinked into the virtualenv. This is a +# slightly hacky alternative to `--system-site-packages` which would mess +# with Graphite's other dependencies. # class graphite::deps { + $root_dir = $::graphite::root_dir - ensure_packages([ - 'python-ldap', - 'python-cairo', - 'python-django', - 'python-twisted', - 'python-django-tagging', - 'python-simplejson', - 'python-memcache', - 'python-pysqlite2', - 'python-support', - 'python-pip', + python::virtualenv { $root_dir: } -> + python::pip { [ 'gunicorn', - ]) + 'twisted==11.1.0', + 'django==1.4.10', + 'django-tagging==0.3.1', + 'python-memcached==1.47', + 'simplejson==2.1.6', + ]: + virtualenv => $root_dir, + } + + ensure_packages(['python-cairo']) + file { "${root_dir}/lib/python2.7/site-packages/cairo": + ensure => link, + target => '/usr/lib/python2.7/dist-packages/cairo', + require => [ + Python::Virtualenv[$root_dir], + Package['python-cairo'], + ], + } } diff --git a/manifests/install.pp b/manifests/install.pp index eef8554..f2ec8e6 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -6,37 +6,12 @@ $root_dir = $::graphite::root_dir $ver = $::graphite::version - package { 'whisper': - ensure => $ver, - provider => pip, - } - - $carbon_pip_args = [ - "--install-option=\"--prefix=${root_dir}\"", - "--install-option=\"--install-lib=${root_dir}/lib\"", - ] - $carbon_args = join($carbon_pip_args, ' ') - - exec { 'graphite/install carbon': - command => "/usr/bin/pip install ${carbon_args} carbon==${ver}", - creates => "${root_dir}/bin/carbon-cache.py", - } - - $graphite_pip_args = [ - "--install-option=\"--prefix=${root_dir}\"", - "--install-option=\"--install-lib=${root_dir}/webapp\"" - ] - $graphite_web_args = join($graphite_pip_args, ' ') - - exec { 'graphite/install graphite-web': - command => "/usr/bin/pip install ${graphite_web_args} graphite-web==${ver}", - creates => "${root_dir}/webapp/graphite/manage.py", - } - - file { '/var/log/carbon': - ensure => directory, - owner => www-data, - group => www-data, + python::pip { [ + "whisper==${ver}", + "carbon==${ver}", + "graphite-web==${ver}" + ]: + virtualenv => $root_dir, } } diff --git a/templates/upstart/carbon-cache.conf b/templates/upstart/carbon-cache.conf index 2322b2d..563870e 100755 --- a/templates/upstart/carbon-cache.conf +++ b/templates/upstart/carbon-cache.conf @@ -12,4 +12,4 @@ pre-start exec rm -f '<%= @root_dir %>'/storage/carbon-cache.pid chdir '<%= @root_dir %>' env GRAPHITE_STORAGE_DIR='<%= @root_dir %>/storage' env GRAPHITE_CONF_DIR='<%= @root_dir %>/conf' -exec python '<%= @root_dir %>/bin/carbon-cache.py' --debug start +exec <%= @root_dir %>/bin/carbon-cache.py --debug start diff --git a/templates/upstart/graphite-web.conf b/templates/upstart/graphite-web.conf index 7793902..eef28f2 100644 --- a/templates/upstart/graphite-web.conf +++ b/templates/upstart/graphite-web.conf @@ -11,4 +11,4 @@ chdir '<%= @root_dir %>/webapp' env PYTHONPATH='<%= @root_dir %>/webapp' env GRAPHITE_STORAGE_DIR='<%= @root_dir %>/storage' env GRAPHITE_CONF_DIR='<%= @root_dir %>/conf' -exec /usr/bin/gunicorn_django -b127.0.0.1:<%= @port %> -w2 graphite/settings.py +exec <%= @root_dir %>/bin/gunicorn_django -b127.0.0.1:<%= @port %> -w2 graphite/settings.py