2013-08-27 22:43:47 +02:00
|
|
|
# PRIVATE CLASS: do not call directly
|
|
|
|
class postgresql::server::initdb {
|
|
|
|
$needs_initdb = $postgresql::server::needs_initdb
|
|
|
|
$initdb_path = $postgresql::server::initdb_path
|
|
|
|
$datadir = $postgresql::server::datadir
|
2013-09-25 19:00:24 +02:00
|
|
|
$xlogdir = $postgresql::server::xlogdir
|
2013-08-27 22:43:47 +02:00
|
|
|
$encoding = $postgresql::server::encoding
|
|
|
|
$locale = $postgresql::server::locale
|
|
|
|
$group = $postgresql::server::group
|
|
|
|
$user = $postgresql::server::user
|
|
|
|
|
2014-07-02 16:45:07 +02:00
|
|
|
# Make sure the data directory exists, and has the correct permissions.
|
|
|
|
file { $datadir:
|
|
|
|
ensure => directory,
|
|
|
|
owner => $user,
|
|
|
|
group => $group,
|
|
|
|
mode => '0700',
|
|
|
|
}
|
|
|
|
|
|
|
|
if($xlogdir) {
|
|
|
|
# Make sure the xlog directory exists, and has the correct permissions.
|
|
|
|
file { $xlogdir:
|
2013-09-14 07:33:46 +02:00
|
|
|
ensure => directory,
|
|
|
|
owner => $user,
|
|
|
|
group => $group,
|
2013-09-21 19:45:35 +02:00
|
|
|
mode => '0700',
|
2013-09-14 07:33:46 +02:00
|
|
|
}
|
2014-07-02 16:45:07 +02:00
|
|
|
}
|
2013-09-14 07:33:46 +02:00
|
|
|
|
2014-07-02 16:45:07 +02:00
|
|
|
if($needs_initdb) {
|
|
|
|
# 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}'"
|
|
|
|
$ic_xlog = $xlogdir ? {
|
|
|
|
undef => $ic_base,
|
|
|
|
default => "${ic_base} --xlogdir '${xlogdir}'"
|
2013-08-27 22:43:47 +02:00
|
|
|
}
|
2014-08-19 09:38:05 +02:00
|
|
|
|
|
|
|
# The xlogdir need to be present before initdb runs.
|
|
|
|
# If xlogdir is default it's created by package installer
|
|
|
|
if($xlogdir) {
|
|
|
|
$require_before_initdb = [$datadir, $xlogdir]
|
|
|
|
} else {
|
|
|
|
$require_before_initdb = [$datadir]
|
|
|
|
}
|
|
|
|
|
2014-07-02 16:45:07 +02:00
|
|
|
$initdb_command = $locale ? {
|
|
|
|
undef => $ic_xlog,
|
|
|
|
default => "${ic_xlog} --locale '${locale}'"
|
2013-08-27 22:43:47 +02:00
|
|
|
}
|
2013-09-25 19:00:24 +02:00
|
|
|
|
2014-07-02 16:45:07 +02:00
|
|
|
# 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,
|
2014-08-19 09:38:05 +02:00
|
|
|
require => File[$require_before_initdb],
|
2013-09-25 19:00:24 +02:00
|
|
|
}
|
2013-08-27 22:43:47 +02:00
|
|
|
}
|
|
|
|
}
|