module-postgresql/manifests/server/initdb.pp
Ken Barber 59c1cbfbf8 Major rewrite to solve order dependencies and unclear public API
This is a very very large change to the module. It started out as a fix to add
postgresl::server::config_entry, and quickly became a rewrite to fix a lot of
ordering issues inherent in the API.

Since this changes the Public API it is considered a backwards compatible
change.

See the upgrading guide in README.md for more details as to what has been
modified in this patch.

Signed-off-by: Ken Barber <ken@bob.sh>
2013-09-14 06:39:15 +01:00

44 lines
1.4 KiB
Puppet

# PRIVATE CLASS: do not call directly
class postgresql::server::initdb {
$ensure = $postgresql::server::ensure
$needs_initdb = $postgresql::server::needs_initdb
$initdb_path = $postgresql::server::initdb_path
$datadir = $postgresql::server::datadir
$encoding = $postgresql::server::encoding
$locale = $postgresql::server::locale
$group = $postgresql::server::group
$user = $postgresql::server::user
# Build up the initdb command.
#
# We optionally add the locale switch if specified. Older versions of the
# initdb command don't accept this switch. So if the user didn't pass the
# parameter, lets not pass the switch at all.
$ic_base = "${initdb_path} --encoding '${encoding}' --pgdata '${datadir}'"
$initdb_command = $locale ? {
undef => $ic_base,
default => "${ic_base} --locale '${locale}'"
}
if($ensure == 'present' or $ensure == true) {
if($needs_initdb) {
# This runs the initdb command, we use the existance of the PG_VERSION
# file to ensure we don't keep running this command.
exec { 'postgresql_initdb':
command => $initdb_command,
creates => "${datadir}/PG_VERSION",
user => $user,
group => $group,
logoutput => on_failure,
}
}
} else {
# Purge data directory if ensure => absent
file { $datadir:
ensure => absent,
recurse => true,
force => true,
}
}
}