From 5ca0114364f6c9be13bbb032f3ac786226b4a907 Mon Sep 17 00:00:00 2001 From: Justin Dray Date: Sun, 14 Jun 2015 12:13:50 +1000 Subject: [PATCH 01/11] Workaround until upstream supports ability to detect launch systems correctly --- manifests/service.pp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/manifests/service.pp b/manifests/service.pp index ffcac94..883b915 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -12,8 +12,14 @@ 'Solaris' => '/lib/svc/manifest/network/diamond.xml', default => undef, } + $provider = $::systemd_available ? { + 'true' => 'systemd', + default => undef, + } + service { 'diamond': ensure => $ensure, + provider => $provider, name => $service_name, enable => $diamond::enable, hasstatus => true, From 65aaf21d53208cc6a021880f3141b06aca470446 Mon Sep 17 00:00:00 2001 From: Justin Dray Date: Sun, 14 Jun 2015 12:14:10 +1000 Subject: [PATCH 02/11] Added archlinux support and additional deps --- metadata.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/metadata.json b/metadata.json index 1f43889..23ef6f0 100644 --- a/metadata.json +++ b/metadata.json @@ -31,6 +31,8 @@ "operatingsystemrelease": [ "5.11" ] + },{ + "operatingsystem": "Archlinux" } ], "requirements": [ @@ -47,6 +49,10 @@ { "name": "puppetlabs/stdlib", "version_requirement": ">= 4.2.0" + }, + { + "name": "justin8/systemd", + "version_requirement": "> 0.0.1" } ] } From 667131fb53df046b7954f5bb3c68dc08a2384311 Mon Sep 17 00:00:00 2001 From: Justin Dray Date: Sun, 14 Jun 2015 12:15:50 +1000 Subject: [PATCH 03/11] Fixed collector paths when installing via pip in ubuntu --- manifests/config.pp | 1 + manifests/init.pp | 22 ++++++++++++++++++++++ templates/etc/diamond/diamond.conf.erb | 2 +- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/manifests/config.pp b/manifests/config.pp index 35526da..e5ca0ec 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -20,6 +20,7 @@ $hostname_method = $diamond::hostname_method $handlers_path = $diamond::handlers_path $rotate_days = $diamond::rotate_days + $collectors_path = $diamond::collectors_path file { '/etc/diamond/diamond.conf': ensure => present, content => template('diamond/etc/diamond/diamond.conf.erb'), diff --git a/manifests/init.pp b/manifests/init.pp index 48fab26..9304d43 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -91,6 +91,28 @@ $purge_collectors = false, $install_from_pip = false, ) { + include systemd + + case $osfamily { + 'Archlinux': { + $diamond_path = '/usr/bin/diamond' + $collectors_path = '/usr/share/diamond/collectors/' + } + 'RedHat': { + $diamond_path = '/usr/bin/diamond' + $collectors_path = '/usr/share/diamond/collectors/' + } + 'Debian': { + $diamond_path = '/usr/local/bin/diamond' + $collectors_path = '/usr/local/share/diamond/collectors/' + } + 'Solaris': { + $diamond_path = '/usr/bin/diamond' + $collectors_path = '/usr/share/diamond/collectors/' + $provider = undef + } + } + class{'diamond::install': } -> class{'diamond::config': } ~> class{'diamond::service': } -> diff --git a/templates/etc/diamond/diamond.conf.erb b/templates/etc/diamond/diamond.conf.erb index 250db41..ff056c6 100644 --- a/templates/etc/diamond/diamond.conf.erb +++ b/templates/etc/diamond/diamond.conf.erb @@ -33,7 +33,7 @@ group = pid_file = /var/run/diamond.pid # Directory to load collector modules from -collectors_path = /usr/share/diamond/collectors/ +collectors_path = <%= @collectors_path %> # Directory to load collector configs from collectors_config_path = /etc/diamond/collectors/ From 8945324ed9d88458b660e20bf0d9ac673b8b9228 Mon Sep 17 00:00:00 2001 From: Justin Dray Date: Sun, 14 Jun 2015 12:16:14 +1000 Subject: [PATCH 04/11] Fixed incorrect binary path for pip installation under ubuntu --- manifests/install.pp | 9 +++++++++ templates/diamond.service.erb | 9 +++++++++ 2 files changed, 18 insertions(+) create mode 100644 templates/diamond.service.erb diff --git a/manifests/install.pp b/manifests/install.pp index ab01386..b3791ef 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -4,6 +4,7 @@ # Also installed dependencies for collectors # class diamond::install { + $diamond_path = $diamond::diamond_path if $diamond::install_from_pip { case $::osfamily { @@ -55,12 +56,20 @@ group => 'sys', require => [Package['diamond'],File['/lib/svc/method/diamond']], } + } + + if $::systemd_available == 'true' { + file { "${::systemd::unit_path}/diamond.service": + content => template('diamond/diamond.service.erb'), + before => Service['diamond'], + } } else { file { '/etc/init.d/diamond': mode => '0755', require => Package['diamond'], } } + file { '/var/log/diamond': ensure => directory, } diff --git a/templates/diamond.service.erb b/templates/diamond.service.erb new file mode 100644 index 0000000..b5ddf20 --- /dev/null +++ b/templates/diamond.service.erb @@ -0,0 +1,9 @@ +[Unit] +Description=Diamond daemon +After=network.target + +[Service] +ExecStart=<%= @diamond_path %> --foreground --log-stdout + +[Install] +WantedBy=multi-user.target From 7593899ad32cbc3267afd8f9d8a89998cf15dd17 Mon Sep 17 00:00:00 2001 From: Justin Dray Date: Sun, 14 Jun 2015 15:32:47 +1000 Subject: [PATCH 05/11] Added scope to osfamily and a default case for linting --- manifests/init.pp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/manifests/init.pp b/manifests/init.pp index 9304d43..a41263b 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -93,7 +93,7 @@ ) { include systemd - case $osfamily { + case $::osfamily { 'Archlinux': { $diamond_path = '/usr/bin/diamond' $collectors_path = '/usr/share/diamond/collectors/' @@ -111,6 +111,10 @@ $collectors_path = '/usr/share/diamond/collectors/' $provider = undef } + default: { + $diamond_path = '/usr/bin/diamond' + $collectors_path = '/usr/share/diamond/collectors/' + $provider = undef } class{'diamond::install': } -> From e32bc032738a05b7fb3b3cde579926f4665ab22e Mon Sep 17 00:00:00 2001 From: Justin Dray Date: Sun, 14 Jun 2015 15:32:47 +1000 Subject: [PATCH 06/11] Added scope to osfamily and a default case for linting --- manifests/init.pp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/manifests/init.pp b/manifests/init.pp index 9304d43..4ce064b 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -93,7 +93,7 @@ ) { include systemd - case $osfamily { + case $::osfamily { 'Archlinux': { $diamond_path = '/usr/bin/diamond' $collectors_path = '/usr/share/diamond/collectors/' @@ -111,6 +111,11 @@ $collectors_path = '/usr/share/diamond/collectors/' $provider = undef } + default: { + $diamond_path = '/usr/bin/diamond' + $collectors_path = '/usr/share/diamond/collectors/' + $provider = undef + } } class{'diamond::install': } -> From 77feed515c010be8aef277f21750792f745bc7a2 Mon Sep 17 00:00:00 2001 From: Justin Dray Date: Sun, 14 Jun 2015 15:45:55 +1000 Subject: [PATCH 07/11] Added systemd module to fixtures for rspec tests --- .fixtures.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.fixtures.yml b/.fixtures.yml index 8aa336e..8ea8ec9 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -2,5 +2,6 @@ fixtures: repositories: stdlib: git://github.com/puppetlabs/puppetlabs-stdlib.git epel: git://github.com/stahnma/puppet-module-epel.git + systemd: git://github.com/justin8/justin8-systemd.git symlinks: diamond: "#{source_dir}" From 1d6f794f38a7694800dd65283dc8caa2f1e6b3b8 Mon Sep 17 00:00:00 2001 From: Justin Dray Date: Sun, 14 Jun 2015 16:22:26 +1000 Subject: [PATCH 08/11] Added rspec tests for systemd units. Fixed ubuntu tests. --- spec/classes/diamond/diamond_spec.rb | 42 ++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/spec/classes/diamond/diamond_spec.rb b/spec/classes/diamond/diamond_spec.rb index 0369e03..1c0a909 100644 --- a/spec/classes/diamond/diamond_spec.rb +++ b/spec/classes/diamond/diamond_spec.rb @@ -157,9 +157,22 @@ it { should contain_file('/var/log/diamond')} end + context 'with enabling pip installation on RedHat with systemd' do + let (:params) { {'install_from_pip' => true} } + let (:facts) { { + :osfamily => 'RedHat', + :systemd_available => 'true', + } } + # All other checks should be the exact same as without systemd + it { should contain_file('/usr/lib/systemd/system/diamond.service')} + end + context 'with enabling pip installation on Debian' do let (:params) { {'install_from_pip' => true} } - let (:facts) { {:osfamily => 'Debian'} } + let (:facts) { { + :osfamily => 'Debian', + :operatingsystem => 'Debian', + } } it { should contain_package('python-pip').that_comes_before('Package[diamond]')} it { should contain_package('python-configobj').that_comes_before('Package[diamond]')} it { should contain_package('gcc').that_comes_before('Package[diamond]')} @@ -173,9 +186,23 @@ it { should contain_file('/var/log/diamond')} end + context 'with enabling pip installation on Debian with systemd' do + let (:params) { {'install_from_pip' => true} } + let (:facts) { { + :osfamily => 'Debian', + :operatingsystem => 'Debian', + :systemd_available => 'true', + } } + # All other checks should be the exact same as without systemd + it { should contain_file('/lib/systemd/system/diamond.service')} + end + context 'with enabling pip installation on Ubuntu' do let (:params) { {'install_from_pip' => true} } - let (:facts) { {:osfamily => 'Ubuntu'} } + let (:facts) { { + :osfamily => 'Debian', + :operatingsystem => 'Ubuntu', + } } it { should contain_package('python-pip').that_comes_before('Package[diamond]')} it { should contain_package('python-configobj').that_comes_before('Package[diamond]')} it { should contain_package('gcc').that_comes_before('Package[diamond]')} @@ -189,6 +216,17 @@ it { should contain_file('/var/log/diamond')} end + context 'with enabling pip installation on Ubuntu with systemd' do + let (:params) { {'install_from_pip' => true} } + let (:facts) { { + :osfamily => 'Debian', + :operatingsystem => 'Ubuntu', + :systemd_available => 'true', + } } + # All other checks should be the exact same as without systemd + it { should contain_file('/lib/systemd/system/diamond.service')} + end + context 'with enabling pip installation on Solaris' do let (:params) { {'install_from_pip' => true} } let (:facts) { {:osfamily => 'Solaris', :operatingsystemrelease => '5.11'} } From 81d210c550d7104e0b469d3ee193f15c2936dd09 Mon Sep 17 00:00:00 2001 From: Justin Dray Date: Sun, 14 Jun 2015 19:52:11 +1000 Subject: [PATCH 09/11] Don't log to stdout as well. It duplicates all log entries to journal and /var/log/diamond/diamond.log in all diamond versions --- templates/diamond.service.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/diamond.service.erb b/templates/diamond.service.erb index b5ddf20..9a10c80 100644 --- a/templates/diamond.service.erb +++ b/templates/diamond.service.erb @@ -3,7 +3,7 @@ Description=Diamond daemon After=network.target [Service] -ExecStart=<%= @diamond_path %> --foreground --log-stdout +ExecStart=<%= @diamond_path %> --foreground [Install] WantedBy=multi-user.target From c50c9cd2b9f596ebaa167ef5b41ef7855e5ed950 Mon Sep 17 00:00:00 2001 From: Justin Dray Date: Wed, 24 Jun 2015 17:46:56 +1000 Subject: [PATCH 10/11] Reload systemd daemons on service file changes --- manifests/install.pp | 1 + 1 file changed, 1 insertion(+) diff --git a/manifests/install.pp b/manifests/install.pp index b3791ef..a6065aa 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -62,6 +62,7 @@ file { "${::systemd::unit_path}/diamond.service": content => template('diamond/diamond.service.erb'), before => Service['diamond'], + notify => Exec['systemd-daemon-reload'], } } else { file { '/etc/init.d/diamond': From 82dc05528b60b06101a6670ce51cf9d5139c9f39 Mon Sep 17 00:00:00 2001 From: Justin Dray Date: Wed, 24 Jun 2015 17:47:27 +1000 Subject: [PATCH 11/11] Added upper bounds version for systemd --- metadata.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata.json b/metadata.json index 23ef6f0..42d867c 100644 --- a/metadata.json +++ b/metadata.json @@ -52,7 +52,7 @@ }, { "name": "justin8/systemd", - "version_requirement": "> 0.0.1" + "version_requirement": "> 0.0.1 <= 1.0.0" } ] }