Skip to content

Commit 4c6ff5d

Browse files
committed
Adds support for PGDATA changing in config_entry.pp
Ensure that data_directory is set in the config. per GitHub user tbd - PR#510 / PR#494 that was filed against wrong module branch" Adds acceptance test for non default PGDATA, based on alternative_port_spec.rb Fixes typo in acceptance test, its datadir instead of data_directory
1 parent 5d4a543 commit 4c6ff5d

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

manifests/server/config.pp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
$version = $postgresql::server::_version
1616
$manage_pg_hba_conf = $postgresql::server::manage_pg_hba_conf
1717
$manage_pg_ident_conf = $postgresql::server::manage_pg_ident_conf
18+
$datadir = $postgresql::server::datadir
1819

1920
if ($manage_pg_hba_conf == true) {
2021
# Prepare the main pg_hba file
@@ -100,6 +101,9 @@
100101
postgresql::server::config_entry { 'port':
101102
value => $port,
102103
}
104+
postgresql::server::config_entry { 'data_directory':
105+
value => $datadir,
106+
}
103107

104108
# RedHat-based systems hardcode some PG* variables in the init script, and need to be overriden
105109
# in /etc/sysconfig/pgsql/postgresql. Create a blank file so we can manage it with augeas later.

manifests/server/config_entry.pp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,27 @@
8686
notify => Class['postgresql::server::service'],
8787
before => Class['postgresql::server::reload'],
8888
}
89+
} else {
90+
if $name == 'data_directory' {
91+
# We need to force postgresql to stop before updating the data directory
92+
# otherwise init script breaks
93+
exec { "postgresql_${name}":
94+
command => "service ${::postgresql::server::service_name} stop",
95+
onlyif => "service ${::postgresql::server::service_name} status",
96+
unless => "grep 'PGDATA=${value}' /etc/sysconfig/pgsql/postgresql",
97+
path => '/sbin:/bin:/usr/bin:/usr/local/bin',
98+
require => File['/etc/sysconfig/pgsql/postgresql'],
99+
} ->
100+
augeas { 'override PGDATA in /etc/sysconfig/pgsql/postgresql':
101+
lens => 'Shellvars.lns',
102+
incl => '/etc/sysconfig/pgsql/*',
103+
context => '/files/etc/sysconfig/pgsql/postgresql',
104+
changes => "set PGDATA ${value}",
105+
require => File['/etc/sysconfig/pgsql/postgresql'],
106+
notify => Class['postgresql::server::service'],
107+
before => Class['postgresql::server::reload'],
108+
}
109+
}
89110
}
90111
}
91112
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
require 'spec_helper_acceptance'
2+
3+
# These tests ensure that postgres can change itself to an alternative pgdata
4+
# location properly.
5+
describe 'postgres::server', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
6+
it 'on an alternative pgdata location' do
7+
pp = <<-EOS
8+
class { 'postgresql::server': datadir => '/var/pgsql' }
9+
EOS
10+
11+
apply_manifest(pp, :catch_failures => true)
12+
apply_manifest(pp, :catch_changes => true)
13+
end
14+
15+
it 'can connect with psql' do
16+
psql('--command="\l" postgres', 'postgres') do |r|
17+
expect(r.stdout).to match(/List of databases/)
18+
end
19+
end
20+
21+
end

0 commit comments

Comments
 (0)