From bf1eb1799df5f068b48aed850d9a21a86bc4f842 Mon Sep 17 00:00:00 2001 From: Steve Traylen Date: Sat, 5 Dec 2020 10:16:59 +0100 Subject: [PATCH] Always reload rather than start/stop the nscd service --- data/Debian-family.yaml | 1 + data/RedHat-family.yaml | 1 + manifests/init.pp | 2 ++ manifests/service.pp | 13 ++++++++----- spec/classes/nscd_spec.rb | 4 +++- 5 files changed, 15 insertions(+), 6 deletions(-) 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/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..8f8279d 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,11 @@ 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$}) } + it { is_expected.to contain_service('nscd').with_restart('/bin/systemctl reload nscd') } end end