diff --git a/manifests/init.pp b/manifests/init.pp index 4bc00ebbb..f62349cc5 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -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, @@ -141,8 +142,6 @@ } class { 'nginx::service': - configtest_enable => $configtest_enable, - service_restart => $service_restart, } create_resources('nginx::resource::upstream', $nginx_upstreams) diff --git a/manifests/params.pp b/manifests/params.pp index 48a771013..b887cc689 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -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 diff --git a/manifests/service.pp b/manifests/service.pp index 2ec38b51d..e02c35be4 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -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, } diff --git a/spec/classes/service_spec.rb b/spec/classes/service_spec.rb index 9e8e7ce1c..300316e5d 100644 --- a/spec/classes/service_spec.rb +++ b/spec/classes/service_spec.rb @@ -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 @@ -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