|
17 | 17 | # @param user Overrides the default PostgreSQL super user and owner of PostgreSQL related files in the file system.
|
18 | 18 | # @param group Overrides the default postgres user group to be used for related files in the file system.
|
19 | 19 | # @param module_workdir Working directory for the PostgreSQL module
|
| 20 | +# @param auth_host auth method used by default for host authorization |
| 21 | +# @param auth_local auth method used by default for local authorization |
| 22 | +# @param lc_messages locale used for logging and system messages |
| 23 | +# @param username username of user running the postgres instance |
20 | 24 | # lint:endignore:140chars
|
21 | 25 | define postgresql::server::instance::initdb (
|
| 26 | + Optional[String[1]] $auth_host = $postgresql::server::auth_host, |
| 27 | + Optional[String[1]] $auth_local = $postgresql::server::auth_local, |
22 | 28 | Boolean $needs_initdb = $postgresql::server::needs_initdb,
|
23 | 29 | Variant[String[1], Stdlib::Absolutepath] $initdb_path = $postgresql::server::initdb_path,
|
24 | 30 | String[1] $datadir = $postgresql::server::datadir,
|
|
28 | 34 | Boolean $manage_logdir = $postgresql::server::manage_logdir,
|
29 | 35 | Boolean $manage_xlogdir = $postgresql::server::manage_xlogdir,
|
30 | 36 | Optional[String[1]] $encoding = $postgresql::server::encoding,
|
| 37 | + Optional[String[1]] $lc_messages = $postgresql::server::lc_messages, |
31 | 38 | Optional[String[1]] $locale = $postgresql::server::locale,
|
32 | 39 | Optional[Boolean] $data_checksums = $postgresql::server::data_checksums,
|
33 | 40 | String[1] $group = $postgresql::server::group,
|
34 | 41 | String[1] $user = $postgresql::server::user,
|
| 42 | + Optional[String[1]] $username = $postgresql::server::username, |
35 | 43 | String[1] $module_workdir = $postgresql::server::module_workdir,
|
36 | 44 | ) {
|
37 | 45 | if $facts['os']['family'] == 'RedHat' and $facts['os']['selinux']['enabled'] == true {
|
38 | 46 | $seltype = 'postgresql_db_t'
|
39 | 47 | $logdir_type = 'postgresql_log_t'
|
40 |
| - } |
41 |
| - |
42 |
| - else { |
| 48 | + } else { |
43 | 49 | $seltype = undef
|
44 | 50 | $logdir_type = undef
|
45 | 51 | }
|
46 | 52 |
|
47 |
| - if($manage_datadir) { |
| 53 | + if $manage_datadir { |
48 | 54 | # Make sure the data directory exists, and has the correct permissions.
|
49 | 55 | file { $datadir:
|
50 | 56 | ensure => directory,
|
|
64 | 70 | }
|
65 | 71 | }
|
66 | 72 |
|
67 |
| - if($xlogdir) { |
68 |
| - if($manage_xlogdir) { |
| 73 | + if $xlogdir { |
| 74 | + # The xlogdir need to be present before initdb runs. |
| 75 | + # If xlogdir is default it's created by package installer |
| 76 | + $require_before_initdb = [$datadir, $xlogdir] |
| 77 | + if$manage_xlogdir { |
69 | 78 | # Make sure the xlog directory exists, and has the correct permissions.
|
70 | 79 | file { $xlogdir:
|
71 | 80 | ensure => directory,
|
|
84 | 93 | seltype => $seltype,
|
85 | 94 | }
|
86 | 95 | }
|
| 96 | + } else { |
| 97 | + $require_before_initdb = [$datadir] |
87 | 98 | }
|
88 | 99 |
|
89 |
| - if($logdir) { |
90 |
| - if($manage_logdir) { |
| 100 | + if $logdir { |
| 101 | + if $manage_logdir { |
91 | 102 | # Make sure the log directory exists, and has the correct permissions.
|
92 | 103 | file { $logdir:
|
93 | 104 | ensure => directory,
|
|
106 | 117 | }
|
107 | 118 | }
|
108 | 119 |
|
109 |
| - if($needs_initdb) { |
| 120 | + if $needs_initdb { |
110 | 121 | # Build up the initdb command.
|
111 | 122 | #
|
112 | 123 | # We optionally add the locale switch if specified. Older versions of the
|
113 | 124 | # initdb command don't accept this switch. So if the user didn't pass the
|
114 | 125 | # parameter, lets not pass the switch at all.
|
115 |
| - $ic_base = "${initdb_path} --pgdata '${datadir}'" |
116 |
| - $ic_xlog = $xlogdir ? { |
117 |
| - undef => $ic_base, |
118 |
| - default => "${ic_base} -X '${xlogdir}'" |
| 126 | + |
| 127 | + $auth_host_parameter = $auth_host ? { |
| 128 | + undef => undef, |
| 129 | + default => "--auth-host '${auth_host}'" |
119 | 130 | }
|
120 | 131 |
|
121 |
| - # The xlogdir need to be present before initdb runs. |
122 |
| - # If xlogdir is default it's created by package installer |
123 |
| - if($xlogdir) { |
124 |
| - $require_before_initdb = [$datadir, $xlogdir] |
125 |
| - } else { |
126 |
| - $require_before_initdb = [$datadir] |
| 132 | + $auth_local_parameter = $auth_local ? { |
| 133 | + undef => undef, |
| 134 | + default => "--auth-local '${auth_local}'" |
| 135 | + } |
| 136 | + |
| 137 | + $data_checksums_parameter = $data_checksums ? { |
| 138 | + undef => undef, |
| 139 | + false => undef, |
| 140 | + default => '--data-checksums' |
127 | 141 | }
|
128 | 142 |
|
| 143 | + $datadir_parameter = "--pgdata '${datadir}'" |
| 144 | + |
129 | 145 | # PostgreSQL 11 no longer allows empty encoding
|
130 |
| - $ic_encoding = $encoding ? { |
131 |
| - undef => $ic_xlog, |
132 |
| - default => "${ic_xlog} --encoding '${encoding}'" |
| 146 | + $encoding_parameter = $encoding ? { |
| 147 | + undef => undef, |
| 148 | + default => "--encoding '${encoding}'" |
133 | 149 | }
|
134 | 150 |
|
135 |
| - $ic_locale = $locale ? { |
136 |
| - undef => $ic_encoding, |
137 |
| - default => "${ic_encoding} --locale '${locale}'" |
| 151 | + $lc_messages_parameter = $locale ? { |
| 152 | + undef => undef, |
| 153 | + default => "--lc-messages '${lc_messages}'" |
138 | 154 | }
|
139 | 155 |
|
140 |
| - $initdb_command = $data_checksums ? { |
141 |
| - undef => $ic_locale, |
142 |
| - false => $ic_locale, |
143 |
| - default => "${ic_locale} --data-checksums" |
| 156 | + $locale_parameter = $locale ? { |
| 157 | + undef => undef, |
| 158 | + default => "--locale '${locale}'" |
144 | 159 | }
|
145 | 160 |
|
| 161 | + $username_parameter = $username ? { |
| 162 | + undef => undef, |
| 163 | + default => "--username '${username}'" |
| 164 | + } |
| 165 | + |
| 166 | + $xlogdir_parameter = $xlogdir ? { |
| 167 | + undef => undef, |
| 168 | + default => "-X '${xlogdir}'" |
| 169 | + } |
| 170 | + |
| 171 | + $initdb_command = "${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 |
| 172 | + |
146 | 173 | # This runs the initdb command, we use the existance of the PG_VERSION
|
147 | 174 | # file to ensure we don't keep running this command.
|
148 | 175 | exec { 'postgresql_initdb':
|
|
0 commit comments