From 08b8cc0dd57e2c8697f7f5539d54b64d6da92b7b Mon Sep 17 00:00:00 2001 From: William Yardley Date: Thu, 13 Oct 2016 10:21:18 -0700 Subject: [PATCH] Restore $service_restart, but now without $configtest_enable parameter (see comments in #921). Pass on $nginx::service_foo directly to service class --- manifests/init.pp | 11 ++++------- manifests/service.pp | 17 ++++++++++++----- spec/classes/service_spec.rb | 11 +++++++++++ 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index 948a96a76..1b1dc7098 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -114,6 +114,7 @@ ### START Service Configuation ### $service_ensure = running, $service_flags = undef, + $service_restart = undef, $service_name = undef, $service_manage = true, ### END Service Configuration ### @@ -300,14 +301,10 @@ sites_available_mode => $sites_available_mode, } } - Class['::nginx::package'] -> Class['::nginx::config'] ~> Class['::nginx::service'] - class { '::nginx::service': - service_ensure => $service_ensure, - service_name => $service_name, - service_flags => $service_flags, - service_manage => $service_manage, - } + include '::nginx::service' + + Class['::nginx::package'] -> Class['::nginx::config'] ~> Class['::nginx::service'] create_resources('nginx::resource::upstream', $nginx_upstreams) create_resources('nginx::resource::vhost', $nginx_vhosts, $nginx_vhosts_defaults) diff --git a/manifests/service.pp b/manifests/service.pp index af29b8f7e..4d062580b 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -14,11 +14,12 @@ # # This class file is not called directly class nginx::service( - $service_ensure = 'running', - $service_name = 'nginx', - $service_flags = undef, - $service_manage = true, -) { + $service_restart = $::nginx::service_restart, + $service_ensure = $::nginx::service_ensure, + $service_name = $::nginx::service_name, + $service_flags = $::nginx::service_flags, + $service_manage = $::nginx::service_manage, +) inherits nginx { $service_enable = $service_ensure ? { 'running' => true, @@ -58,4 +59,10 @@ } } + # Allow overriding of 'restart' of Service resource; not used by default + if $service_restart { + Service['nginx'] { + restart => $service_restart, + } + } } diff --git a/spec/classes/service_spec.rb b/spec/classes/service_spec.rb index 7aee18320..1d5c959f4 100644 --- a/spec/classes/service_spec.rb +++ b/spec/classes/service_spec.rb @@ -21,6 +21,17 @@ it { is_expected.to contain_service('nginx').without_restart } end + context "when service_restart => 'a restart command'" do + let :params do + { + service_restart: 'a restart command', + service_ensure: 'running', + service_name: 'nginx' + } + end + it { is_expected.to contain_service('nginx').with_restart('a restart command') } + end + describe "when service_name => 'nginx14" do let :params do {