Skip to content

Adds support for PGDATA changing #514

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 30, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions manifests/server/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
$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
Expand Down Expand Up @@ -100,6 +101,9 @@
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.
Expand Down
21 changes: 21 additions & 0 deletions manifests/server/config_entry.pp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,27 @@
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'],
}
}
}
}
}
Expand Down
25 changes: 25 additions & 0 deletions spec/acceptance/alternative_pgdata_spec.rb
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions spec/unit/defines/server/config_entry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@
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' }}

Expand Down