Skip to content

Commit

Permalink
Merge pull request jhoblitt#43 from queeno/manage_service_and_dont_at…
Browse files Browse the repository at this point in the history
…tempt_to_stop

Manage smartd service and don't attempt to stop if package is absent
  • Loading branch information
Joshua Hoblitt committed Oct 14, 2015
2 parents 6802d4f + 19be823 commit 0d434ce
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
27 changes: 20 additions & 7 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@
#
# defaults to: `running`
#
# [*manage_service*]
# `Bool`
#
# State whether or not this puppet module should manage the service.
# This parameter is disregarded when $ensure = absent|purge.
#
# defaults to: `true`
#
# [*config_file*]
# `String`
#
Expand Down Expand Up @@ -101,6 +109,7 @@
$package_name = $smartd::params::package_name,
$service_name = $smartd::params::service_name,
$service_ensure = $smartd::params::service_ensure,
$manage_service = $smartd::params::manage_service,
$config_file = $smartd::params::config_file,
$devicescan = $smartd::params::devicescan,
$devicescan_options = $smartd::params::devicescan_options,
Expand Down Expand Up @@ -130,12 +139,14 @@
$svc_ensure = $service_ensure
$svc_enable = $service_ensure ? { 'running' => true, 'stopped' => false }
$file_ensure = 'present'
$srv_manage = $manage_service
}
'absent', 'purged': {
$pkg_ensure = $ensure
$svc_ensure = 'stopped'
$svc_enable = false
$file_ensure = 'absent'
$srv_manage = false
}
default: {
fail("unsupported value of \$ensure: ${ensure}")
Expand All @@ -146,14 +157,16 @@
ensure => $pkg_ensure,
}

service { $service_name:
ensure => $svc_ensure,
enable => $svc_enable,
hasrestart => true,
hasstatus => true,
}
if $srv_manage {
service { $service_name:
ensure => $svc_ensure,
enable => $svc_enable,
hasrestart => true,
hasstatus => true,
}

Package[$package_name] -> Service[$service_name]
Package[$package_name] -> Service[$service_name]
}

file { $config_file:
ensure => $file_ensure,
Expand Down
1 change: 1 addition & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
class smartd::params {
$package_name = 'smartmontools'
$service_ensure = 'running'
$manage_service = true
$devicescan = true
$devicescan_options = undef
$devices = []
Expand Down
10 changes: 8 additions & 2 deletions spec/unit/classes/smartd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,15 @@
let(:params) {{ :ensure => 'absent' }}

it { should contain_package('smartmontools').with_ensure('absent') }
it { should contain_service('smartd').with_ensure('stopped').with_enable(false) }
it { should_not contain_service('smartd') }
it { should contain_file('/etc/smartd.conf').with_ensure('absent') }
end

describe 'ensure => purge' do
let(:params) {{ :ensure => 'purged' }}

it { should contain_package('smartmontools').with_ensure('purged') }
it { should contain_service('smartd').with_ensure('stopped').with_enable(false) }
it { should_not contain_service('smartd') }
it { should contain_file('/etc/smartd.conf').with_ensure('absent') }
end

Expand Down Expand Up @@ -172,6 +172,12 @@
it { should contain_service('smartd').with_ensure('stopped').with_enable(false) }
end

describe 'manage_service => false' do
let(:params) {{ :manage_service => false }}

it { should_not contain_service('smartd') }
end

describe 'service_ensure => badvalue' do
let(:params) {{ :service_ensure => 'badvalue' }}

Expand Down

0 comments on commit 0d434ce

Please sign in to comment.