28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
# File 'manifests/server/instance/initdb.pp', line 28
define postgresql::server::instance::initdb (
Optional[String[1]] $auth_host = $postgresql::server::auth_host,
Optional[String[1]] $auth_local = $postgresql::server::auth_local,
Optional[Boolean] $data_checksums = $postgresql::server::data_checksums,
String[1] $datadir = $postgresql::server::datadir,
Optional[String[1]] $encoding = $postgresql::server::encoding,
String[1] $group = $postgresql::server::group,
Variant[String[1], Stdlib::Absolutepath] $initdb_path = $postgresql::server::initdb_path,
Optional[String[1]] $lc_messages = $postgresql::server::lc_messages,
Optional[String[1]] $locale = $postgresql::server::locale,
Optional[String[1]] $logdir = $postgresql::server::logdir,
Boolean $manage_datadir = $postgresql::server::manage_datadir,
Boolean $manage_logdir = $postgresql::server::manage_logdir,
Boolean $manage_xlogdir = $postgresql::server::manage_xlogdir,
String[1] $module_workdir = $postgresql::server::module_workdir,
Boolean $needs_initdb = $postgresql::server::needs_initdb,
String[1] $user = $postgresql::server::user,
Optional[String[1]] $username = $postgresql::server::username,
Optional[String[1]] $xlogdir = $postgresql::server::xlogdir,
) {
if $facts['os']['family'] == 'RedHat' and $facts['os']['selinux']['enabled'] == true {
$seltype = 'postgresql_db_t'
$logdir_type = 'postgresql_log_t'
} else {
$seltype = undef
$logdir_type = undef
}
if $manage_datadir {
# Make sure the data directory exists, and has the correct permissions.
file { $datadir:
ensure => directory,
owner => $user,
group => $group,
mode => '0700',
seltype => $seltype,
}
} else {
# changes an already defined datadir
File <| title == $datadir |> {
ensure => directory,
owner => $user,
group => $group,
mode => '0700',
seltype => $seltype,
}
}
if $xlogdir {
# The xlogdir need to be present before initdb runs.
# If xlogdir is default it's created by package installer
$require_before_initdb = [$datadir, $xlogdir]
if$manage_xlogdir {
# Make sure the xlog directory exists, and has the correct permissions.
file { $xlogdir:
ensure => directory,
owner => $user,
group => $group,
mode => '0700',
seltype => $seltype,
}
} else {
# changes an already defined xlogdir
File <| title == $xlogdir |> {
ensure => directory,
owner => $user,
group => $group,
mode => '0700',
seltype => $seltype,
}
}
} else {
$require_before_initdb = [$datadir]
}
if $logdir {
if $manage_logdir {
# Make sure the log directory exists, and has the correct permissions.
file { $logdir:
ensure => directory,
owner => $user,
group => $group,
seltype => $logdir_type,
}
} else {
# changes an already defined logdir
File <| title == $logdir |> {
ensure => directory,
owner => $user,
group => $group,
seltype => $logdir_type,
}
}
}
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.
$auth_host_parameter = $auth_host ? {
undef => undef,
default => "--auth-host '${auth_host}'"
}
$auth_local_parameter = $auth_local ? {
undef => undef,
default => "--auth-local '${auth_local}'"
}
$data_checksums_parameter = $data_checksums ? {
undef => undef,
false => undef,
default => '--data-checksums'
}
$datadir_parameter = "--pgdata '${datadir}'"
# PostgreSQL 11 no longer allows empty encoding
$encoding_parameter = $encoding ? {
undef => undef,
default => "--encoding '${encoding}'"
}
$lc_messages_parameter = $locale ? {
undef => undef,
default => "--lc-messages '${lc_messages}'"
}
$locale_parameter = $locale ? {
undef => undef,
default => "--locale '${locale}'"
}
$username_parameter = $username ? {
undef => undef,
default => "--username '${username}'"
}
$xlogdir_parameter = $xlogdir ? {
undef => undef,
default => "-X '${xlogdir}'"
}
$initdb_command = squeeze("${initdb_path} ${auth_host_parameter} ${auth_local_parameter} ${data_checksums_parameter} ${datadir_parameter} ${encoding_parameter} ${lc_messages_parameter} ${locale_parameter} ${username_parameter} ${xlogdir_parameter}", ' ') # lint:ignore:140chars
# 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,
require => File[$require_before_initdb],
cwd => $module_workdir,
}
} elsif $encoding != undef {
include postgresql::server::late_initdb
}
}
|