Add service_manage parameter

Loosely addresses MODULES-1522
This commit is contained in:
juniorsysadmin 2014-12-05 00:26:37 +11:00
parent 61f86551d8
commit 789543fc45
5 changed files with 45 additions and 23 deletions

View file

@ -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.

View file

@ -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)

View file

@ -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,

View file

@ -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']
}
}
}

View file

@ -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
{