From a4a1168f29c6ce14ef7673cf6877b675f3f41444 Mon Sep 17 00:00:00 2001 From: Steve Traylen Date: Sat, 5 Dec 2020 10:16:59 +0100 Subject: [PATCH 1/2] Always reload rather than start/stop the nscd service --- data/Debian-8.yaml | 2 ++ data/Debian-family.yaml | 1 + data/RedHat-family.yaml | 1 + data/Ubuntu-16.04.yaml | 2 ++ hiera.yaml | 3 ++- manifests/init.pp | 2 ++ manifests/service.pp | 13 ++++++++----- spec/classes/nscd_spec.rb | 9 ++++++++- 8 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 data/Debian-8.yaml create mode 100644 data/Ubuntu-16.04.yaml diff --git a/data/Debian-8.yaml b/data/Debian-8.yaml new file mode 100644 index 0000000..05d3b87 --- /dev/null +++ b/data/Debian-8.yaml @@ -0,0 +1,2 @@ +--- +nscd::service_restart: /usr/sbin/service nscd reload diff --git a/data/Debian-family.yaml b/data/Debian-family.yaml index 32d92e7..e14ddbf 100644 --- a/data/Debian-family.yaml +++ b/data/Debian-family.yaml @@ -1,2 +1,3 @@ --- nscd::user: root +nscd::service_restart: /bin/systemctl reload nscd diff --git a/data/RedHat-family.yaml b/data/RedHat-family.yaml index f0b90b4..4431be7 100644 --- a/data/RedHat-family.yaml +++ b/data/RedHat-family.yaml @@ -1,3 +1,4 @@ --- nscd::user: nscd nscd::logfile: /var/log/nscd.log +nscd::service_restart: /usr/bin/systemctl reload nscd diff --git a/data/Ubuntu-16.04.yaml b/data/Ubuntu-16.04.yaml new file mode 100644 index 0000000..05d3b87 --- /dev/null +++ b/data/Ubuntu-16.04.yaml @@ -0,0 +1,2 @@ +--- +nscd::service_restart: /usr/sbin/service nscd reload diff --git a/hiera.yaml b/hiera.yaml index 422fa92..e339ced 100644 --- a/hiera.yaml +++ b/hiera.yaml @@ -6,9 +6,10 @@ defaults: data_hash: 'yaml_data' hierarchy: + - name: 'Operating System Name Version' + path: '%{facts.os.name}-%{facts.os.release.full}.yaml' - name: 'Operating System Family' path: '%{facts.os.family}-family.yaml' - - name: 'common' path: 'common.yaml' diff --git a/manifests/init.pp b/manifests/init.pp index 7689f9b..4b236a6 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -20,6 +20,7 @@ # @param pkg_ensure state of nscd package. # @param service_ensure state of nscd service ensure # @param service_enable state of nscd service enable +# $param service_restart command to reload nscd service # @param threads number of threads. # @param max_threads maximum number of threads. # @prarm paranoia enable internal restart mode. @@ -32,6 +33,7 @@ # @dbconfig configuration for each of the passwd, group, hosts and service database. class nscd ( + String[1] $service_restart, Nscd::Database $dbconfig, Enum['present','absent','latest'] $pkg_ensure = 'present', Boolean $service_ensure = true, diff --git a/manifests/service.pp b/manifests/service.pp index 3b7fd44..122c497 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -1,12 +1,15 @@ class nscd::service ( - $service_ensure = $nscd::service_ensure, - $service_enable = $nscd::service_enable, - $pkg_ensure = $nscd::pkg_ensure, + $service_ensure = $nscd::service_ensure, + $service_enable = $nscd::service_enable, + $service_restart = $nscd::service_restart, + $pkg_ensure = $nscd::pkg_ensure, ) { if $pkg_ensure != 'absent' { service { 'nscd': - ensure => $service_ensure, - enable => $service_enable, + ensure => $service_ensure, + enable => $service_enable, + restart => $service_restart, + hasrestart => true, } } } diff --git a/spec/classes/nscd_spec.rb b/spec/classes/nscd_spec.rb index 2509ac9..4fedf9a 100644 --- a/spec/classes/nscd_spec.rb +++ b/spec/classes/nscd_spec.rb @@ -12,6 +12,7 @@ it { is_expected.to contain_class('nscd::service') } it { is_expected.to contain_package('nscd').with_ensure('present') } it { is_expected.to contain_service('nscd').with_ensure(true) } + it { is_expected.to contain_service('nscd').with_hasrestart(true) } it { is_expected.to contain_file('/etc/nscd.conf').with_content(%r{^threads\s+5$}) } it { is_expected.to contain_file('/etc/nscd.conf').with_content(%r{^max-threads\s+32$}) } @@ -73,10 +74,16 @@ when 'RedHat' it { is_expected.to contain_file('/etc/nscd.conf').with_content(%r{^logfile\s+/var/log/nscd.log$}) } it { is_expected.to contain_file('/etc/nscd.conf').with_content(%r{^server-user\s+nscd$}) } - + it { is_expected.to contain_service('nscd').with_restart('/usr/bin/systemctl reload nscd') } else it { is_expected.to contain_file('/etc/nscd.conf').without_content(%r{^logfile.*$}) } it { is_expected.to contain_file('/etc/nscd.conf').with_content(%r{^server-user\s+root$}) } + case facts[:os]['release']['full'] + when '16.04', '8' + it { is_expected.to contain_service('nscd').with_restart('/usr/sbin/service nscd reload') } + else + it { is_expected.to contain_service('nscd').with_restart('/bin/systemctl reload nscd') } + end end end From 2f5384caf7c3e8da1fd275f8a6b2d668521e9341 Mon Sep 17 00:00:00 2001 From: Steve Traylen Date: Sat, 5 Dec 2020 12:49:58 +0100 Subject: [PATCH 2/2] fixup --- data/Debian-8.yaml | 2 -- data/Debian-family.yaml | 1 - data/RedHat-family.yaml | 1 - data/Ubuntu-16.04.yaml | 2 -- hiera.yaml | 2 -- manifests/init.pp | 2 +- spec/classes/nscd_spec.rb | 8 +------- 7 files changed, 2 insertions(+), 16 deletions(-) delete mode 100644 data/Debian-8.yaml delete mode 100644 data/Ubuntu-16.04.yaml diff --git a/data/Debian-8.yaml b/data/Debian-8.yaml deleted file mode 100644 index 05d3b87..0000000 --- a/data/Debian-8.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -nscd::service_restart: /usr/sbin/service nscd reload diff --git a/data/Debian-family.yaml b/data/Debian-family.yaml index e14ddbf..32d92e7 100644 --- a/data/Debian-family.yaml +++ b/data/Debian-family.yaml @@ -1,3 +1,2 @@ --- nscd::user: root -nscd::service_restart: /bin/systemctl reload nscd diff --git a/data/RedHat-family.yaml b/data/RedHat-family.yaml index 4431be7..f0b90b4 100644 --- a/data/RedHat-family.yaml +++ b/data/RedHat-family.yaml @@ -1,4 +1,3 @@ --- nscd::user: nscd nscd::logfile: /var/log/nscd.log -nscd::service_restart: /usr/bin/systemctl reload nscd diff --git a/data/Ubuntu-16.04.yaml b/data/Ubuntu-16.04.yaml deleted file mode 100644 index 05d3b87..0000000 --- a/data/Ubuntu-16.04.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -nscd::service_restart: /usr/sbin/service nscd reload diff --git a/hiera.yaml b/hiera.yaml index e339ced..4670840 100644 --- a/hiera.yaml +++ b/hiera.yaml @@ -6,8 +6,6 @@ defaults: data_hash: 'yaml_data' hierarchy: - - name: 'Operating System Name Version' - path: '%{facts.os.name}-%{facts.os.release.full}.yaml' - name: 'Operating System Family' path: '%{facts.os.family}-family.yaml' - name: 'common' diff --git a/manifests/init.pp b/manifests/init.pp index 4b236a6..131c8de 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -33,11 +33,11 @@ # @dbconfig configuration for each of the passwd, group, hosts and service database. class nscd ( - String[1] $service_restart, Nscd::Database $dbconfig, Enum['present','absent','latest'] $pkg_ensure = 'present', Boolean $service_ensure = true, Boolean $service_enable = true, + String[1] $service_restart = '/bin/systemctl reload nscd', String[1] $user = 'root', Optional[String[1]] $stat_user = undef, Integer $threads = 5, diff --git a/spec/classes/nscd_spec.rb b/spec/classes/nscd_spec.rb index 4fedf9a..546c9f2 100644 --- a/spec/classes/nscd_spec.rb +++ b/spec/classes/nscd_spec.rb @@ -13,6 +13,7 @@ it { is_expected.to contain_package('nscd').with_ensure('present') } it { is_expected.to contain_service('nscd').with_ensure(true) } it { is_expected.to contain_service('nscd').with_hasrestart(true) } + it { is_expected.to contain_service('nscd').with_restart('/bin/systemctl reload nscd') } it { is_expected.to contain_file('/etc/nscd.conf').with_content(%r{^threads\s+5$}) } it { is_expected.to contain_file('/etc/nscd.conf').with_content(%r{^max-threads\s+32$}) } @@ -74,16 +75,9 @@ when 'RedHat' it { is_expected.to contain_file('/etc/nscd.conf').with_content(%r{^logfile\s+/var/log/nscd.log$}) } it { is_expected.to contain_file('/etc/nscd.conf').with_content(%r{^server-user\s+nscd$}) } - it { is_expected.to contain_service('nscd').with_restart('/usr/bin/systemctl reload nscd') } else it { is_expected.to contain_file('/etc/nscd.conf').without_content(%r{^logfile.*$}) } it { is_expected.to contain_file('/etc/nscd.conf').with_content(%r{^server-user\s+root$}) } - case facts[:os]['release']['full'] - when '16.04', '8' - it { is_expected.to contain_service('nscd').with_restart('/usr/sbin/service nscd reload') } - else - it { is_expected.to contain_service('nscd').with_restart('/bin/systemctl reload nscd') } - end end end