Merge platform.pp back into params.pp
Nan showed me a trick that will let us keep all of that param stuff inside of params.pp, make it a parameterized class, and still support the ability for users to specify a custom (non-system-default) pg version. This commit takes the first step towards that pattern by consolidating platform.pp and params.pp. (Everything old is new again!)
This commit is contained in:
parent
fa24f24397
commit
18167c7a3e
12 changed files with 99 additions and 211 deletions
|
@ -39,27 +39,11 @@ class postgresql::config(
|
|||
$listen_addresses = $postgresql::params::listen_addresses,
|
||||
$ipv4acls = $postgresql::params::ipv4acls,
|
||||
$ipv6acls = $postgresql::params::ipv6acls,
|
||||
$pg_hba_conf_path = '',
|
||||
$postgresql_conf_path = '',
|
||||
$pg_hba_conf_path = $postgresql::params::pg_hba_conf_path,
|
||||
$postgresql_conf_path = $postgresql::params::postgresql_conf_path,
|
||||
$manage_redhat_firewall = $postgresql::params::manage_redhat_firewall
|
||||
) inherits postgresql::params {
|
||||
|
||||
include postgresql::platform
|
||||
|
||||
if ! $pg_hba_conf_path {
|
||||
$pg_hba_conf_path_real = $postgresql::platform::pg_hba_conf_path
|
||||
}
|
||||
else {
|
||||
$pg_hba_conf_path_real = $pg_hba_conf_path
|
||||
}
|
||||
|
||||
if ! $postgresql_conf_path {
|
||||
$postgresql_conf_path_real = $postgresql::platform::postgresql_conf_path
|
||||
}
|
||||
else {
|
||||
$postgresql_conf_path_real = $postgresql_conf_path
|
||||
}
|
||||
|
||||
# Basically, all this class needs to handle is passing parameters on
|
||||
# to the "beforeservice" and "afterservice" classes, and ensure
|
||||
# the proper ordering.
|
||||
|
@ -70,8 +54,8 @@ class postgresql::config(
|
|||
listen_addresses => $listen_addresses,
|
||||
ipv4acls => $ipv4acls,
|
||||
ipv6acls => $ipv6acls,
|
||||
pg_hba_conf_path => $pg_hba_conf_path_real,
|
||||
postgresql_conf_path => $postgresql_conf_path_real,
|
||||
pg_hba_conf_path => $pg_hba_conf_path,
|
||||
postgresql_conf_path => $postgresql_conf_path,
|
||||
manage_redhat_firewall => $manage_redhat_firewall,
|
||||
}
|
||||
|
||||
|
|
|
@ -23,13 +23,13 @@ define postgresql::database(
|
|||
$dbname = $title,
|
||||
$charset = 'UTF8')
|
||||
{
|
||||
include postgresql::platform
|
||||
include postgresql::params
|
||||
|
||||
if ($::postgres_default_version != '8.1') {
|
||||
$locale_option = '--locale=C'
|
||||
}
|
||||
|
||||
$createdb_command = "${postgresql::platform::createdb_path} --template=template0 --encoding '${charset}' ${locale_option} '${dbname}'"
|
||||
$createdb_command = "${postgresql::params::createdb_path} --template=template0 --encoding '${charset}' ${locale_option} '${dbname}'"
|
||||
|
||||
postgresql_psql { "Check for existence of db '$dbname'":
|
||||
command => "SELECT 1",
|
||||
|
|
|
@ -13,20 +13,12 @@
|
|||
# Sample Usage:
|
||||
#
|
||||
class postgresql::devel(
|
||||
$package_name = '',
|
||||
$package_name = $postgresql::params::devel_package_name,
|
||||
$package_ensure = 'present'
|
||||
) {
|
||||
|
||||
if ! $package_name {
|
||||
include postgresql::platform
|
||||
$package_name_real = $postgresql::platform::devel_package_name
|
||||
}
|
||||
else {
|
||||
$package_name_real = $package_name
|
||||
}
|
||||
) inherits postgresql::params {
|
||||
|
||||
package { 'postgresql_devel':
|
||||
ensure => $package_ensure,
|
||||
name => $package_name_real,
|
||||
name => $package_name,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,21 +17,13 @@
|
|||
#
|
||||
class postgresql (
|
||||
$version = $::postgres_default_version,
|
||||
$package_name = '',
|
||||
$package_name = $postgresql::params::client_package_name,
|
||||
$package_ensure = 'present'
|
||||
) inherits postgresql::params {
|
||||
|
||||
if ! $package_name {
|
||||
include postgresql::platform
|
||||
$package_name_real = $postgresql::platform::client_package_name
|
||||
}
|
||||
else {
|
||||
$package_name_real = $package_name
|
||||
}
|
||||
|
||||
package { 'postgresql_client':
|
||||
ensure => $package_ensure,
|
||||
name => $package_name_real,
|
||||
name => $package_name,
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,32 +17,17 @@
|
|||
# limitations under the License.
|
||||
|
||||
class postgresql::initdb(
|
||||
$datadir = '',
|
||||
$datadir = $postgresql::params::datadir,
|
||||
$encoding = 'UTF8',
|
||||
$group = 'postgres',
|
||||
$initdb_path = '',
|
||||
$options = '',
|
||||
$initdb_path = $postgresql::params::initdb_path,
|
||||
$user = 'postgres'
|
||||
) inherits postgresql::params {
|
||||
|
||||
include postgresql::platform
|
||||
|
||||
if ! $datadir {
|
||||
$datadir_real = $postgresql::platform::datadir
|
||||
} else {
|
||||
$datadir_real = $datadir
|
||||
}
|
||||
|
||||
if ! $initdb_path {
|
||||
$initdb_path_real = $postgresql::platform::initdb_path
|
||||
} else {
|
||||
$initdb_path_real = $initdb_path
|
||||
}
|
||||
|
||||
$initdb_command = "${initdb_path_real} --encoding '${encoding}' --pgdata '${datadir_real}'"
|
||||
$initdb_command = "${initdb_path} --encoding '${encoding}' --pgdata '${datadir}'"
|
||||
|
||||
exec { $initdb_command:
|
||||
creates => "${datadir_real}/PG_VERSION",
|
||||
creates => "${datadir}/PG_VERSION",
|
||||
user => $user,
|
||||
group => $group
|
||||
}
|
||||
|
|
|
@ -31,22 +31,87 @@ class postgresql::params {
|
|||
fail "No value for postgres_default_version facter fact; it's possible that you don't have pluginsync enabled."
|
||||
}
|
||||
|
||||
|
||||
if defined(Class[Postgresql::Package_source_info]) {
|
||||
$version = $postgresql::package_source_info::version
|
||||
} else {
|
||||
$version = $::postgres_default_version
|
||||
}
|
||||
|
||||
|
||||
case $::operatingsystem {
|
||||
default: {
|
||||
$service_provider = undef
|
||||
}
|
||||
}
|
||||
|
||||
case $::osfamily {
|
||||
'RedHat': {
|
||||
$needs_initdb = true
|
||||
$firewall_supported = true
|
||||
$persist_firewall_command = '/sbin/iptables-save > /etc/sysconfig/iptables'
|
||||
$persist_firewall_command = '/sbin/iptables-save > /etc/sysconfig/iptables'
|
||||
|
||||
if $version == $::postgres_default_version {
|
||||
$client_package_name = 'postgresql'
|
||||
$server_package_name = 'postgresql-server'
|
||||
$devel_package_name = 'postgresql-devel'
|
||||
$service_name = 'postgresql'
|
||||
$bindir = '/usr/bin'
|
||||
$datadir = '/var/lib/pgsql/data'
|
||||
$confdir = $datadir
|
||||
} else {
|
||||
$version_parts = split($version, '[.]')
|
||||
$package_version = "${version_parts[0]}${version_parts[1]}"
|
||||
$client_package_name = "postgresql${package_version}"
|
||||
$server_package_name = "postgresql${package_version}-server"
|
||||
$devel_package_name = "postgresql${package_version}-devel"
|
||||
$service_name = "postgresql-${version}"
|
||||
$bindir = "/usr/pgsql-${version}/bin"
|
||||
$datadir = "/var/lib/pgsql/${version}/data"
|
||||
$confdir = $datadir
|
||||
}
|
||||
|
||||
$service_status = undef
|
||||
}
|
||||
|
||||
'Debian': {
|
||||
$needs_initdb = false
|
||||
$firewall_supported = false
|
||||
# TODO: not exactly sure yet what the right thing to do for Debian/Ubuntu is.
|
||||
#$persist_firewall_command = '/sbin/iptables-save > /etc/iptables/rules.v4'
|
||||
|
||||
|
||||
case $::operatingsystem {
|
||||
'Debian': {
|
||||
$service_name = 'postgresql'
|
||||
}
|
||||
|
||||
'Ubuntu': {
|
||||
case $::lsbmajdistrelease {
|
||||
# thanks, ubuntu
|
||||
'10': { $service_name = "postgresql-${::postgres_default_version}" }
|
||||
default: { $service_name = 'postgresql' }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$client_package_name = 'postgresql-client'
|
||||
$server_package_name = 'postgresql'
|
||||
$devel_package_name = 'libpq-dev'
|
||||
$bindir = "/usr/lib/postgresql/${::postgres_default_version}/bin"
|
||||
$datadir = "/var/lib/postgresql/${::postgres_default_version}/main"
|
||||
$confdir = "/etc/postgresql/${::postgres_default_version}/main"
|
||||
$service_status = "/etc/init.d/${service_name} status | /bin/egrep -q 'Running clusters: .+'"
|
||||
}
|
||||
|
||||
default: {
|
||||
fail("Unsupported osfamily: ${::osfamily} operatingsystem: ${::operatingsystem}, module ${module_name} currently only supports osfamily RedHat and Debian")
|
||||
}
|
||||
}
|
||||
|
||||
$initdb_path = "${bindir}/initdb"
|
||||
$createdb_path = "${bindir}/createdb"
|
||||
$psql_path = "${bindir}/psql"
|
||||
$pg_hba_conf_path = "${confdir}/pg_hba.conf"
|
||||
$postgresql_conf_path = "${confdir}/postgresql.conf"
|
||||
}
|
||||
|
|
|
@ -1,95 +0,0 @@
|
|||
# Class: postgresql::platform
|
||||
#
|
||||
# An abstraction for the postgresql platform. Based on the desired version of
|
||||
# postgres, whether it is part of the OS distro, OS distro differences / defaults,
|
||||
# etc., figures out the package names, service names, paths, etc.
|
||||
#
|
||||
# Parameters:
|
||||
#
|
||||
# Actions:
|
||||
#
|
||||
# Requires:
|
||||
#
|
||||
# Sample Usage:
|
||||
#
|
||||
class postgresql::platform {
|
||||
|
||||
if defined(Class[Postgresql::Package_source_info]) {
|
||||
$version = $postgresql::package_source_info::version
|
||||
} else {
|
||||
$version = $::postgres_default_version
|
||||
}
|
||||
|
||||
|
||||
case $::operatingsystem {
|
||||
default: {
|
||||
$service_provider = undef
|
||||
}
|
||||
}
|
||||
|
||||
case $::osfamily {
|
||||
'RedHat': {
|
||||
if $version == $::postgres_default_version {
|
||||
$client_package_name = 'postgresql'
|
||||
$server_package_name = 'postgresql-server'
|
||||
$devel_package_name = 'postgresql-devel'
|
||||
$service_name = 'postgresql'
|
||||
$bindir = '/usr/bin'
|
||||
$datadir = '/var/lib/pgsql/data'
|
||||
$confdir = $datadir
|
||||
} else {
|
||||
$version_parts = split($version, '[.]')
|
||||
$package_version = "${version_parts[0]}${version_parts[1]}"
|
||||
$client_package_name = "postgresql${package_version}"
|
||||
$server_package_name = "postgresql${package_version}-server"
|
||||
$devel_package_name = "postgresql${package_version}-devel"
|
||||
$service_name = "postgresql-${version}"
|
||||
$bindir = "/usr/pgsql-${version}/bin"
|
||||
$datadir = "/var/lib/pgsql/${version}/data"
|
||||
$confdir = $datadir
|
||||
}
|
||||
|
||||
$service_status = undef
|
||||
}
|
||||
|
||||
'Debian': {
|
||||
|
||||
case $::operatingsystem {
|
||||
'Debian': {
|
||||
$service_name = 'postgresql'
|
||||
}
|
||||
|
||||
'Ubuntu': {
|
||||
case $::lsbmajdistrelease {
|
||||
# thanks, ubuntu
|
||||
'10': { $service_name = "postgresql-${::postgres_default_version}" }
|
||||
default: { $service_name = 'postgresql' }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$client_package_name = 'postgresql-client'
|
||||
$server_package_name = 'postgresql'
|
||||
$devel_package_name = 'libpq-dev'
|
||||
$bindir = "/usr/lib/postgresql/${::postgres_default_version}/bin"
|
||||
$datadir = "/var/lib/postgresql/${::postgres_default_version}/main"
|
||||
$confdir = "/etc/postgresql/${::postgres_default_version}/main"
|
||||
$service_status = "/etc/init.d/${service_name} status | /bin/egrep -q 'Running clusters: .+'"
|
||||
# TODO: not exactly sure yet what the right thing to do for Debian/Ubuntu is.
|
||||
#$persist_firewall_command = '/sbin/iptables-save > /etc/iptables/rules.v4'
|
||||
|
||||
}
|
||||
|
||||
default: {
|
||||
fail("Unsupported osfamily: ${::osfamily} operatingsystem: ${::operatingsystem}, module ${module_name} currently only supports osfamily RedHat and Debian")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$initdb_path = "${bindir}/initdb"
|
||||
$createdb_path = "${bindir}/createdb"
|
||||
$psql_path = "${bindir}/psql"
|
||||
$pg_hba_conf_path = "${confdir}/pg_hba.conf"
|
||||
$postgresql_conf_path = "${confdir}/postgresql.conf"
|
||||
|
||||
}
|
|
@ -24,7 +24,7 @@ define postgresql::psql(
|
|||
$user = 'postgres'
|
||||
) {
|
||||
|
||||
require postgresql::platform
|
||||
include postgresql::params
|
||||
|
||||
# TODO: FIXME: shellquote does not work, and this regex works for trivial
|
||||
# things but not nested escaping. Need a lexer, preferably a ruby SQL parser
|
||||
|
@ -34,7 +34,7 @@ define postgresql::psql(
|
|||
$no_password_option = '--no-password'
|
||||
}
|
||||
|
||||
$psql = "${postgresql::platform::psql_path} ${no_password_option} --tuples-only --quiet --dbname ${db}"
|
||||
$psql = "${postgresql::params::psql_path} ${no_password_option} --tuples-only --quiet --dbname ${db}"
|
||||
$quoted_command = regsubst($command, '"', '\\"', 'G')
|
||||
$quoted_unless = regsubst($unless, '"', '\\"', 'G')
|
||||
|
||||
|
|
|
@ -15,43 +15,17 @@
|
|||
# Sample Usage:
|
||||
#
|
||||
class postgresql::server (
|
||||
$package_name = '',
|
||||
$package_name = $postgresql::params::server_package_name,
|
||||
$package_ensure = 'present',
|
||||
$service_name = '',
|
||||
$service_provider = '',
|
||||
$service_status = '',
|
||||
$service_name = $postgresql::params::service_name,
|
||||
$service_provider = $postgresql::params::service_provider,
|
||||
$service_status = $postgresql::params::service_status,
|
||||
$config_hash = {}
|
||||
) inherits postgresql::params {
|
||||
|
||||
include postgresql::platform
|
||||
|
||||
if ! $package_name {
|
||||
$package_name_real = $postgresql::platform::server_package_name
|
||||
} else {
|
||||
$package_name_real = $package_name
|
||||
}
|
||||
|
||||
if ! $service_name {
|
||||
$service_name_real = $postgresql::platform::service_name
|
||||
} else {
|
||||
$service_name_real = $service_name
|
||||
}
|
||||
|
||||
if ! $service_provider {
|
||||
$service_provider_real = $postgresql::platform::service_provider
|
||||
} else {
|
||||
$service_provider_real = $service_provider
|
||||
}
|
||||
|
||||
if ! $service_status {
|
||||
$service_status_real = $postgresql::platform::service_status
|
||||
} else {
|
||||
$service_status_real = $service_status
|
||||
}
|
||||
|
||||
package { 'postgresql-server':
|
||||
ensure => $package_ensure,
|
||||
name => $package_name_real,
|
||||
name => $package_name,
|
||||
}
|
||||
|
||||
if defined(Yumrepo['yum.postgresql.org']) {
|
||||
|
@ -66,11 +40,11 @@ class postgresql::server (
|
|||
|
||||
service { 'postgresqld':
|
||||
ensure => running,
|
||||
name => $service_name_real,
|
||||
name => $service_name,
|
||||
enable => true,
|
||||
require => Package['postgresql-server'],
|
||||
provider => $service_provider_real,
|
||||
status => $service_status_real,
|
||||
provider => $service_provider,
|
||||
status => $service_status,
|
||||
}
|
||||
|
||||
if ($postgresql::params::needs_initdb) {
|
||||
|
@ -84,10 +58,10 @@ class postgresql::server (
|
|||
|
||||
exec { 'reload_postgresql':
|
||||
path => '/usr/bin:/usr/sbin:/bin:/sbin',
|
||||
command => "service ${service_name_real} reload",
|
||||
command => "service ${service_name} reload",
|
||||
user => $postgresql::params::user,
|
||||
group => $postgresql::params::group,
|
||||
onlyif => $service_status_real,
|
||||
onlyif => $service_status,
|
||||
refreshonly => true,
|
||||
}
|
||||
|
||||
|
|
|
@ -49,28 +49,19 @@ define postgresql::validate_db_connection(
|
|||
$database_name,
|
||||
$database_password,
|
||||
$database_username,
|
||||
$client_package_name = '',
|
||||
$client_package_name = $postgresql::params::client_package_name,
|
||||
$database_port = 5432
|
||||
) {
|
||||
include postgresql::platform
|
||||
|
||||
# This is a bit messy, but we need to use the correct client package name
|
||||
# from the params class if the user did not explicitly provide one.
|
||||
if (! $client_package_name) {
|
||||
$package_name = $postgresql::platform::client_package_name
|
||||
} else {
|
||||
$package_name = $client_package_name
|
||||
}
|
||||
) inherits postgresql::params {
|
||||
|
||||
# Make sure the postgres client package is installed; we need it for
|
||||
# `psql`.
|
||||
package { 'postgresql-client':
|
||||
ensure => present,
|
||||
name => $package_name,
|
||||
name => $client_package_name,
|
||||
}
|
||||
|
||||
# TODO: port to ruby
|
||||
$psql = "${postgresql::platform::psql_path} --tuples-only --quiet -h ${database_host} -U ${database_username} -p ${database_port} --dbname ${database_name}"
|
||||
$psql = "${postgresql::params::psql_path} --tuples-only --quiet -h ${database_host} -U ${database_username} -p ${database_port} --dbname ${database_name}"
|
||||
|
||||
$exec_name = "validate postgres connection for ${database_host}/${database_name}"
|
||||
exec { $exec_name:
|
||||
|
|
|
@ -11,4 +11,4 @@ module PostgresTestConfig
|
|||
# iterative development, but will save a lot of system resources by not
|
||||
# keeping all of the VMs running at the same time.
|
||||
SuspendVMsAfterSuite = false
|
||||
end
|
||||
end
|
||||
|
|
|
@ -23,7 +23,7 @@ shared_context :pg_vm_context do
|
|||
@env.cli("up", vm.to_s)
|
||||
|
||||
if PostgresTestConfig::HardCoreTesting
|
||||
sudo_and_log(vm, '[ "$(facter osfamily)" == "Debian" ] && apt-get update')
|
||||
sudo_and_log(vm, 'if [ "$(facter osfamily)" == "Debian" ] ; then apt-get update ; fi')
|
||||
end
|
||||
|
||||
install_postgres
|
||||
|
|
Loading…
Reference in a new issue