Skip to content
This repository was archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
Small fixes and improvements (#281)
Browse files Browse the repository at this point in the history
* Fixes that weren't properly merged

- The `wsgi.py` link is no longer needed since one was made in
  `config.pp`. So that code is no longer necessary. This block wasn't
  merged in.
- Removing subscription to `$local_settings_py_file`. It is not defined
  when `config_gunicorn.pp` is evaluated. As it turns out, it can be safely
  removed.

* New variable means WorkingDirectory doesn't need /graphite on the end

* Only run race condition fix after initial db creation

It used to `exec` on every run, now it won't.

* Only bump systemd on install

* Add service provider definition for Debian-based OSs

Debian 8 was not starting carbon-cache because it didn't know it had to
reload the systemd definitions. So I coded in a params for it, like was
done for redhat-based OSs. This allowed for simplified logic in
`config.pp`.

* Adding provider to gunicorn service

Ubuntu 15.10 has some weird race condition or something, where the
service would sometimes start and sometimes not. Explicitly specifying
the service provider seems to have no such error.

* Set RedHat service provider based on OS version

Rather than blanketing everything with RedHat and using OS version
checks, I have coded in what the `service_provider` should be.

* Adding rspec for config_gunicorn and updating the others

* Fix for float vs string problem
  • Loading branch information
squarebracket authored and dwerder committed Apr 28, 2016
1 parent 2f1578a commit 2b3364c
Show file tree
Hide file tree
Showing 9 changed files with 231 additions and 46 deletions.
2 changes: 1 addition & 1 deletion manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
3 changes: 2 additions & 1 deletion manifests/config_apache.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
28 changes: 10 additions & 18 deletions manifests/config_gunicorn.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
}
}

Expand All @@ -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,
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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'],
}
}

Expand All @@ -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],
}

}
18 changes: 16 additions & 2 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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
Expand Down Expand Up @@ -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'

Expand All @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/graphite_config_apache_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,4 @@

end

end
end
133 changes: 133 additions & 0 deletions spec/classes/graphite_config_gunicorn_spec.rb
Original file line number Diff line number Diff line change
@@ -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
16 changes: 13 additions & 3 deletions spec/classes/graphite_config_nginx_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -50,7 +60,7 @@
facts
end
let :pre_condition do
'include ::graphite'
'class { ::graphite: gr_web_server => nginx }'
end

it_behaves_like 'all platforms'
Expand All @@ -68,4 +78,4 @@

end

end
end
Loading

0 comments on commit 2b3364c

Please sign in to comment.