|
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 ( |
22 | 26 | Boolean $needs_initdb = $postgresql::server::needs_initdb, |
|
37 | 41 | if $facts['os']['family'] == 'RedHat' and $facts['os']['selinux']['enabled'] == true { |
38 | 42 | $seltype = 'postgresql_db_t' |
39 | 43 | $logdir_type = 'postgresql_log_t' |
40 | | - } |
41 | | - |
42 | | - else { |
| 44 | + } else { |
43 | 45 | $seltype = undef |
44 | 46 | $logdir_type = undef |
45 | 47 | } |
46 | 48 |
|
47 | | - if($manage_datadir) { |
| 49 | + if $manage_datadir { |
48 | 50 | # Make sure the data directory exists, and has the correct permissions. |
49 | 51 | file { $datadir: |
50 | 52 | ensure => directory, |
|
64 | 66 | } |
65 | 67 | } |
66 | 68 |
|
67 | | - if($xlogdir) { |
68 | | - if($manage_xlogdir) { |
| 69 | + if $xlogdir { |
| 70 | + # The xlogdir need to be present before initdb runs. |
| 71 | + # If xlogdir is default it's created by package installer |
| 72 | + $require_before_initdb = [$datadir, $xlogdir] |
| 73 | + if$manage_xlogdir { |
69 | 74 | # Make sure the xlog directory exists, and has the correct permissions. |
70 | 75 | file { $xlogdir: |
71 | 76 | ensure => directory, |
|
84 | 89 | seltype => $seltype, |
85 | 90 | } |
86 | 91 | } |
| 92 | + } else { |
| 93 | + $require_before_initdb = [$datadir] |
87 | 94 | } |
88 | 95 |
|
89 | | - if($logdir) { |
90 | | - if($manage_logdir) { |
| 96 | + if $logdir { |
| 97 | + if $manage_logdir { |
91 | 98 | # Make sure the log directory exists, and has the correct permissions. |
92 | 99 | file { $logdir: |
93 | 100 | ensure => directory, |
|
106 | 113 | } |
107 | 114 | } |
108 | 115 |
|
109 | | - if($needs_initdb) { |
| 116 | + if $needs_initdb { |
110 | 117 | # Build up the initdb command. |
111 | 118 | # |
112 | 119 | # We optionally add the locale switch if specified. Older versions of the |
113 | 120 | # initdb command don't accept this switch. So if the user didn't pass the |
114 | 121 | # 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}'" |
| 122 | + |
| 123 | + $auth_host_parameter = $auth_host ? { |
| 124 | + undef => undef, |
| 125 | + default => "--auth-host '${auth_host}'" |
119 | 126 | } |
120 | 127 |
|
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] |
| 128 | + $auth_local_parameter = $auth_local ? { |
| 129 | + undef => undef, |
| 130 | + default => "--auth-local '${auth_local}'" |
| 131 | + } |
| 132 | + |
| 133 | + $data_checksums_parameter = $data_checksums ? { |
| 134 | + undef => undef, |
| 135 | + false => undef, |
| 136 | + default => '--data-checksums' |
127 | 137 | } |
128 | 138 |
|
| 139 | + $datadir_parameter = "--pgdata '${datadir}'" |
| 140 | + |
129 | 141 | # PostgreSQL 11 no longer allows empty encoding |
130 | | - $ic_encoding = $encoding ? { |
131 | | - undef => $ic_xlog, |
132 | | - default => "${ic_xlog} --encoding '${encoding}'" |
| 142 | + $encoding_parameter = $encoding ? { |
| 143 | + undef => undef, |
| 144 | + default => "--encoding '${encoding}'" |
133 | 145 | } |
134 | 146 |
|
135 | | - $ic_locale = $locale ? { |
136 | | - undef => $ic_encoding, |
137 | | - default => "${ic_encoding} --locale '${locale}'" |
| 147 | + $lc_messages_parameter = $locale ? { |
| 148 | + undef => undef, |
| 149 | + default => "--lc-messages '${lc_messages}'" |
138 | 150 | } |
139 | 151 |
|
140 | | - $initdb_command = $data_checksums ? { |
141 | | - undef => $ic_locale, |
142 | | - false => $ic_locale, |
143 | | - default => "${ic_locale} --data-checksums" |
| 152 | + $locale_parameter = $locale ? { |
| 153 | + undef => undef, |
| 154 | + default => "--locale '${locale}'" |
144 | 155 | } |
145 | 156 |
|
| 157 | + $username_parameter = $username ? { |
| 158 | + undef => undef, |
| 159 | + default => "--username '${username}'" |
| 160 | + } |
| 161 | + |
| 162 | + $xlogdir_parameter = $xlogdir ? { |
| 163 | + undef => undef, |
| 164 | + default => "-X '${xlogdir}'" |
| 165 | + } |
| 166 | + |
| 167 | + $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 |
| 168 | + |
146 | 169 | # This runs the initdb command, we use the existance of the PG_VERSION |
147 | 170 | # file to ensure we don't keep running this command. |
148 | 171 | exec { 'postgresql_initdb': |
|
0 commit comments