5df36cf1f7
This patch is a fix for the race condition that keeps occuring during postgresql setup. Its very rare on its own, but when you are using this module in a CI environment it happens quite frequently. Basically what happens is that sometimes the service will announce the database has started, but really it is still working in the background. Sometimes the unix socket may not be listening, and sometimes the system is still loading and you get a weird client error. The fix itself is a modification to postgresql::validate_db_connection so that it is able to connect on the local unix socket, plus retry until the database is available. This new and improved validate_db_connection can then be put into the build pipeline (in the service class in particular) to ensure the database is started before continuing on with the remaining steps. This in effect blocks the puppet module from continuing until the postgresql database is fully started and able to receive connections which is perfect. Tests and documentation provided. Signed-off-by: Ken Barber <ken@bob.sh>
38 lines
1.2 KiB
Puppet
38 lines
1.2 KiB
Puppet
# PRIVATE CLASS: do not call directly
|
|
class postgresql::server::service {
|
|
$ensure = $postgresql::server::ensure
|
|
$service_name = $postgresql::server::service_name
|
|
$service_provider = $postgresql::server::service_provider
|
|
$service_status = $postgresql::server::service_status
|
|
$user = $postgresql::server::user
|
|
|
|
$service_ensure = $ensure ? {
|
|
present => true,
|
|
absent => false,
|
|
default => $ensure
|
|
}
|
|
|
|
service { 'postgresqld':
|
|
ensure => $service_ensure,
|
|
name => $service_name,
|
|
enable => $service_ensure,
|
|
provider => $service_provider,
|
|
hasstatus => true,
|
|
status => $service_status,
|
|
}
|
|
|
|
if($service_ensure) {
|
|
# 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,
|
|
sleep => 1,
|
|
tries => 30,
|
|
create_db_first => false,
|
|
require => Service['postgresqld'],
|
|
}
|
|
}
|
|
}
|