diff --git a/README.md b/README.md index f73b541..644ef85 100644 --- a/README.md +++ b/README.md @@ -393,6 +393,9 @@ Value to pass through to the `package` resource when creating the server instanc ####`plperl_package_name` This sets the default package name for the PL/Perl extension. Defaults to utilising the operating system default. +####`service_manage` +This setting selects whether Puppet should manage the service. Defaults to `true`. + ####`service_name` This setting can be used to override the default postgresql service name. If not specified, the module will use whatever service name is the default for your OS distro. diff --git a/manifests/params.pp b/manifests/params.pp index a918fb1..85f3955 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -12,6 +12,7 @@ class postgresql::params inherits postgresql::globals { $locale = $locale $service_ensure = 'running' $service_enable = true + $service_manage = true $service_provider = $service_provider $manage_pg_hba_conf = pick($manage_pg_hba_conf, true) $manage_pg_ident_conf = pick($manage_pg_ident_conf, true) diff --git a/manifests/server.pp b/manifests/server.pp index 960815b..0d05558 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -10,6 +10,7 @@ class postgresql::server ( $service_ensure = $postgresql::params::service_ensure, $service_enable = $postgresql::params::service_enable, + $service_manage = $postgresql::params::service_manage, $service_name = $postgresql::params::service_name, $service_provider = $postgresql::params::service_provider, $service_status = $postgresql::params::service_status, diff --git a/manifests/server/service.pp b/manifests/server/service.pp index 18d7529..de06818 100644 --- a/manifests/server/service.pp +++ b/manifests/server/service.pp @@ -2,6 +2,7 @@ class postgresql::server::service { $service_ensure = $postgresql::server::service_ensure $service_enable = $postgresql::server::service_enable + $service_manage = $postgresql::server::service_manage $service_name = $postgresql::server::service_name $service_provider = $postgresql::server::service_provider $service_status = $postgresql::server::service_status @@ -11,30 +12,33 @@ class postgresql::server::service { anchor { 'postgresql::server::service::begin': } - service { 'postgresqld': - ensure => $service_ensure, - enable => $service_enable, - name => $service_name, - provider => $service_provider, - hasstatus => true, - status => $service_status, - } + if $service_manage { - if $service_ensure == 'running' { - # This blocks the class before continuing if chained correctly, making - # sure the service really is 'up' before continuing. - # - # Without it, we may continue doing more work before the database is - # prepared leading to a nasty race condition. - postgresql::validate_db_connection { 'validate_service_is_running': - run_as => $user, - database_name => $default_database, - database_port => $port, - sleep => 1, - tries => 60, - create_db_first => false, - require => Service['postgresqld'], - before => Anchor['postgresql::server::service::end'] + service { 'postgresqld': + ensure => $service_ensure, + enable => $service_enable, + name => $service_name, + provider => $service_provider, + hasstatus => true, + status => $service_status, + } + + if $service_ensure == 'running' { + # This blocks the class before continuing if chained correctly, making + # sure the service really is 'up' before continuing. + # + # Without it, we may continue doing more work before the database is + # prepared leading to a nasty race condition. + postgresql::validate_db_connection { 'validate_service_is_running': + run_as => $user, + database_name => $default_database, + database_port => $port, + sleep => 1, + tries => 60, + create_db_first => false, + require => Service['postgresqld'], + before => Anchor['postgresql::server::service::end'] + } } } diff --git a/spec/unit/classes/server_spec.rb b/spec/unit/classes/server_spec.rb index e6d0852..2fe1e31 100644 --- a/spec/unit/classes/server_spec.rb +++ b/spec/unit/classes/server_spec.rb @@ -39,6 +39,19 @@ describe 'postgresql::server', :type => :class do end end + describe 'service_manage => true' do + let(:params) {{ :service_manage => true }} + it { is_expected.to contain_service('postgresqld') } + end + + describe 'service_manage => false' do + let(:params) {{ :service_manage => false }} + it { is_expected.not_to contain_service('postgresqld') } + it 'shouldnt validate connection' do + is_expected.not_to contain_postgresql__validate_db_connection('validate_service_is_running') + end + end + describe 'package_ensure => absent' do let(:params) do {