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

add service_ensure support #264

Merged
merged 2 commits into from
Mar 17, 2014
Merged
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
3 changes: 1 addition & 2 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
$proxy_cache_inactive = $nginx::params::nx_proxy_cache_inactive,
$configtest_enable = $nginx::params::nx_configtest_enable,
$service_restart = $nginx::params::nx_service_restart,
$service_ensure = $nginx::params::nx_service_ensure,
$mail = $nginx::params::nx_mail,
$server_tokens = $nginx::params::nx_server_tokens,
$client_max_body_size = $nginx::params::nx_client_max_body_size,
Expand Down Expand Up @@ -141,8 +142,6 @@
}

class { 'nginx::service':
configtest_enable => $configtest_enable,
service_restart => $service_restart,
}

create_resources('nginx::resource::upstream', $nginx_upstreams)
Expand Down
1 change: 1 addition & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@

$nx_configtest_enable = false
$nx_service_restart = '/etc/init.d/nginx configtest && /etc/init.d/nginx restart'
$nx_service_ensure = running

$nx_mail = false

Expand Down
16 changes: 12 additions & 4 deletions manifests/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,25 @@
#
# This class file is not called directly
class nginx::service(
$configtest_enable = $nginx::params::nx_configtest_enable,
$service_restart = $nginx::params::nx_service_restart
$configtest_enable = $nginx::configtest_enable,
$service_restart = $nginx::service_restart,
$service_ensure = $nginx::service_ensure,
) {

if $caller_module_name != $module_name {
warning("${name} is deprecated as a public API of the ${module_name} module and should no longer be directly included in the manifest.")
}

$service_enable = $service_ensure ? {
running => true,
absent => false,
stopped => false,
default => true,
}

service { 'nginx':
ensure => running,
enable => true,
ensure => $service_ensure,
enable => $service_enable,
hasstatus => true,
hasrestart => true,
}
Expand Down
12 changes: 6 additions & 6 deletions spec/classes/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
:operatingsystem => 'debian',
} end

let :pre_condition do
[
'include ::nginx::params',
]
end
let :params do {
:configtest_enable => false,
:service_restart => '/etc/init.d/nginx configtest && /etc/init.d/nginx restart',
:service_ensure => 'running',
} end

context "using default parameters" do

Expand All @@ -26,7 +26,7 @@
end

describe "when configtest_enable => true" do
let(:params) {{ :configtest_enable => true }}
let(:params) {{ :configtest_enable => true, :service_restart => '/etc/init.d/nginx configtest && /etc/init.d/nginx restart'}}
it { should contain_service('nginx').with_restart('/etc/init.d/nginx configtest && /etc/init.d/nginx restart') }

context "when service_restart => 'a restart command'" do
Expand Down