Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ubuntu15 and systemd support #37

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
1 change: 1 addition & 0 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
27 changes: 27 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,33 @@
$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
}
default: {
$diamond_path = '/usr/bin/diamond'
$collectors_path = '/usr/share/diamond/collectors/'
$provider = undef
}
}

class{'diamond::install': } ->
class{'diamond::config': } ~>
class{'diamond::service': } ->
Expand Down
10 changes: 10 additions & 0 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Also installed dependencies for collectors
#
class diamond::install {
$diamond_path = $diamond::diamond_path

if $diamond::install_from_pip {
case $::osfamily {
Expand Down Expand Up @@ -55,12 +56,21 @@
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'],
notify => Exec['systemd-daemon-reload'],
}
} else {
file { '/etc/init.d/diamond':
mode => '0755',
require => Package['diamond'],
}
}

file { '/var/log/diamond':
ensure => directory,
}
Expand Down
6 changes: 6 additions & 0 deletions manifests/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
"operatingsystemrelease": [
"5.11"
]
},{
"operatingsystem": "Archlinux"
}
],
"requirements": [
Expand All @@ -47,6 +49,10 @@
{
"name": "puppetlabs/stdlib",
"version_requirement": ">= 4.2.0"
},
{
"name": "justin8/systemd",
"version_requirement": "> 0.0.1 <= 1.0.0"
}
]
}
42 changes: 40 additions & 2 deletions spec/classes/diamond/diamond_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]')}
Expand All @@ -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]')}
Expand All @@ -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'} }
Expand Down
9 changes: 9 additions & 0 deletions templates/diamond.service.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Unit]
Description=Diamond daemon
After=network.target

[Service]
ExecStart=<%= @diamond_path %> --foreground

[Install]
WantedBy=multi-user.target
2 changes: 1 addition & 1 deletion templates/etc/diamond/diamond.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down