|
1 | 1 | # lint:ignore:140chars
|
2 |
| -# @param needs_initdb Explicitly calls the initdb operation after server package is installed |
3 |
| -# and before the PostgreSQL service is started. |
4 |
| -# @param initdb_path Specifies the path to the initdb command. |
| 2 | +# @param auth_host auth method used by default for host authorization |
| 3 | +# @param auth_local auth method used by default for local authorization |
| 4 | +# @param data_checksums Boolean. Use checksums on data pages to help detect corruption by the I/O system that would otherwise be silent. |
5 | 5 | # @param datadir PostgreSQL data directory
|
6 |
| -# @param xlogdir PostgreSQL xlog directory |
7 |
| -# @param logdir PostgreSQL log directory |
8 |
| -# @param manage_datadir Set to false if you have file{ $datadir: } already defined |
9 |
| -# @param manage_logdir Set to false if you have file{ $logdir: } already defined |
10 |
| -# @param manage_xlogdir Set to false if you have file{ $xlogdir: } already defined |
11 | 6 | # @param encoding Sets the default encoding for all databases created with this module.
|
12 | 7 | # On certain operating systems this is also used during the template1 initialization, so it becomes a default outside of the module as well.
|
| 8 | +# @param group Overrides the default postgres user group to be used for related files in the file system. |
| 9 | +# @param initdb_path Specifies the path to the initdb command. |
| 10 | +# @param lc_messages locale used for logging and system messages |
13 | 11 | # @param locale Sets the default database locale for all databases created with this module.
|
14 | 12 | # On certain operating systems this is used during the template1 initialization as well, so it becomes a default outside of the module.
|
15 |
| -# @param data_checksums Boolean. Use checksums on data pages to help detect corruption by the I/O system that would otherwise be silent. |
16 | 13 | # Warning: This option is used during initialization by initdb, and cannot be changed later. If set, checksums are calculated for all objects, in all databases.
|
17 |
| -# @param user Overrides the default PostgreSQL super user and owner of PostgreSQL related files in the file system. |
18 |
| -# @param group Overrides the default postgres user group to be used for related files in the file system. |
| 14 | +# @param logdir PostgreSQL log directory |
| 15 | +# @param manage_datadir Set to false if you have file{ $datadir: } already defined |
| 16 | +# @param manage_logdir Set to false if you have file{ $logdir: } already defined |
| 17 | +# @param manage_xlogdir Set to false if you have file{ $xlogdir: } already defined |
19 | 18 | # @param module_workdir Working directory for the PostgreSQL module
|
| 19 | +# @param needs_initdb Explicitly calls the initdb operation after server package is installed |
| 20 | +# and before the PostgreSQL service is started. |
| 21 | +# @param user Overrides the default PostgreSQL super user and owner of PostgreSQL related files in the file system. |
| 22 | +# @param username username of user running the postgres instance |
| 23 | +# @param xlogdir PostgreSQL xlog/WAL directory |
20 | 24 | # lint:endignore:140chars
|
21 | 25 | define postgresql::server::instance::initdb (
|
22 |
| - Boolean $needs_initdb = $postgresql::server::needs_initdb, |
23 |
| - Variant[String[1], Stdlib::Absolutepath] $initdb_path = $postgresql::server::initdb_path, |
| 26 | + Optional[String[1]] $auth_host = $postgresql::server::auth_host, |
| 27 | + Optional[String[1]] $auth_local = $postgresql::server::auth_local, |
| 28 | + Optional[Boolean] $data_checksums = $postgresql::server::data_checksums, |
24 | 29 | String[1] $datadir = $postgresql::server::datadir,
|
25 |
| - Optional[String[1]] $xlogdir = $postgresql::server::xlogdir, |
| 30 | + Optional[String[1]] $encoding = $postgresql::server::encoding, |
| 31 | + String[1] $group = $postgresql::server::group, |
| 32 | + Variant[String[1], Stdlib::Absolutepath] $initdb_path = $postgresql::server::initdb_path, |
| 33 | + Optional[String[1]] $lc_messages = $postgresql::server::lc_messages, |
| 34 | + Optional[String[1]] $locale = $postgresql::server::locale, |
26 | 35 | Optional[String[1]] $logdir = $postgresql::server::logdir,
|
27 | 36 | Boolean $manage_datadir = $postgresql::server::manage_datadir,
|
28 | 37 | Boolean $manage_logdir = $postgresql::server::manage_logdir,
|
29 | 38 | Boolean $manage_xlogdir = $postgresql::server::manage_xlogdir,
|
30 |
| - Optional[String[1]] $encoding = $postgresql::server::encoding, |
31 |
| - Optional[String[1]] $locale = $postgresql::server::locale, |
32 |
| - Optional[Boolean] $data_checksums = $postgresql::server::data_checksums, |
33 |
| - String[1] $group = $postgresql::server::group, |
34 |
| - String[1] $user = $postgresql::server::user, |
35 | 39 | String[1] $module_workdir = $postgresql::server::module_workdir,
|
| 40 | + Boolean $needs_initdb = $postgresql::server::needs_initdb, |
| 41 | + String[1] $user = $postgresql::server::user, |
| 42 | + Optional[String[1]] $username = $postgresql::server::username, |
| 43 | + Optional[String[1]] $xlogdir = $postgresql::server::xlogdir, |
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}'" |
| 149 | + } |
| 150 | + |
| 151 | + $lc_messages_parameter = $locale ? { |
| 152 | + undef => undef, |
| 153 | + default => "--lc-messages '${lc_messages}'" |
133 | 154 | }
|
134 | 155 |
|
135 |
| - $ic_locale = $locale ? { |
136 |
| - undef => $ic_encoding, |
137 |
| - default => "${ic_encoding} --locale '${locale}'" |
| 156 | + $locale_parameter = $locale ? { |
| 157 | + undef => undef, |
| 158 | + default => "--locale '${locale}'" |
138 | 159 | }
|
139 | 160 |
|
140 |
| - $initdb_command = $data_checksums ? { |
141 |
| - undef => $ic_locale, |
142 |
| - false => $ic_locale, |
143 |
| - default => "${ic_locale} --data-checksums" |
| 161 | + $username_parameter = $username ? { |
| 162 | + undef => undef, |
| 163 | + default => "--username '${username}'" |
144 | 164 | }
|
145 | 165 |
|
| 166 | + $xlogdir_parameter = $xlogdir ? { |
| 167 | + undef => undef, |
| 168 | + default => "-X '${xlogdir}'" |
| 169 | + } |
| 170 | + |
| 171 | + $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 |
| 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