Add actual postgresl module from puppetlabs
[mirror/dsa-puppet.git] / 3rdparty / modules / postgresql / manifests / initdb.pp
1 # puppet-postgresql
2 # For all details and documentation:
3 # http://github.com/inkling/puppet-postgresql
4 #
5 # Copyright 2012- Inkling Systems, Inc.
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 #     http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18
19 class postgresql::initdb(
20   $datadir     = $postgresql::params::datadir,
21   $encoding    = $postgresql::params::charset,
22   $group       = $postgresql::params::group,
23   $initdb_path = $postgresql::params::initdb_path,
24   $user        = $postgresql::params::user
25 ) inherits postgresql::params {
26   # Build up the initdb command.
27   #
28   # We optionally add the locale switch if specified. Older versions of the
29   # initdb command don't accept this switch. So if the user didn't pass the
30   # parameter, lets not pass the switch at all.
31   $initdb_command = $postgresql::params::locale ? {
32     undef   => "${initdb_path} --encoding '${encoding}' --pgdata '${datadir}'",
33     default => "${initdb_path} --encoding '${encoding}' --pgdata '${datadir}' --locale '${postgresql::params::locale}'"
34   }
35
36   # This runs the initdb command, we use the existance of the PG_VERSION file to
37   # ensure we don't keep running this command.
38   exec { 'postgresql_initdb':
39     command   => $initdb_command,
40     creates   => "${datadir}/PG_VERSION",
41     user      => $user,
42     group     => $group,
43     logoutput => on_failure,
44   }
45
46   # If we manage the package (which is user configurable) make sure the
47   # package exists first.
48   if defined(Package[$postgresql::params::server_package_name]) {
49     Package[$postgresql::params::server_package_name]->
50       Exec['postgresql_initdb']
51   }
52 }