diff --git a/CONTRIBUTORS b/CONTRIBUTORS new file mode 100644 index 0000000..2923155 --- /dev/null +++ b/CONTRIBUTORS @@ -0,0 +1,12 @@ +Gareth Rushgrove +Philip Potter +Nick Stenning +Bob Walker +Garima Singh +Dan Carley +Neil Houston +Nick Osborn +Sam J Sharpe +Kushal Pisavadia +Matt Bostock +Simon Croome \ No newline at end of file diff --git a/README.md b/README.md index 48bbb86..049d4b5 100644 --- a/README.md +++ b/README.md @@ -56,5 +56,5 @@ the other puppet modules I found either lacked support for Ubuntu/Debian, relied on an undocumented package or did a lot of wgetting. -Although I've only tested this module on Ubuntu it should work on other -distros too, maybe with minor tweaks. +Tested on Ubuntu and CentOS 7, though other RHEL variants including < 7.x +and Fedora should work (bug reports welcome). diff --git a/manifests/config.pp b/manifests/config.pp index c93ff37..443e138 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -8,6 +8,9 @@ $bind_address = $::graphite::bind_address $port = $::graphite::port $root_dir = $::graphite::root_dir + $user = $graphite::user + $init_style = $graphite::params::init_style + $sysconfig = $graphite::params::sysconfig if ($::graphite::aggregation_rules_source == undef and $::graphite::aggregation_rules_content == undef) { @@ -43,32 +46,96 @@ $carbon_content = $::graphite::carbon_content } - file { - [ - '/etc/init.d/carbon-aggregator', - '/etc/init.d/carbon-cache', - '/etc/init.d/graphite-web' - ]: - ensure => link, - target => '/lib/init/upstart-job', - } - - file { '/etc/init/carbon-aggregator.conf': - ensure => present, - content => template('graphite/upstart/carbon-aggregator.conf'), - mode => '0555', - } + # Environment variables kept centrally, will also work for Debian + # by reworking upstart scripts to remove 'env' entries and add: + # pre-start script + # [ -f <%= @sysconfig %>/carbon-aggregator ] && \ + # . <%= @sysconfig %>/carbon-aggregator + # end script + if $::osfamily == 'RedHat' { + file { "${sysconfig}/carbon-aggregator": + ensure => present, + content => template('graphite/sysconfig/carbon-aggregator'), + mode => '0644', + } + file { "${sysconfig}/carbon-cache": + ensure => present, + content => template('graphite/sysconfig/carbon-cache'), + mode => '0644', + } + file { "${sysconfig}/graphite-web": + ensure => present, + content => template('graphite/sysconfig/graphite-web'), + mode => '0644', + } + } + + case $init_style { + + 'upstart': { + file { + [ + '/etc/init.d/carbon-aggregator', + '/etc/init.d/carbon-cache', + '/etc/init.d/graphite-web' + ]: + ensure => link, + target => '/lib/init/upstart-job', + } + + file { '/etc/init/carbon-aggregator.conf': + ensure => present, + content => template('graphite/upstart/carbon-aggregator.conf'), + mode => '0555', + } + + file { '/etc/init/carbon-cache.conf': + ensure => present, + content => template('graphite/upstart/carbon-cache.conf'), + mode => '0555', + } + + file { '/etc/init/graphite-web.conf': + ensure => present, + content => template('graphite/upstart/graphite-web.conf'), + mode => '0555', + } + } + 'systemd' : { + file { '/lib/systemd/system/carbon-aggregator.service': + ensure => present, + content => template('graphite/systemd/carbon-aggregator.service'), + mode => '0644', + } + file { '/lib/systemd/system/carbon-cache.service': + ensure => present, + content => template('graphite/systemd/carbon-cache.service'), + mode => '0644', + } + file { '/lib/systemd/system/graphite-web.service': + ensure => present, + content => template('graphite/systemd/graphite-web.service'), + mode => '0644', + } + } + 'init', default : { + file { '/etc/init.d/carbon-aggregator': + ensure => present, + content => template('graphite/init/carbon-aggregator'), + mode => '0755', + } + file { '/etc/init.d/carbon-cache': + ensure => present, + content => template('graphite/init/carbon-cache'), + mode => '0755', + } + file { '/etc/init.d/graphite-web': + ensure => present, + content => template('graphite/init/graphite-web'), + mode => '0755', + } + } - file { '/etc/init/carbon-cache.conf': - ensure => present, - content => template('graphite/upstart/carbon-cache.conf'), - mode => '0555', - } - - file { '/etc/init/graphite-web.conf': - ensure => present, - content => template('graphite/upstart/graphite-web.conf'), - mode => '0555', } file { "${root_dir}/conf/carbon.conf": @@ -96,7 +163,7 @@ } file { ["${root_dir}/storage", "${root_dir}/storage/whisper"]: - owner => 'www-data', + owner => $user, mode => '0775', } @@ -115,14 +182,14 @@ } file { "${root_dir}/storage/graphite.db": - owner => 'www-data', + owner => $user, mode => '0664', subscribe => Exec['init-db'], } file { "${root_dir}/storage/log/webapp/": ensure => 'directory', - owner => 'www-data', + owner => $user, mode => '0775', } diff --git a/manifests/deps.pp b/manifests/deps.pp index dae2a4b..9f350d9 100644 --- a/manifests/deps.pp +++ b/manifests/deps.pp @@ -9,7 +9,9 @@ # with Graphite's other dependencies. # class graphite::deps { - $root_dir = $::graphite::root_dir + $root_dir = $::graphite::root_dir + $packages = $::graphite::packages + $cairo_target = $::graphite::cairo_target python::virtualenv { $root_dir: } -> python::pip { [ @@ -23,14 +25,14 @@ virtualenv => $root_dir, } - ensure_packages(['python-cairo']) + ensure_packages($packages) file { "${root_dir}/lib/python2.7/site-packages/cairo": ensure => link, - target => '/usr/lib/python2.7/dist-packages/cairo', + target => $cairo_target, require => [ Python::Virtualenv[$root_dir], - Package['python-cairo'], + Package[$packages], ], } } diff --git a/manifests/init.pp b/manifests/init.pp index 11df9fc..2f7f62e 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -20,6 +20,10 @@ # Where to install Graphite. # Default: /opt/graphite # +# [*user*] +# User the graphite-web user interface runs as. +# Default: www-data for Debian-based, root for RedHat-based systems. +# # [*carbon_aggregator*] # Optional: Boolean, whether to run carbon-aggregator. You will need to # provide an appropriate `carbon_content` or `carbon_source` config. @@ -53,6 +57,7 @@ $bind_address = $graphite::params::bind_address, $port = $graphite::params::port, $root_dir = $graphite::params::root_dir, + $user = $graphite::params::user, $carbon_aggregator = false, $aggregation_rules_content = undef, $aggregation_rules_source = undef, diff --git a/manifests/params.pp b/manifests/params.pp index 9615ccf..22c3bfa 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -4,8 +4,38 @@ # class graphite::params { $admin_password = 'sha1$1b11b$edeb0a67a9622f1f2cfeabf9188a711f5ac7d236' - $bind_address = '127.0.0.1' - $port = 8000 - $root_dir = '/opt/graphite' - $version = '0.9.12' + $bind_address = '127.0.0.1' + $port = 8000 + $root_dir = '/opt/graphite' + $version = '0.9.12' + + case $::osfamily { + 'Debian': { + $user = 'www-data' + $sysconfig = '/etc/default' + $packages = ['python-cairo'] + $cairo_target = '/usr/lib/python2.7/dist-packages/cairo' + $init_style = 'upstart' + } + 'RedHat': { + $user = 'root' + $sysconfig = '/etc/sysconfig' + $packages = ['pycairo'] + $cairo_target = '/usr/lib64/python2.7/site-packages/cairo' + + if ($::operatingsystem != 'Fedora' + and versioncmp($::operatingsystemrelease, '7') >= 0) + or ($::operatingsystem == 'Fedora' + and versioncmp($::operatingsystemrelease, '15') >= 0) { + $init_style = 'systemd' + } + else { + $init_style = 'init' + } + } + default: { + fail("${module_name} not supported on an ${::osfamily} based system.") + } + } + } diff --git a/manifests/service.pp b/manifests/service.pp index e6eb42f..e833559 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -12,19 +12,19 @@ ensure => $aggregator_ensure, hasstatus => true, hasrestart => true, - provider => upstart, + provider => $::graphite::params::init_style, } -> service { 'carbon-cache': ensure => running, hasstatus => true, hasrestart => true, - provider => upstart, + provider => $::graphite::params::init_style, } service { 'graphite-web': ensure => running, hasstatus => true, hasrestart => true, - provider => upstart, + provider => $::graphite::params::init_style, } } diff --git a/spec/classes/graphite/graphite__config_spec.rb b/spec/classes/graphite/graphite__config_spec.rb index a595569..b8955e0 100644 --- a/spec/classes/graphite/graphite__config_spec.rb +++ b/spec/classes/graphite/graphite__config_spec.rb @@ -1,132 +1,470 @@ require 'spec_helper' describe 'graphite', :type => :class do - it { should contain_file('/etc/init.d/carbon-aggregator').with_ensure('link'). - with_target('/lib/init/upstart-job') } - it { should contain_file('/etc/init.d/carbon-cache').with_ensure('link'). - with_target('/lib/init/upstart-job') } - it { should contain_file('/etc/init.d/graphite-web').with_ensure('link'). - with_target('/lib/init/upstart-job') } - - it { should contain_file('/opt/graphite/storage').with_owner('www-data'). - with_mode('0775') } - it { should contain_file('/opt/graphite/storage/whisper'). - with_owner('www-data').with_mode('0775') } - - context "root_dir" do - let(:params) {{ :root_dir => '/this/is/root' }} - describe "intial_data.json" do - it { should contain_file('/this/is/root/webapp/graphite/initial_data.json') } + describe "start scripts" do + context "debian upstart" do + let(:facts) {{ :osfamily => 'Debian' }} + it { should contain_file('/etc/init.d/carbon-aggregator').with_ensure('link'). + with_target('/lib/init/upstart-job') } + it { should contain_file('/etc/init.d/carbon-cache').with_ensure('link'). + with_target('/lib/init/upstart-job') } + it { should contain_file('/etc/init.d/graphite-web').with_ensure('link'). + with_target('/lib/init/upstart-job') } end - describe "carbon-aggregator.conf" do - it { should contain_file('/etc/init/carbon-aggregator.conf').with_ensure('present'). - with_content(/chdir '\/this\/is\/root'/). - with_content(/GRAPHITE_STORAGE_DIR='\/this\/is\/root\/storage'/). - with_content(/GRAPHITE_CONF_DIR='\/this\/is\/root\/conf'/). - with_content(/exec \/this\/is\/root\/bin\/carbon-aggregator.py/). - with_mode('0555') } + context "fedora init" do + let(:facts) {{ + :osfamily => 'RedHat', + :operatingsystem => 'Fedora', + :operatingsystemrelease => '14' + }} + it { should contain_file('/etc/init.d/carbon-aggregator') } + it { should contain_file('/etc/init.d/carbon-cache') } + it { should contain_file('/etc/init.d/graphite-web') } end - describe "carbon-cache.conf" do - it { should contain_file('/etc/init/carbon-cache.conf').with_ensure('present'). - with_content(/chdir '\/this\/is\/root'/). - with_content(/GRAPHITE_STORAGE_DIR='\/this\/is\/root\/storage'/). - with_content(/GRAPHITE_CONF_DIR='\/this\/is\/root\/conf'/). - with_content(/exec \/this\/is\/root\/bin\/carbon-cache.py/). - with_mode('0555') } + context "fedora systemd" do + let(:facts) {{ + :osfamily => 'RedHat', + :operatingsystem => 'Fedora', + :operatingsystemrelease => '15' + }} + it { should contain_file('/lib/systemd/system/carbon-aggregator.service') } + it { should contain_file('/lib/systemd/system/carbon-cache.service') } + it { should contain_file('/lib/systemd/system/graphite-web.service') } end - describe "graphite-web.conf" do - it { should contain_file('/etc/init/graphite-web.conf').with_ensure('present'). - with_content(/chdir '\/this\/is\/root\/webapp'/). - with_content(/PYTHONPATH='\/this\/is\/root\/webapp'/). - with_content(/GRAPHITE_STORAGE_DIR='\/this\/is\/root\/storage'/). - with_content(/GRAPHITE_CONF_DIR='\/this\/is\/root\/conf'/). - with_content(/-b127\.0\.0\.1:8000/). - with_mode('0555') } + context "redhat init" do + let(:facts) {{ + :osfamily => 'RedHat', + :operatingsystem => 'RedHat', + :operatingsystemrelease => '6' + }} + it { should contain_file('/etc/init.d/carbon-aggregator') } + it { should contain_file('/etc/init.d/carbon-cache') } + it { should contain_file('/etc/init.d/graphite-web') } end - describe "carbon.conf" do - it { should contain_file('/this/is/root/conf/carbon.conf'). - with_content(/LOCAL_DATA_DIR = \/this\/is\/root\/storage\/whisper\//) } + context "redhat systemd" do + let(:facts) {{ + :osfamily => 'RedHat', + :operatingsystem => 'RedHat', + :operatingsystemrelease => '7' + }} + it { should contain_file('/lib/systemd/system/carbon-aggregator.service') } + it { should contain_file('/lib/systemd/system/carbon-cache.service') } + it { should contain_file('/lib/systemd/system/graphite-web.service') } end - end - context "carbon_content" do - let(:params) {{ :root_dir => '/this/is/root', :carbon_content => 'SOMEVAR=SOMECONTENT' }} + context "centos init" do + let(:facts) {{ + :osfamily => 'RedHat', + :operatingsystem => 'Centos', + :operatingsystemrelease => '6' + }} + it { should contain_file('/etc/init.d/carbon-aggregator') } + it { should contain_file('/etc/init.d/carbon-cache') } + it { should contain_file('/etc/init.d/graphite-web') } + end - context 'with configured carbon contents' do - it { should contain_file('/this/is/root/conf/carbon.conf').with_ensure('present'). - with_content(/SOMECONTENT/) } + context "centos systemd" do + let(:facts) {{ + :osfamily => 'RedHat', + :operatingsystem => 'Centos', + :operatingsystemrelease => '7' + }} + it { should contain_file('/lib/systemd/system/carbon-aggregator.service') } + it { should contain_file('/lib/systemd/system/carbon-cache.service') } + it { should contain_file('/lib/systemd/system/graphite-web.service') } end - end - describe "aggregation-rules.conf" do - context 'with unconfigured aggregation rules' do - it { should contain_file('/opt/graphite/conf/aggregation-rules.conf'). - with_ensure('absent') } - it { should_not contain_file('/etc/init/carbon-aggregator.conf'). - with_content(/--rules/) } + context "redhat sysconfig" do + let(:facts) {{ + :osfamily => 'RedHat', + }} + it { should contain_file('/etc/sysconfig/carbon-aggregator') } + it { should contain_file('/etc/sysconfig/carbon-cache') } + it { should contain_file('/etc/sysconfig/graphite-web') } end - context 'with configured aggregation rules' do - let(:params) { {'aggregation_rules_content' => "Elephants and giraffes!" } } - it { should contain_file('/opt/graphite/conf/aggregation-rules.conf'). - with_content("Elephants and giraffes!") } - it { should contain_file('/etc/init/carbon-aggregator.conf'). - with_content(/--rules='\/opt\/graphite\/conf\/aggregation-rules\.conf'/) } + context "debian upstart contents" do + let(:facts) {{ :osfamily => 'Debian' }} + let(:params) {{ :root_dir => '/this/is/root' }} + + describe "carbon-aggregator.conf" do + it { should contain_file('/etc/init/carbon-aggregator.conf').with_ensure('present'). + with_content(/chdir '\/this\/is\/root'/). + with_content(/GRAPHITE_STORAGE_DIR='\/this\/is\/root\/storage'/). + with_content(/GRAPHITE_CONF_DIR='\/this\/is\/root\/conf'/). + with_content(/exec \/this\/is\/root\/bin\/carbon-aggregator.py/). + with_mode('0555') } + end + + describe "carbon-cache.conf" do + it { should contain_file('/etc/init/carbon-cache.conf').with_ensure('present'). + with_content(/chdir '\/this\/is\/root'/). + with_content(/GRAPHITE_STORAGE_DIR='\/this\/is\/root\/storage'/). + with_content(/GRAPHITE_CONF_DIR='\/this\/is\/root\/conf'/). + with_content(/exec \/this\/is\/root\/bin\/carbon-cache.py/). + with_mode('0555') } + end + + describe "graphite-web.conf" do + it { should contain_file('/etc/init/graphite-web.conf').with_ensure('present'). + with_content(/chdir '\/this\/is\/root\/webapp'/). + with_content(/PYTHONPATH='\/this\/is\/root\/webapp'/). + with_content(/GRAPHITE_STORAGE_DIR='\/this\/is\/root\/storage'/). + with_content(/GRAPHITE_CONF_DIR='\/this\/is\/root\/conf'/). + with_content(/-b127\.0\.0\.1:8000/). + with_mode('0555') } + end end - end - describe "storage-aggregation.conf" do - context 'with unconfigured storage aggregation' do - it { should contain_file('/opt/graphite/conf/storage-aggregation.conf'). - with_source(/storage-aggregation\.conf/) } + describe "redhat init contents" do + let(:facts) {{ + :osfamily => 'RedHat', + :operatingsystem => 'RedHat', + :operatingsystemrelease => '6' + }} + let(:params) {{ :root_dir => '/this/is/root' }} + + describe "carbon-aggregator" do + it { should contain_file('/etc/init.d/carbon-aggregator').with_ensure('present'). + with_content(/^\. \/etc\/sysconfig\/carbon-aggregator/). + with_content(/^exec="\/this\/is\/root\/bin\/carbon-aggregator.py/). + with_mode('0755') } + end + + describe "carbon-cache" do + it { should contain_file('/etc/init.d/carbon-cache').with_ensure('present'). + with_content(/^\. \/etc\/sysconfig\/carbon-cache/). + with_content(/^exec="\/this\/is\/root\/bin\/carbon-cache.py/). + with_mode('0755') } + end + + describe "graphite-web" do + it { should contain_file('/etc/init.d/graphite-web').with_ensure('present'). + with_content(/^\. \/etc\/sysconfig\/graphite-web/). + with_content(/^DAEMON=\/this\/is\/root\/bin\/gunicorn_django/). + with_content(/^DAEMON_OPTS=\"-b 127\.0\.0\.1:8000/). + with_content(/^DAEMON_OPTS=\".*--daemon graphite\/settings.py\"/). + with_mode('0755') } + end end - context 'with configured storage aggregation' do - let(:params) { {'storage_aggregation_content' => "Elephants and giraffes!" } } - it { should contain_file('/opt/graphite/conf/storage-aggregation.conf'). - with_content("Elephants and giraffes!") } + context "redhat systemd contents" do + let(:facts) {{ + :osfamily => 'RedHat', + :operatingsystem => 'RedHat', + :operatingsystemrelease => '7' + }} + let(:params) {{ :root_dir => '/this/is/root' }} + + describe "carbon-aggregator.service" do + it { should contain_file('/lib/systemd/system/carbon-aggregator.service').with_ensure('present'). + with_content(/^EnvironmentFile=\/etc\/sysconfig\/carbon-aggregator/). + with_content(/^User=root/). + with_content(/^ExecStart=\/this\/is\/root\/bin\/carbon-aggregator.py/). + with_mode('0644') } + end + + describe "carbon-cache.service" do + it { should contain_file('/lib/systemd/system/carbon-cache.service').with_ensure('present'). + with_content(/^EnvironmentFile=\/etc\/sysconfig\/carbon-cache/). + with_content(/^User=root/). + with_content(/^ExecStart=\/this\/is\/root\/bin\/carbon-cache.py/). + with_mode('0644') } + end + + describe "graphite-web.service" do + it { should contain_file('/lib/systemd/system/graphite-web.service').with_ensure('present'). + with_content(/^EnvironmentFile=\/etc\/sysconfig\/graphite-web/). + with_content(/^User=root/). + with_content(/^ExecStart=\/this\/is\/root\/bin\/gunicorn_django -b 127\.0\.0\.1:8000 -w2/). + with_content(/^ExecStart=.* -w2 graphite\/settings.py/). + with_mode('0644') } + end + end + + context "redhat sysconfig contents" do + let(:facts) {{ :osfamily => 'RedHat' }} + let(:params) {{ :root_dir => '/this/is/root' }} + + describe "carbon-aggregator" do + it { should contain_file('/etc/sysconfig/carbon-aggregator').with_ensure('present'). + with_content(/^APP_ROOT="\/this\/is\/root\/webapp\/graphite"$/). + with_content(/^GRAPHITE_STORAGE_DIR="\/this\/is\/root\/storage"$/). + with_content(/^GRAPHITE_CONF_DIR="\/this\/is\/root\/conf"$/). + with_mode('0644') } + end + + describe "carbon-cache" do + it { should contain_file('/etc/sysconfig/carbon-cache').with_ensure('present'). + with_content(/^APP_ROOT="\/this\/is\/root\/webapp\/graphite"$/). + with_content(/^GRAPHITE_STORAGE_DIR="\/this\/is\/root\/storage"$/). + with_content(/^GRAPHITE_CONF_DIR="\/this\/is\/root\/conf"$/). + with_mode('0644') } + end + + describe "graphite-web" do + it { should contain_file('/etc/sysconfig/graphite-web').with_ensure('present'). + with_content(/^APP_ROOT="\/this\/is\/root\/webapp\/graphite"$/). + with_content(/^PYTHONPATH="\/this\/is\/root\/webapp"$/). + with_content(/^GRAPHITE_STORAGE_DIR="\/this\/is\/root\/storage"$/). + with_content(/^GRAPHITE_CONF_DIR="\/this\/is\/root\/conf"$/). + with_mode('0644') } + end end end - describe "storage-schemas" do - context 'with unconfigured storage schemas' do - it { should contain_file('/opt/graphite/conf/storage-schemas.conf'). - with_source(/storage-schemas\.conf/) } + describe "configuration" do + let(:params) {{ :root_dir => '/this/is/root' }} + describe "initial_data.json" do + context "debian" do + let(:facts) {{ :osfamily => 'Debian' }} + it { should contain_file('/this/is/root/webapp/graphite/initial_data.json') } + end + context "redhat" do + let(:facts) {{ :osfamily => 'RedHat' }} + it { should contain_file('/this/is/root/webapp/graphite/initial_data.json') } + end end - context 'with configured storage schemas' do - let(:params) { {'storage_schemas_content' => "Giraffes and elephants!" } } - it { should contain_file('/opt/graphite/conf/storage-schemas.conf'). - with_content("Giraffes and elephants!") } + describe "carbon.conf" do + context "debian" do + let(:facts) {{ :osfamily => 'Debian' }} + it { should contain_file('/this/is/root/conf/carbon.conf'). + with_content(/LOCAL_DATA_DIR = \/this\/is\/root\/storage\/whisper\//) } + end + context "redhat" do + let(:facts) {{ :osfamily => 'RedHat' }} + it { should contain_file('/this/is/root/conf/carbon.conf'). + with_content(/LOCAL_DATA_DIR = \/this\/is\/root\/storage\/whisper\//) } + end + end + + describe "carbon.conf carbon_content" do + let(:params) {{ :root_dir => '/this/is/root', :carbon_content => 'SOMEVAR=SOMECONTENT' }} + context "debian" do + let(:facts) {{ :osfamily => 'Debian' }} + it { should contain_file('/this/is/root/conf/carbon.conf').with_ensure('present'). + with_content(/SOMECONTENT/) } + end + context "redhat" do + let(:facts) {{ :osfamily => 'RedHat' }} + it { should contain_file('/this/is/root/conf/carbon.conf').with_ensure('present'). + with_content(/SOMECONTENT/) } + end + end + + describe "aggregation-rules.conf" do + context 'with unconfigured aggregation rules' do + context "debian" do + let(:facts) {{ :osfamily => 'Debian' }} + it { should contain_file('/this/is/root/conf/aggregation-rules.conf'). + with_ensure('absent') } + it { should_not contain_file('/etc/init/carbon-aggregator.conf'). + with_content(/--rules/) } + end + context "redhat" do + let(:facts) {{ :osfamily => 'RedHat' }} + it { should contain_file('/this/is/root/conf/aggregation-rules.conf'). + with_ensure('absent') } + it { should_not contain_file('/etc/init/carbon-aggregator.conf'). + with_content(/--rules/) } + end + end + context 'with configured aggregation rules' do + let(:params) {{ + :root_dir => '/this/is/root', + :aggregation_rules_content => "Elephants and giraffes!", + }} + context "debian" do + let(:facts) {{ :osfamily => 'Debian' }} + it { should contain_file('/this/is/root/conf/aggregation-rules.conf'). + with_content("Elephants and giraffes!") } + it { should contain_file('/etc/init/carbon-aggregator.conf'). + with_content(/--rules='\/this\/is\/root\/conf\/aggregation-rules\.conf'/) } + end + context "redhat" do + let(:facts) {{ :osfamily => 'RedHat' }} + it { should contain_file('/this/is/root/conf/aggregation-rules.conf'). + with_content("Elephants and giraffes!") } + context "init" do + let(:facts) {{ + :osfamily => 'RedHat', + :operatingsystem => 'RedHat', + :operatingsystemrelease => '6' + }} + it { should contain_file('/etc/init.d/carbon-aggregator'). + with_content(/--rules='\/this\/is\/root\/conf\/aggregation-rules\.conf'/) } + end + context "systemd" do + let(:facts) {{ + :osfamily => 'RedHat', + :operatingsystem => 'RedHat', + :operatingsystemrelease => '7' + }} + it { should contain_file('/lib/systemd/system/carbon-aggregator.service'). + with_content(/--rules='\/this\/is\/root\/conf\/aggregation-rules\.conf'/) } + end + end + end + end + + describe "storage-aggregation.conf" do + context 'with unconfigured storage aggregation' do + context "debian" do + let(:facts) {{ :osfamily => 'Debian' }} + it { should contain_file('/this/is/root/conf/storage-aggregation.conf'). + with_source(/storage-aggregation\.conf/) } + end + context "redhat" do + let(:facts) {{ :osfamily => 'RedHat' }} + it { should contain_file('/this/is/root/conf/storage-aggregation.conf'). + with_source(/storage-aggregation\.conf/) } + end + end + context 'with configured storage aggregation' do + let(:params) {{ + :root_dir => '/this/is/root', + :storage_aggregation_content => "Elephants and giraffes!", + }} + context "debian" do + let(:facts) {{ :osfamily => 'Debian' }} + it { should contain_file('/this/is/root/conf/storage-aggregation.conf'). + with_content("Elephants and giraffes!") } + end + context "redhat" do + let(:facts) {{ :osfamily => 'RedHat' }} + it { should contain_file('/this/is/root/conf/storage-aggregation.conf'). + with_content("Elephants and giraffes!") } + end + end + end + + describe "storage-schemas.conf" do + context 'with unconfigured storage schemas' do + context "debian" do + let(:facts) {{ :osfamily => 'Debian' }} + it { should contain_file('/this/is/root/conf/storage-schemas.conf'). + with_source(/storage-schemas\.conf/) } + end + context "redhat" do + let(:facts) {{ :osfamily => 'RedHat' }} + it { should contain_file('/this/is/root/conf/storage-schemas.conf'). + with_source(/storage-schemas\.conf/) } + end + end + context 'with configured storage schemas' do + let(:params) {{ + :root_dir => '/this/is/root', + :storage_schemas_content => "Elephants and giraffes!", + }} + context "debian" do + let(:facts) {{ :osfamily => 'Debian' }} + it { should contain_file('/this/is/root/conf/storage-schemas.conf'). + with_content("Elephants and giraffes!") } + end + context "redhat" do + let(:facts) {{ :osfamily => 'RedHat' }} + it { should contain_file('/this/is/root/conf/storage-schemas.conf'). + with_content("Elephants and giraffes!") } + end + end + end + + describe "initial_data.json" do + describe "admin password" do + let(:params) {{ + :root_dir => '/this/is/root', + :admin_password => "should be a hash", + }} + # let(:params) { {'admin_password' => 'should be a hash' }} + context "debian" do + let(:facts) {{ :osfamily => 'Debian' }} + it { should contain_file('/this/is/root/webapp/graphite/initial_data.json'). + with_content(/should be a hash/) } + end + context "redhat" do + let(:facts) {{ :osfamily => 'RedHat' }} + it { should contain_file('/this/is/root/webapp/graphite/initial_data.json'). + with_content(/should be a hash/) } + end + end + end + + describe "local_settings.py" do + context "debian" do + let(:facts) {{ :osfamily => 'Debian' }} + it { should contain_file('/this/is/root/webapp/graphite/local_settings.py'). + with_source('puppet:///modules/graphite/local_settings.py') } + end + context "redhat" do + let(:facts) {{ :osfamily => 'RedHat' }} + it { should contain_file('/this/is/root/webapp/graphite/local_settings.py'). + with_source('puppet:///modules/graphite/local_settings.py') } + end end - end - context 'with admin password' do - let(:params) { {'admin_password' => 'should be a hash' }} - it { should contain_file('/opt/graphite/webapp/graphite/initial_data.json').with_content(/should be a hash/) } end - it { - should contain_exec('init-db').with_command('/opt/graphite/bin/python manage.py syncdb --noinput'). - with_cwd('/opt/graphite/webapp/graphite') - } + describe "files" do + let(:params) {{ :root_dir => '/this/is/root' }} - it { - should contain_file('/opt/graphite/storage/graphite.db').with_owner('www-data') - } + describe "init-db" do + context "debian" do + let(:facts) {{ :osfamily => 'Debian' }} + it { should contain_exec('init-db'). + with_command('/this/is/root/bin/python manage.py syncdb --noinput'). + with_cwd('/this/is/root/webapp/graphite') } + end + context "redhat" do + let(:facts) {{ :osfamily => 'RedHat' }} + it { should contain_file('/this/is/root/webapp/graphite/local_settings.py'). + with_source('puppet:///modules/graphite/local_settings.py') } + end + end - it { - should contain_file('/opt/graphite/storage/log/webapp/').with_owner('www-data') - } + describe "storage" do + context "debian" do + let(:facts) {{ :osfamily => 'Debian' }} + it { should contain_file('/this/is/root/storage').with_owner('www-data'). + with_mode('0775') } + it { should contain_file('/this/is/root/storage/whisper'). + with_owner('www-data').with_mode('0775') } + end + context "redhat" do + let(:facts) {{ :osfamily => 'RedHat' }} + it { should contain_file('/this/is/root/storage').with_owner('root'). + with_mode('0775') } + it { should contain_file('/this/is/root/storage/whisper'). + with_owner('root').with_mode('0775') } + end + end + + describe "graphite-db" do + context "debian" do + let(:facts) {{ :osfamily => 'Debian' }} + it { should contain_file('/this/is/root/storage/graphite.db').with_owner('www-data') } + end + context "redhat" do + let(:facts) {{ :osfamily => 'RedHat' }} + it { should contain_file('/this/is/root/storage/graphite.db').with_owner('root') } + end + end - it { - should contain_file('/opt/graphite/webapp/graphite/local_settings.py'). - with_source('puppet:///modules/graphite/local_settings.py') - } + describe "logs" do + context "debian" do + let(:facts) {{ :osfamily => 'Debian' }} + it { should contain_file('/this/is/root/storage/log/webapp/').with_owner('www-data') } + end + context "redhat" do + let(:facts) {{ :osfamily => 'RedHat' }} + it { should contain_file('/this/is/root/storage/log/webapp/').with_owner('root') } + end + end + end end diff --git a/spec/classes/graphite/graphite__deps_spec.rb b/spec/classes/graphite/graphite__deps_spec.rb index 940cf18..10c30a4 100644 --- a/spec/classes/graphite/graphite__deps_spec.rb +++ b/spec/classes/graphite/graphite__deps_spec.rb @@ -1,19 +1,55 @@ require 'spec_helper' describe 'graphite', :type => :class do + let(:params) {{:root_dir => '/this/is/root'}} - context 'root_dir' do - let(:params) {{ - :root_dir => '/this/is/root', - }} + describe 'virtualenv root_dir' do + context 'debian' do + let(:facts) {{ :osfamily => 'Debian' }} + it { should contain_python__virtualenv('/this/is/root') } + end + context 'redhat' do + let(:facts) {{ :osfamily => 'RedHat' }} + it { should contain_python__virtualenv('/this/is/root') } + end + end + + describe 'web server' do + context 'debian' do + let(:facts) {{ :osfamily => 'Debian' }} + it { should contain_python__pip('gunicorn').with_virtualenv('/this/is/root') } + end + context 'redhat' do + let(:facts) {{ :osfamily => 'RedHat' }} + it { should contain_python__pip('gunicorn').with_virtualenv('/this/is/root') } + end + end - it { should contain_python__virtualenv('/this/is/root') } - it { should contain_python__pip('gunicorn').with_virtualenv('/this/is/root') } + describe 'cairo' do + context 'debian' do + let(:facts) {{ :osfamily => 'Debian' }} + it { should contain_package('python-cairo').with_ensure('present') } + end + context 'redhat' do + let(:facts) {{ :osfamily => 'RedHat' }} + it { should contain_package('pycairo').with_ensure('present') } + end + end - it { should contain_package('python-cairo').with_ensure('present') } - it { should contain_file('/this/is/root/lib/python2.7/site-packages/cairo'). - with_ensure('link'). - with_target('/usr/lib/python2.7/dist-packages/cairo'). - with_require(['Python::Virtualenv[/this/is/root]', 'Package[python-cairo]']) } + describe 'cairo symlink' do + context 'debian' do + let(:facts) {{ :osfamily => 'Debian' }} + it { should contain_file('/this/is/root/lib/python2.7/site-packages/cairo'). + with_ensure('link'). + with_target('/usr/lib/python2.7/dist-packages/cairo'). + with_require(['Python::Virtualenv[/this/is/root]', 'Package[python-cairo]']) } + end + context 'redhat' do + let(:facts) {{ :osfamily => 'RedHat' }} + it { should contain_file('/this/is/root/lib/python2.7/site-packages/cairo'). + with_ensure('link'). + with_target('/usr/lib64/python2.7/site-packages/cairo'). + with_require(['Python::Virtualenv[/this/is/root]', 'Package[pycairo]']) } + end end end diff --git a/spec/classes/graphite/graphite__install_spec.rb b/spec/classes/graphite/graphite__install_spec.rb index 6182be7..e476804 100644 --- a/spec/classes/graphite/graphite__install_spec.rb +++ b/spec/classes/graphite/graphite__install_spec.rb @@ -7,14 +7,22 @@ end describe 'graphite', :type => :class do - context 'root_dir and version' do + describe 'root_dir and version' do let(:params) {{ :version => '1.2.3', :root_dir => '/this/is/root', }} - - it_should_behave_like "pip_package", "whisper" - it_should_behave_like "pip_package", "carbon" - it_should_behave_like "pip_package", "graphite-web" + context 'debian' do + let(:facts) {{ :osfamily => 'Debian' }} + it_should_behave_like "pip_package", "whisper" + it_should_behave_like "pip_package", "carbon" + it_should_behave_like "pip_package", "graphite-web" + end + context 'redhat' do + let(:facts) {{ :osfamily => 'RedHat' }} + it_should_behave_like "pip_package", "whisper" + it_should_behave_like "pip_package", "carbon" + it_should_behave_like "pip_package", "graphite-web" + end end end diff --git a/spec/classes/graphite/graphite__service_spec.rb b/spec/classes/graphite/graphite__service_spec.rb index 09ea825..b344a10 100644 --- a/spec/classes/graphite/graphite__service_spec.rb +++ b/spec/classes/graphite/graphite__service_spec.rb @@ -1,17 +1,30 @@ require 'spec_helper' describe 'graphite', :type => :class do - context 'param defaults' do - it { should contain_service('carbon-aggregator').with_ensure('stopped') } - it { should contain_service('carbon-cache') } - it { should contain_service('graphite-web') } + describe 'param defaults' do + context 'debian' do + let(:facts) {{ :osfamily => 'Debian' }} + it { should contain_service('carbon-aggregator').with_ensure('stopped') } + it { should contain_service('carbon-cache') } + it { should contain_service('graphite-web') } + end + context 'redhat' do + let(:facts) {{ :osfamily => 'RedHat' }} + it { should contain_service('carbon-aggregator').with_ensure('stopped') } + it { should contain_service('carbon-cache') } + it { should contain_service('graphite-web') } + end end - - context 'carbon_aggregator' do - let(:params) {{ - :carbon_aggregator => true, - }} - - it { should contain_service('carbon-aggregator').with_ensure('running') } + describe 'carbon_aggregator' do + let(:params) {{ :carbon_aggregator => true }} + context 'debian' do + let(:facts) {{ :osfamily => 'Debian' }} + it { should contain_service('carbon-aggregator').with_ensure('running') } + end + context 'redhat' do + let(:facts) {{ :osfamily => 'RedHat' }} + it { should contain_service('carbon-aggregator').with_ensure('running') } + end end + end diff --git a/spec/classes/graphite/graphite_spec.rb b/spec/classes/graphite/graphite_spec.rb index ddbe4a5..38be500 100644 --- a/spec/classes/graphite/graphite_spec.rb +++ b/spec/classes/graphite/graphite_spec.rb @@ -1,10 +1,45 @@ require 'spec_helper' describe 'graphite', :type => :class do - let(:facts) { {:osfamily => 'debian'} } - it { should create_class('graphite::config')} - it { should create_class('graphite::install')} - it { should create_class('graphite::service')} - it { should contain_class('graphite::deps') } + context 'osfamily => debian' do + let(:facts) {{ :osfamily => 'Debian' }} + it { should create_class('graphite::config')} + it { should create_class('graphite::install')} + it { should create_class('graphite::service')} + it { should contain_class('graphite::deps') } + end + + context 'osfamily => redhat' do + let(:facts) {{ :osfamily => 'RedHat' }} + it { should create_class('graphite::config')} + it { should create_class('graphite::install')} + it { should create_class('graphite::service')} + it { should contain_class('graphite::deps') } + end + + context 'osfamily => Suse' do + let(:facts) {{ :osfamily => 'Suse' }} + it { expect { should contain_class('graphite') }.to raise_error(Puppet::Error) } + end + + context 'osfamily => Solaris' do + let(:facts) {{ :osfamily => 'Solaris' }} + it { expect { should contain_class('graphite') }.to raise_error(Puppet::Error) } + end + context 'osfamily => Gentoo' do + let(:facts) {{ :osfamily => 'Gentoo' }} + it { expect { should contain_class('graphite') }.to raise_error(Puppet::Error) } + end + + context 'osfamily => Archlinux' do + let(:facts) {{ :osfamily => 'Archlinux' }} + it { expect { should contain_class('graphite') }.to raise_error(Puppet::Error) } + end + + context 'osfamily => Mandrake' do + let(:facts) {{ :osfamily => 'Mandrake' }} + it { expect { should contain_class('graphite') }.to raise_error(Puppet::Error) } + end + end diff --git a/templates/init/carbon-aggregator b/templates/init/carbon-aggregator new file mode 100644 index 0000000..1714586 --- /dev/null +++ b/templates/init/carbon-aggregator @@ -0,0 +1,88 @@ +#! /bin/sh +### BEGIN INIT INFO +# Required-Stop: $local_fs $remote_fs $network $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Carbon aggregator service for Graphite +# Description: Carbon aggregator service for Graphite +### END INIT INFO + +# Source function library. +. /etc/rc.d/init.d/functions + +if [ ! -f /etc/sysconfig/carbon-aggregator ]; then + exit 6 +fi + +. /etc/sysconfig/carbon-aggregator + +PID=/var/run/carbon-aggregator.pid + +exec="<%= @root_dir %>/bin/carbon-aggregator.py" + + +[ -e /etc/sysconfig/carbon-aggregator ] && . /etc/sysconfig/carbon-aggregator + +lockfile=/var/lock/subsys/carbon-aggregator + +start() { + [ -d $GRAPHITE_CONF_DIR ] || exit 6 + [ -x $exec ] || exit 5 + echo -n $"Starting `basename $exec`: " + daemon "$exec \ + <% if @aggregation_rules_ensure == 'present' -%> + --rules='<%= @root_dir %>/conf/aggregation-rules.conf' \ + <% end -%> + --pidfile=$PID start" + retval=$? + echo + [ $retval -eq 0 ] && touch $lockfile + return $retval +} + +stop() { + echo -n $"Stopping `basename $exec`: " + killproc -p $PID `basename $exec` + retval=$? + echo + [ $retval -eq 0 ] && rm -f $lockfile + return $retval +} + +restart() { + stop + start +} + +rh_status() { + status -p $PID `basename $exec` +} + +rh_status_q() { + rh_status >/dev/null 2>&1 +} + +case "$1" in + start) + rh_status_q && exit 0 + $1 + ;; + stop) + rh_status_q || exit 0 + $1 + ;; + restart) + $1 + ;; + status) + rh_status + ;; + condrestart|try-restart) + rh_status_q || exit 0 + restart + ;; + *) + echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart}" + exit 2 +esac +exit $? \ No newline at end of file diff --git a/templates/init/carbon-cache b/templates/init/carbon-cache new file mode 100644 index 0000000..1c12dd3 --- /dev/null +++ b/templates/init/carbon-cache @@ -0,0 +1,83 @@ +#! /bin/sh +### BEGIN INIT INFO +# Required-Stop: $local_fs $remote_fs $network $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: carbon-cache init script +# Description: carbon-cache init script +### END INIT INFO + +# Source function library. +. /etc/rc.d/init.d/functions + +if [ ! -f /etc/sysconfig/carbon-cache ]; then + exit 6 +fi + +. /etc/sysconfig/carbon-cache + +PID=/var/run/carbon-cache.pid + +exec="<%= @root_dir %>/bin/carbon-cache.py" + +[ -e /etc/sysconfig/carbon-cache ] && . /etc/sysconfig/carbon-cache + +lockfile=/var/lock/subsys/carbon-cache + +start() { + [ -d $GRAPHITE_CONF_DIR ] || exit 6 + [ -x $exec ] || exit 5 + echo -n $"Starting `basename $exec`: " + daemon "$exec --pidfile=$PID start" + retval=$? + echo + [ $retval -eq 0 ] && touch $lockfile + return $retval +} + +stop() { + echo -n $"Stopping `basename $exec`: " + killproc -p $PID `basename $exec` + retval=$? + echo + [ $retval -eq 0 ] && rm -f $lockfile + return $retval +} + +restart() { + stop + start +} + +rh_status() { + status -p $PID `basename $exec` +} + +rh_status_q() { + rh_status >/dev/null 2>&1 +} + +case "$1" in + start) + rh_status_q && exit 0 + $1 + ;; + stop) + rh_status_q || exit 0 + $1 + ;; + restart) + $1 + ;; + status) + rh_status + ;; + condrestart|try-restart) + rh_status_q || exit 0 + restart + ;; + *) + echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart}" + exit 2 +esac +exit $? \ No newline at end of file diff --git a/templates/init/graphite-web b/templates/init/graphite-web new file mode 100644 index 0000000..946835b --- /dev/null +++ b/templates/init/graphite-web @@ -0,0 +1,56 @@ +#! /bin/sh +### BEGIN INIT INFO +# Required-Stop: $local_fs $remote_fs $network $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Graphite realtime graphing engine +# Description: Graphite realtime graphing engine +### END INIT INFO + +. /etc/init.d/functions + +if [ ! -f /etc/sysconfig/graphite-web ]; then + exit 6 +fi + +. /etc/sysconfig/graphite-web + +PID=/var/run/graphite-web.pid + +# Name of executable daemon +NAME=gunicorn-graphite +DESC=gunicorn-graphite + +# Path to Executable +DAEMON=<%= @root_dir %>/bin/gunicorn_django + +# DAEMON_OPTS="--user=$USER --group=$GROUP --bind=$BIND --pid=$PID --workers=$WORKERS --name=$APP --preload --daemon" +DAEMON_OPTS="-b <%= @bind_address -%>:<%= @port %> -w2 --pid=$PID --daemon graphite/settings.py" + +case "$1" in + start) + CD_TO_APP_DIR="cd $APP_ROOT" + + echo -n "Starting $DESC: " + $CD_TO_APP_DIR && $DAEMON $DAEMON_OPTS + echo "$NAME." + ;; + stop) + echo -n "Stopping $DESC: " + kill -QUIT `cat $PID` + echo "$NAME." + ;; + restart) + stop + start + ;; + status) + status -p $PID `basename $DAEMON` + ;; + *) + echo "Usage: $NAME {start|stop|restart|status}" >&2 + exit 1 + ;; +esac + +exit 0 \ No newline at end of file diff --git a/templates/sysconfig/carbon-aggregator b/templates/sysconfig/carbon-aggregator new file mode 100644 index 0000000..b95903b --- /dev/null +++ b/templates/sysconfig/carbon-aggregator @@ -0,0 +1,3 @@ +APP_ROOT="<%= @root_dir %>/webapp/graphite" +GRAPHITE_STORAGE_DIR="<%= @root_dir %>/storage" +GRAPHITE_CONF_DIR="<%= @root_dir %>/conf" diff --git a/templates/sysconfig/carbon-cache b/templates/sysconfig/carbon-cache new file mode 100644 index 0000000..b95903b --- /dev/null +++ b/templates/sysconfig/carbon-cache @@ -0,0 +1,3 @@ +APP_ROOT="<%= @root_dir %>/webapp/graphite" +GRAPHITE_STORAGE_DIR="<%= @root_dir %>/storage" +GRAPHITE_CONF_DIR="<%= @root_dir %>/conf" diff --git a/templates/sysconfig/graphite-web b/templates/sysconfig/graphite-web new file mode 100644 index 0000000..7c37952 --- /dev/null +++ b/templates/sysconfig/graphite-web @@ -0,0 +1,4 @@ +APP_ROOT="<%= @root_dir %>/webapp/graphite" +PYTHONPATH="<%= @root_dir %>/webapp" +GRAPHITE_STORAGE_DIR="<%= @root_dir %>/storage" +GRAPHITE_CONF_DIR="<%= @root_dir %>/conf" diff --git a/templates/systemd/carbon-aggregator.service b/templates/systemd/carbon-aggregator.service new file mode 100644 index 0000000..b7c6ca5 --- /dev/null +++ b/templates/systemd/carbon-aggregator.service @@ -0,0 +1,20 @@ +[Unit] +Description=Carbon aggregator service for Graphite +Wants=basic.target +After=basic.target network.target + +[Service] +EnvironmentFile=/etc/sysconfig/carbon-aggregator +User=<%= @user %> +ExecStart=<%= @root_dir %>/bin/carbon-aggregator.py \ +<% if @aggregation_rules_ensure == 'present' -%> + --rules='<%= @root_dir %>/conf/aggregation-rules.conf' \ +<% end -%> + --debug start +ExecReload=/bin/kill -HUP $MAINPID +KillMode=process +Restart=on-failure +RestartSec=42s + +[Install] +WantedBy=multi-user.target diff --git a/templates/systemd/carbon-cache.service b/templates/systemd/carbon-cache.service new file mode 100644 index 0000000..b691e7f --- /dev/null +++ b/templates/systemd/carbon-cache.service @@ -0,0 +1,16 @@ +[Unit] +Description=Carbon cache service for Graphite +Wants=basic.target +After=basic.target network.target + +[Service] +EnvironmentFile=/etc/sysconfig/carbon-cache +User=<%= @user %> +ExecStart=<%= @root_dir %>/bin/carbon-cache.py --debug start +ExecReload=/bin/kill -HUP $MAINPID +KillMode=process +Restart=on-failure +RestartSec=42s + +[Install] +WantedBy=multi-user.target diff --git a/templates/systemd/graphite-web.service b/templates/systemd/graphite-web.service new file mode 100644 index 0000000..4754733 --- /dev/null +++ b/templates/systemd/graphite-web.service @@ -0,0 +1,16 @@ +[Unit] +Description=Graphite realtime graphing engine +Wants=basic.target +After=basic.target network.target + +[Service] +EnvironmentFile=/etc/sysconfig/graphite-web +User=<%= @user %> +ExecStart=<%= @root_dir %>/bin/gunicorn_django -b <%= @bind_address -%>:<%= @port %> -w2 graphite/settings.py +ExecReload=/bin/kill -HUP $MAINPID +KillMode=process +Restart=on-failure +RestartSec=42s + +[Install] +WantedBy=multi-user.target