diff --git a/manifests/config.pp b/manifests/config.pp index 91fb1f72..055170e9 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -17,7 +17,7 @@ # optional: python-ldap, python-memcache, memcached, python-sqlite if ($::osfamily == 'RedHat' and $::operatingsystemrelease =~ /^7\.\d+/) or ( - $::graphite::params::service_provider == 'debian' and $::operatingsystemmajrelease =~ /8|15\.10/) { + $::graphite::params::service_provider == 'systemd') { $initscript_notify = [Exec['graphite-reload-systemd'],] exec { 'graphite-reload-systemd': diff --git a/manifests/config_apache.pp b/manifests/config_apache.pp index 44aa9f33..5f09096d 100644 --- a/manifests/config_apache.pp +++ b/manifests/config_apache.pp @@ -86,12 +86,13 @@ logoutput => true, group => $graphite::config::gr_web_group_REAL, returns => [0, 1], + refreshonly => true, require => [ File['/tmp/fix-graphite-race-condition.py'], - Exec['Initial django db creation'], Service['carbon-cache'], ], before => Service[$::graphite::params::apache_service_name], + subscribe => Exec['Initial django db creation'], } service { $::graphite::params::apache_service_name: diff --git a/manifests/config_gunicorn.pp b/manifests/config_gunicorn.pp index a98c7a1f..175c9f4a 100644 --- a/manifests/config_gunicorn.pp +++ b/manifests/config_gunicorn.pp @@ -28,7 +28,7 @@ content => template('graphite/etc/gunicorn.d/graphite.erb'), mode => '0644', before => Package[$package_name], - require => File['/etc/gunicorn.d/'], + require => File['/etc/gunicorn.d'], } } @@ -37,7 +37,7 @@ # RedHat package is missing initscript # RedHat 7+ uses systemd - if $::operatingsystemrelease =~ /^7\.\d+/ { + if $::graphite::params::service_provider == 'systemd' { file { '/etc/systemd/system/gunicorn.service': ensure => file, @@ -59,14 +59,15 @@ # TODO: we should use the exec graphite-reload-systemd from config class exec { 'gunicorn-reload-systemd': - command => 'systemctl daemon-reload', - path => ['/usr/bin', '/usr/sbin', '/bin', '/sbin'], - require => [ + command => 'systemctl daemon-reload', + path => ['/usr/bin', '/usr/sbin', '/bin', '/sbin'], + refreshonly => true, + subscribe => [ File['/etc/systemd/system/gunicorn.service'], File['/etc/systemd/system/gunicorn.socket'], File['/etc/tmpfiles.d/gunicorn.conf'], ], - before => Service['gunicorn'] + before => Service['gunicorn'] } } else { @@ -88,16 +89,6 @@ } - # The `gunicorn-debian` command doesn't require this, as it - # uses the deprecated `gunicorn_django` command. But, I hope - # that debian will eventually update their gunicorn package - # to use the non-deprecated version. - file { "${graphite::graphiteweb_install_lib_dir_REAL}/wsgi.py": - ensure => link, - target => "${graphite::graphiteweb_conf_dir_REAL}/graphite.wsgi", - before => Service['gunicorn'], - } - # fix graphite's race condition on start # if the exec fails, assume we're using a version of graphite that doesn't need it if $graphite::gunicorn_workers > 1 { @@ -114,12 +105,13 @@ logoutput => true, group => $graphite::config::gr_web_group_REAL, returns => [0, 1], + refreshonly => true, require => [ File['/tmp/fix-graphite-race-condition.py'], - Exec['Initial django db creation'], Service['carbon-cache'], ], before => Package[$package_name], + subscribe => Exec['Initial django db creation'], } } @@ -139,11 +131,11 @@ enable => true, hasrestart => true, hasstatus => false, + provider => $::graphite::params::service_provider, require => [ Package[$package_name], File["${::graphite::graphiteweb_conf_dir_REAL}/graphite_wsgi.py"] ], - subscribe => File[$::graphite::config::local_settings_py_file], } } diff --git a/manifests/params.pp b/manifests/params.pp index 85a7501b..d675b098 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -48,7 +48,6 @@ $apacheconf_dir = '/etc/apache2/sites-available' $apacheports_file = 'ports.conf' $apache_logdir_graphite = '/var/log/apache2/graphite-web' - $service_provider = undef $nginxconf_dir = '/etc/nginx/sites-available' @@ -69,6 +68,20 @@ 'python-sqlite', ] + if $::operatingsystem == 'Ubuntu' { + if versioncmp($::lsbdistrelease, '15.10') == -1 { + $service_provider = 'debian' + } else { + $service_provider = 'systemd' + } + } elsif $::operatingsystem == 'Debian' { + if versioncmp($::lsbdistrelease, '8.0') == -1 { + $service_provider = 'debian' + } else { + $service_provider = 'systemd' + } + } + case $::lsbdistcodename { /squeeze|wheezy|precise/: { $apache_24 = false @@ -96,7 +109,6 @@ $apacheconf_dir = '/etc/httpd/conf.d' $apacheports_file = 'graphite_ports.conf' $apache_logdir_graphite = '/var/log/httpd/graphite-web' - $service_provider = 'redhat' $nginxconf_dir = '/etc/nginx/conf.d' @@ -121,11 +133,13 @@ /^6\.\d+$/: { $apache_24 = false $graphitepkgs = union($common_os_pkgs,['python-sqlite2', 'bitmap-fonts-compat', 'bitmap', 'pycairo','python-crypto']) + $service_provider = 'redhat' } /^7\.\d+/: { $apache_24 = true $graphitepkgs = union($common_os_pkgs,['python-sqlite3dbm', 'dejavu-fonts-common', 'dejavu-sans-fonts', 'python-cairocffi','python2-crypto']) + $service_provider = 'systemd' } default: { diff --git a/spec/classes/graphite_config_apache_spec.rb b/spec/classes/graphite_config_apache_spec.rb index fb79922d..fd155e81 100644 --- a/spec/classes/graphite_config_apache_spec.rb +++ b/spec/classes/graphite_config_apache_spec.rb @@ -91,4 +91,4 @@ end -end \ No newline at end of file +end diff --git a/spec/classes/graphite_config_gunicorn_spec.rb b/spec/classes/graphite_config_gunicorn_spec.rb new file mode 100644 index 00000000..b3b1821b --- /dev/null +++ b/spec/classes/graphite_config_gunicorn_spec.rb @@ -0,0 +1,133 @@ +require 'spec_helper' + +describe 'graphite::config_gunicorn', :type => 'class' do + + shared_context 'all platforms' do + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('graphite::params') } + end + + shared_context 'RedHat supported platforms' do + it { is_expected.to contain_package('python-gunicorn').with({ :name => 'python-gunicorn', :ensure => 'installed' }) } + end + + shared_context 'RedHat 6 platforms' do + it { is_expected.to contain_file('/etc/init.d/gunicorn').with({ + 'ensure' => 'file', + 'mode' => '0755'}) } + it { is_expected.to contain_service('gunicorn').with({ + 'ensure' => 'running', + 'enable' => 'true', + 'hasrestart' => 'true', + 'hasstatus' => 'false', + 'provider' => 'redhat'}). + that_requires( + ['Package[python-gunicorn]', + 'File[/opt/graphite/conf/graphite_wsgi.py]', + 'File[/etc/init.d/gunicorn]']) } + end + + shared_context 'RedHat 7 platforms' do + it { is_expected.to contain_exec('gunicorn-reload-systemd') } + it { is_expected.to contain_file('/etc/systemd/system/gunicorn.service').with({ + 'ensure' => 'file', + 'mode' => '0644'}).that_notifies('Exec[gunicorn-reload-systemd]') } + it { is_expected.to contain_file('/etc/systemd/system/gunicorn.socket').with({ + 'ensure' => 'file', + 'mode' => '0755'}).that_notifies('Exec[gunicorn-reload-systemd]') } + it { is_expected.to contain_file('/etc/tmpfiles.d/gunicorn.conf').with({ + 'ensure' => 'file', + 'mode' => '0644'}).that_notifies('Exec[gunicorn-reload-systemd]') } + it { is_expected.to contain_service('gunicorn').with({ + 'ensure' => 'running', + 'enable' => 'true', + 'hasrestart' => 'true', + 'hasstatus' => 'false', + 'provider' => 'systemd'}). + that_requires( + ['Package[python-gunicorn]', + 'Exec[gunicorn-reload-systemd]', + 'File[/opt/graphite/conf/graphite_wsgi.py]']) } + end + + shared_context 'Debian supported platforms' do + it { is_expected.to contain_package('gunicorn').with({ :name => 'gunicorn', :ensure => 'installed' }) } + it { is_expected.to contain_file('/etc/gunicorn.d').with({ + 'ensure' => 'directory', + 'path' => '/etc/gunicorn.d'}) } + it { is_expected.to contain_file('/etc/gunicorn.d/graphite').with({ + 'ensure' => 'file', + 'mode' => '0644', + 'before' => 'Package[gunicorn]' }).that_requires('File[/etc/gunicorn.d]') } + it { is_expected.to contain_service('gunicorn').with({ + 'ensure' => 'running', + 'enable' => 'true', + 'hasrestart' => 'true', + 'hasstatus' => 'false'}). + that_requires( + ['Package[gunicorn]', + 'File[/opt/graphite/conf/graphite_wsgi.py]']) } + end + + #shared_context 'Debian sysv platforms' do + #it { is_expected.to contain_service('gunicorn').with({ + #'ensure' => 'running', + #'enable' => 'true', + #'hasrestart' => 'true', + #'hasstatus' => 'false', + #'provider' => 'debian'}). + #that_requires( + #['Package[gunicorn]', + #'File[/opt/graphite/conf/graphite_wsgi.py']) } + #end + + #shared_context 'Debian systemd platforms' do + #it { is_expected.to contain_service('gunicorn').with({ + #'ensure' => 'running', + #'enable' => 'true', + #'hasrestart' => 'true', + #'hasstatus' => 'false', + #'provider' => 'systemd'}). + #that_requires( + #['Package[gunicorn]', + #'File[/opt/graphite/conf/graphite_wsgi.py']) } + #end + + context 'Unsupported OS' do + let(:facts) {{ :osfamily => 'unsupported', :operatingsystem => 'UnknownOS' }} + it { is_expected.to raise_error(Puppet::Error, /unsupported os,.+\./ )} + end + + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts + end + let :pre_condition do + 'class { ::graphite: gr_web_server => nginx }' + end + + it_behaves_like 'all platforms' + + case facts[:osfamily] + when 'Debian' then + it_behaves_like 'Debian supported platforms' + when 'RedHat' then + it_behaves_like 'RedHat supported platforms' + case facts[:operatingsystemrelease] + when /^6/ then + it_behaves_like 'RedHat 6 platforms' + when /^7/ then + it_behaves_like 'RedHat 7 platforms' + else + it { is_expected.to raise_error(Puppet::Error,/unsupported os,.+\./ )} + end + else + it { is_expected.to raise_error(Puppet::Error, /unsupported os,.+\./ )} + end + + end + + end + +end diff --git a/spec/classes/graphite_config_nginx_spec.rb b/spec/classes/graphite_config_nginx_spec.rb index bcbdcc0d..020f6d48 100644 --- a/spec/classes/graphite_config_nginx_spec.rb +++ b/spec/classes/graphite_config_nginx_spec.rb @@ -23,10 +23,15 @@ it { is_expected.to contain_file('/etc/nginx/graphite-htpasswd').with({ 'ensure' => 'absent', 'mode' => '0400', - 'owner' => 'apache', + 'owner' => 'nginx', 'content' => nil, 'require' => 'Package[nginx]', 'notify' => 'Service[nginx]' }) } + it { is_expected.to contain_file('/etc/nginx/conf.d/default.conf').only_with({ + :path => '/etc/nginx/conf.d/default.conf', + :ensure => 'absent', + :require => 'Package[nginx]', + :notify => 'Service[nginx]'}) } end shared_context 'Debian supported platforms' do @@ -37,6 +42,11 @@ 'content' => nil, 'require' => 'Package[nginx]', 'notify' => 'Service[nginx]' }) } + it { is_expected.to contain_file('/etc/nginx/sites-enabled/default').only_with({ + :path => '/etc/nginx/sites-enabled/default', + :ensure => 'absent', + :require => 'Package[nginx]', + :notify => 'Service[nginx]'}) } end context 'Unsupported OS' do @@ -50,7 +60,7 @@ facts end let :pre_condition do - 'include ::graphite' + 'class { ::graphite: gr_web_server => nginx }' end it_behaves_like 'all platforms' @@ -68,4 +78,4 @@ end -end \ No newline at end of file +end diff --git a/spec/classes/graphite_config_spec.rb b/spec/classes/graphite_config_spec.rb index 3872faf4..5c44d7c2 100644 --- a/spec/classes/graphite_config_spec.rb +++ b/spec/classes/graphite_config_spec.rb @@ -56,13 +56,6 @@ 'target' => '/opt/graphite/conf/graphite_wsgi.py', 'require' => 'File[/opt/graphite/conf/graphite_wsgi.py]', 'notify' => 'Service[httpd]' }) } - it { is_expected.to contain_service('carbon-cache').with({ - 'ensure' => 'running', - 'enable' => 'true', - 'hasrestart' => 'true', - 'hasstatus' => 'true', - 'provider' => 'redhat', - 'require' => 'File[/etc/init.d/carbon-cache]' }) } $attributes_redhat = {'ensure' => 'directory', 'group' => 'apache', 'mode' => '0755', 'owner' => 'apache', 'subscribe' => 'Exec[Initial django db creation]'} ['/opt/graphite/storage', @@ -81,6 +74,13 @@ 'mode' => '0750', 'require' => 'File[/opt/graphite/conf/carbon.conf]', 'notify' => [] }) } + it { is_expected.to contain_service('carbon-cache').with({ + 'ensure' => 'running', + 'enable' => 'true', + 'hasrestart' => 'true', + 'hasstatus' => 'true', + 'provider' => 'redhat', + 'require' => 'File[/etc/init.d/carbon-cache]' }) } end shared_context 'RedHat 7 platforms' do @@ -91,6 +91,13 @@ 'mode' => '0750', 'require' => 'File[/opt/graphite/conf/carbon.conf]', 'notify' => /graphite-reload-systemd/ }) } + it { is_expected.to contain_service('carbon-cache').with({ + 'ensure' => 'running', + 'enable' => 'true', + 'hasrestart' => 'true', + 'hasstatus' => 'true', + 'provider' => 'systemd', + 'require' => 'File[/etc/init.d/carbon-cache]' }) } end shared_context 'Debian supported platforms' do @@ -120,28 +127,48 @@ 'target' => '/opt/graphite/conf/graphite_wsgi.py', 'require' => 'File[/opt/graphite/conf/graphite_wsgi.py]', 'notify' => 'Service[apache2]'}) } - it { is_expected.to contain_service('carbon-cache').only_with({ + + $attributes_debian = {'ensure' => 'directory', 'group' => 'www-data', 'mode' => '0755', 'owner' => 'www-data', 'subscribe' => 'Exec[Initial django db creation]'} + ['/opt/graphite/storage', + '/opt/graphite/storage/rrd', + '/opt/graphite/storage/lists', + '/opt/graphite/storage/log', + '/var/lib/graphite-web'].each { |f| + it { is_expected.to contain_file(f).with($attributes_debian)} + } + end + + shared_context 'Debian sysv platforms' do + it { is_expected.to contain_file('/etc/init.d/carbon-cache').with({ + 'ensure' => 'file', + 'content' => /^GRAPHITE_DIR="\/opt\/graphite"$/, + 'mode' => '0750', + 'require' => 'File[/opt/graphite/conf/carbon.conf]', + 'notify' => [] }) } + it { is_expected.to contain_service('carbon-cache').with({ 'ensure' => 'running', 'enable' => 'true', 'hasrestart' => 'true', 'hasstatus' => 'true', - 'provider' => nil, + 'provider' => 'debian', 'require' => 'File[/etc/init.d/carbon-cache]' }) } + end + + shared_context 'Debian systemd platforms' do + it { is_expected.to contain_exec('graphite-reload-systemd') } it { is_expected.to contain_file('/etc/init.d/carbon-cache').with({ 'ensure' => 'file', 'content' => /^GRAPHITE_DIR="\/opt\/graphite"$/, 'mode' => '0750', 'require' => 'File[/opt/graphite/conf/carbon.conf]', - 'notify' => [] }) } - - $attributes_debian = {'ensure' => 'directory', 'group' => 'www-data', 'mode' => '0755', 'owner' => 'www-data', 'subscribe' => 'Exec[Initial django db creation]'} - ['/opt/graphite/storage', - '/opt/graphite/storage/rrd', - '/opt/graphite/storage/lists', - '/opt/graphite/storage/log', - '/var/lib/graphite-web'].each { |f| - it { is_expected.to contain_file(f).with($attributes_debian)} - } + 'notify' => /graphite-reload-systemd/ }) } + it { is_expected.to contain_service('carbon-cache').with({ + 'ensure' => 'running', + 'enable' => 'true', + 'hasrestart' => 'true', + 'hasstatus' => 'true', + 'provider' => 'systemd', + 'require' => 'File[/etc/init.d/carbon-cache]' }) } end context 'Unsupported OS' do @@ -163,6 +190,14 @@ case facts[:osfamily] when 'Debian' then it_behaves_like 'Debian supported platforms' + case facts[:lsbdistcodename] + when /squeeze|wheezy|precise|trusty|utopic|vivid/ then + it_behaves_like 'Debian sysv platforms' + when /jessie|wily/ then + it_behaves_like 'Debian systemd platforms' + else + it { is_expected.to raise_error(Puppet::Error,/unsupported os,.+\./ )} + end when 'RedHat' then it_behaves_like 'RedHat supported platforms' case facts[:operatingsystemrelease] diff --git a/templates/etc/systemd/gunicorn.service.erb b/templates/etc/systemd/gunicorn.service.erb index 2f5f4f06..74b345c5 100644 --- a/templates/etc/systemd/gunicorn.service.erb +++ b/templates/etc/systemd/gunicorn.service.erb @@ -5,7 +5,7 @@ After=network.target [Service] PIDFile=/run/gunicorn.pid -WorkingDirectory=<%= scope.lookupvar('graphite::graphiteweb_webapp_dir_REAL') %>/graphite +WorkingDirectory=<%= scope.lookupvar('graphite::graphiteweb_webapp_dir_REAL') %> ExecStart=/usr/bin/gunicorn --pid /run/gunicorn.pid --timeout=<%= scope.lookupvar('graphite::gunicorn_arg_timeout') %> --bind=<%= scope.lookupvar('graphite::gunicorn_bind') %> --workers=<%= scope.lookupvar('graphite::gunicorn_workers') %> --user <%= scope.lookupvar('graphite::config::gr_web_user_REAL') %> --group <%= scope.lookupvar('graphite::config::gr_web_group_REAL') %> --access-logfile <%= scope.lookupvar('graphite::graphiteweb_log_dir_REAL') %>/access-gunicorn.log --error-logfile <%= scope.lookupvar('graphite::graphiteweb_log_dir_REAL') %>/error-gunicorn.log graphite.graphite_wsgi:application ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s TERM $MAINPID