Merge pull request #514 from mixacha/pg_data_support
Adds support for PGDATA changing
This commit is contained in:
commit
fb719070a7
4 changed files with 59 additions and 0 deletions
|
@ -15,6 +15,7 @@ class postgresql::server::config {
|
|||
$version = $postgresql::server::_version
|
||||
$manage_pg_hba_conf = $postgresql::server::manage_pg_hba_conf
|
||||
$manage_pg_ident_conf = $postgresql::server::manage_pg_ident_conf
|
||||
$datadir = $postgresql::server::datadir
|
||||
|
||||
if ($manage_pg_hba_conf == true) {
|
||||
# Prepare the main pg_hba file
|
||||
|
@ -100,6 +101,9 @@ class postgresql::server::config {
|
|||
postgresql::server::config_entry { 'port':
|
||||
value => $port,
|
||||
}
|
||||
postgresql::server::config_entry { 'data_directory':
|
||||
value => $datadir,
|
||||
}
|
||||
|
||||
# RedHat-based systems hardcode some PG* variables in the init script, and need to be overriden
|
||||
# in /etc/sysconfig/pgsql/postgresql. Create a blank file so we can manage it with augeas later.
|
||||
|
|
|
@ -86,6 +86,27 @@ define postgresql::server::config_entry (
|
|||
notify => Class['postgresql::server::service'],
|
||||
before => Class['postgresql::server::reload'],
|
||||
}
|
||||
} else {
|
||||
if $name == 'data_directory' {
|
||||
# We need to force postgresql to stop before updating the data directory
|
||||
# otherwise init script breaks
|
||||
exec { "postgresql_${name}":
|
||||
command => "service ${::postgresql::server::service_name} stop",
|
||||
onlyif => "service ${::postgresql::server::service_name} status",
|
||||
unless => "grep 'PGDATA=${value}' /etc/sysconfig/pgsql/postgresql",
|
||||
path => '/sbin:/bin:/usr/bin:/usr/local/bin',
|
||||
require => File['/etc/sysconfig/pgsql/postgresql'],
|
||||
} ->
|
||||
augeas { 'override PGDATA in /etc/sysconfig/pgsql/postgresql':
|
||||
lens => 'Shellvars.lns',
|
||||
incl => '/etc/sysconfig/pgsql/*',
|
||||
context => '/files/etc/sysconfig/pgsql/postgresql',
|
||||
changes => "set PGDATA ${value}",
|
||||
require => File['/etc/sysconfig/pgsql/postgresql'],
|
||||
notify => Class['postgresql::server::service'],
|
||||
before => Class['postgresql::server::reload'],
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
25
spec/acceptance/alternative_pgdata_spec.rb
Normal file
25
spec/acceptance/alternative_pgdata_spec.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
# These tests ensure that postgres can change itself to an alternative pgdata
|
||||
# location properly.
|
||||
describe 'postgres::server', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
it 'on an alternative pgdata location' do
|
||||
pp = <<-EOS
|
||||
class { 'postgresql::server': datadir => '/var/pgsql' }
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
end
|
||||
|
||||
describe "Alternate Directory" do
|
||||
File.directory?("/var/pgsql").should be true
|
||||
end
|
||||
|
||||
it 'can connect with psql' do
|
||||
psql('--command="\l" postgres', 'postgres') do |r|
|
||||
expect(r.stdout).to match(/List of databases/)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -88,6 +88,15 @@ describe 'postgresql::server::config_entry', :type => :define do
|
|||
end
|
||||
end
|
||||
|
||||
context "data_directory" do
|
||||
let(:params) {{ :ensure => 'present', :name => 'data_directory_spec', :value => '/var/pgsql' }}
|
||||
|
||||
it 'stops postgresql and changes the data directory' do
|
||||
is_expected.to contain_exec('postgresql_data_directory')
|
||||
is_expected.to contain_augeas('override PGDATA in /etc/sysconfig/pgsql/postgresql')
|
||||
end
|
||||
end
|
||||
|
||||
context "passes values through appropriately" do
|
||||
let(:params) {{ :ensure => 'present', :name => 'check_function_bodies', :value => 'off' }}
|
||||
|
||||
|
|
Loading…
Reference in a new issue