Refactored multi-version support.

This commit is contained in:
Etienne Pelletier 2012-11-20 14:52:44 -06:00 committed by Chris Price
parent 1661ff1696
commit 1fe9559bbe
14 changed files with 199 additions and 109 deletions

View file

@ -39,10 +39,12 @@ class postgresql::config(
$listen_addresses = $postgresql::params::listen_addresses,
$ipv4acls = $postgresql::params::ipv4acls,
$ipv6acls = $postgresql::params::ipv6acls,
$pg_hba_conf_path = $postgresql::params::pg_hba_conf_path,
$postgresql_conf_path = $postgresql::params::postgresql_conf_path,
$pg_hba_conf_path = $postgresql::paths::pg_hba_conf_path,
$postgresql_conf_path = $postgresql::paths::postgresql_conf_path,
$manage_redhat_firewall = $postgresql::params::manage_redhat_firewall
) inherits postgresql::params {
include postgresql::paths
# Basically, all this class needs to handle is passing parameters on
# to the "beforeservice" and "afterservice" classes, and ensure

View file

@ -39,11 +39,13 @@ class postgresql::config::beforeservice(
$listen_addresses = $postgresql::params::listen_addresses,
$ipv4acls = $postgresql::params::ipv4acls,
$ipv6acls = $postgresql::params::ipv6acls,
$pg_hba_conf_path = $postgresql::params::pg_hba_conf_path,
$postgresql_conf_path = $postgresql::params::postgresql_conf_path,
$pg_hba_conf_path = $postgresql::paths::pg_hba_conf_path,
$postgresql_conf_path = $postgresql::paths::postgresql_conf_path,
$manage_redhat_firewall = $postgresql::params::manage_redhat_firewall
) inherits postgresql::params {
include postgresql::paths
File {
owner => $postgresql::params::user,
group => $postgresql::params::group,

View file

@ -23,13 +23,13 @@ define postgresql::database(
$dbname = $title,
$charset = 'UTF8')
{
require postgresql::params
include postgresql::paths
if ($::postgres_default_version != '8.1') {
$locale_option = '--locale=C'
}
$createdb_command = "${postgresql::params::createdb_path} --template=template0 --encoding '${charset}' ${locale_option} '${dbname}'"
$createdb_command = "${postgresql::paths::createdb_path} --template=template0 --encoding '${charset}' ${locale_option} '${dbname}'"
postgresql_psql { "Check for existence of db '$dbname'":
command => "SELECT 1",

View file

@ -13,14 +13,18 @@
# Sample Usage:
#
class postgresql::devel(
$package_name = $postgresql::params::devel_package_name,
$package_name = undef,
$package_ensure = 'present'
) inherits postgresql::params {
) {
require postgresql
$package_name_real = $package_name ? { undef => $postgresql::packages::devel_package_name, default => $package_name }
Class['postgresql::repo'] -> Package['postgresql_devel']
package { 'postgresql_devel':
ensure => $package_ensure,
name => $package_name,
name => $package_name_real,
}
}

View file

@ -12,15 +12,25 @@
# Sample Usage:
#
class postgresql (
$package_name = $postgresql::params::client_package_name,
$version = $::postgres_default_version,
$package_name = undef,
$package_ensure = 'present'
) inherits postgresql::params {
if ! defined(Class['postgresql::version']) {
class { 'postgresql::version':
version => $version
}
}
include postgresql::repo
include postgresql::packages
$package_name_real = $package_name ? { undef => $postgresql::packages::client_package_name, default => $package_name }
Class['postgresql::repo'] -> Package['postgresql_client']
package { 'postgresql_client':
ensure => $package_ensure,
name => $package_name,
name => $package_name_real,
require => Class['postgresql::repo'],
}

View file

@ -17,11 +17,12 @@
# limitations under the License.
class postgresql::initdb(
$datadir = $postgresql::params::datadir,
$datadir = $postgresql::paths::datadir,
$encoding = 'UTF8',
$user = 'postgres'
$group = 'postgres',
$initdb_path = $postgresql::params::initdb_path,
$initdb_path = $postgresql::paths::initdb_path,
$options = '',
$user = 'postgres'
) inherits postgresql::params {
$initdb_command = "${initdb_path} --encoding '${encoding}' --pgdata '${datadir}'"

48
manifests/packages.pp Normal file
View file

@ -0,0 +1,48 @@
# Class: postgresql::params
#
# The postgresql configuration settings.
#
# Parameters:
#
# Actions:
#
# Requires:
#
# Sample Usage:
#
class postgresql::packages {
include postgresql::version
$version = $postgresql::version::version
case $::osfamily {
'RedHat': {
if $version == $::postgres_default_version {
$client_package_name = 'postgresql'
$server_package_name = 'postgresql-server'
$devel_package_name = 'postgresql-devel'
} 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"
}
}
'Debian': {
$client_package_name = 'postgresql-client'
$server_package_name = 'postgresql'
$devel_package_name = 'libpq-dev'
}
default: {
fail("Unsupported osfamily: ${::osfamily} operatingsystem: ${::operatingsystem}, module ${module_name} currently only supports osfamily RedHat and Debian")
}
}
}

View file

@ -11,9 +11,6 @@
# Sample Usage:
#
class postgresql::params {
include postgresql::version
$version = $postgresql::version::version
$user = 'postgres'
$group = 'postgres'
$ip_mask_deny_postgres_user = '0.0.0.0/0'
@ -44,52 +41,10 @@ class postgresql::params {
'RedHat': {
$needs_initdb = true
$firewall_supported = true
$persist_firewall_command = '/sbin/iptables-save > /etc/sysconfig/iptables'
case $version {
'9.0': {
$service_name = 'postgresql-9.0'
$client_package_name = 'postgresql90'
$server_package_name = 'postgresql90-server'
$devel_package_name = 'postgresql90-devel'
$bindir = '/usr/pgsql-9.0/bin'
$datadir = '/var/lib/pgsql/9.0/data'
$confdir = $datadir
}
default: {
$service_name = 'postgresql'
$client_package_name = 'postgresql'
$server_package_name = 'postgresql-server'
$devel_package_name = 'postgresql-devel'
$bindir = '/usr/bin'
$datadir = '/var/lib/pgsql/data'
$confdir = $datadir
}
} # case
$persist_firewall_command = '/sbin/iptables-save > /etc/sysconfig/iptables'
}
'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'
$needs_initdb = false
$bindir = "/usr/lib/postgresql/${::postgres_default_version}/bin"
$datadir = "/var/lib/postgresql/${::postgres_default_version}/main"
$confdir = "/etc/postgresql/${::postgres_default_version}/main"
$firewall_supported = false
$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.
@ -100,13 +55,5 @@ class postgresql::params {
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"
}

66
manifests/paths.pp Normal file
View file

@ -0,0 +1,66 @@
# Class: postgresql::params
#
# The postgresql configuration settings.
#
# Parameters:
#
# Actions:
#
# Requires:
#
# Sample Usage:
#
class postgresql::paths {
include postgresql::version
$version = $postgresql::version::version
case $::osfamily {
'RedHat': {
if $version == $::postgres_default_version {
$service_name = 'postgresql'
$bindir = '/usr/bin'
$datadir = '/var/lib/pgsql/data/'
}
else {
$service_name = "postgresql-${version}"
$bindir = "/usr/pgsql-${version}/bin"
$datadir = "/var/lib/pgsql/${version}/data/"
} # case
}
'Debian': {
case $::operatingsystem {
'Debian': {
$service_name = 'postgresql'
}
'Ubuntu': {
case $::lsbmajdistrelease {
# thanks, ubuntu
'10': { $service_name = "postgresql-${::postgres_default_version}" }
default: { $service_name = 'postgresql' }
}
}
}
$bindir = "/usr/lib/postgresql/${::postgres_default_version}/bin"
$datadir = "/var/lib/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 = "${datadir}pg_hba.conf"
$postgresql_conf_path = "${datadir}postgresql.conf"
}

View file

@ -24,7 +24,7 @@ define postgresql::psql(
$user = 'postgres'
) {
require postgresql::params
require postgresql::paths
# 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::params::psql_path} ${no_password_option} --tuples-only --quiet --dbname ${db}"
$psql = "${postgresql::paths::psql_path} ${no_password_option} --tuples-only --quiet --dbname ${db}"
$quoted_command = regsubst($command, '"', '\\"', 'G')
$quoted_unless = regsubst($unless, '"', '\\"', 'G')

View file

@ -10,29 +10,26 @@
#
# Etienne Pelletier <epelletier@maestrodev.com>
#
class postgresql::repo {
class postgresql::repo($version = $postgresql::version::version) {
include postgresql::version
if $version != $::postgres_default_version {
case $::osfamily {
'RedHat': {
case $postgresql::version::version {
'9.0': {
yumrepo { 'postgresql90':
baseurl => 'http://yum.postgresql.org/9.0/redhat/rhel-$releasever-$basearch',
descr => 'Postgresql 9.0 Yum Repo',
enabled => 1,
gpgcheck => 0,
}
case $::osfamily {
'RedHat': {
$repo_name = "postgresql${version}"
yumrepo { 'postgresql-repo':
name => $repo_name,
baseurl => "http://yum.postgresql.org/${version}/redhat/rhel-\$releasever-\$basearch",
descr => "Postgresql ${version} Yum Repo",
enabled => 1,
gpgcheck => 0,
}
default: {
}
} # case
}
default: {
# TODO add Debian apt repos.
}
}
default: {
}
}
}

View file

@ -15,44 +15,57 @@
# Sample Usage:
#
class postgresql::server (
$package_name = $postgresql::params::server_package_name,
$version = $::postgres_default_version,
$package_name = undef,
$package_ensure = 'present',
$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::repo
if ! defined(Class['postgresql::version']) {
class { 'postgresql::version':
version => $version
}
}
include postgresql::packages
include postgresql::paths
$package_name_real = $package_name ? { undef => $postgresql::packages::server_package_name, default => $package_name }
class { 'postgresql::repo': }
package { 'postgresql-server':
ensure => $package_ensure,
name => $package_name,
name => $package_name_real,
require => Class['postgresql::repo']
}
$config_class = {}
$config_class['postgresql::config'] = $config_hash
create_resources( 'class', $config_class )
Package['postgresql-server'] -> Class['postgresql::config']
if ($postgresql::params::needs_initdb) {
include postgresql::initdb
Class['postgresql::initdb'] -> Class['postgresql::config']
Class['postgresql::initdb'] -> Service['postgresqld']
}
service { 'postgresqld':
ensure => running,
name => $service_name,
name => $postgresql::paths::service_name,
enable => true,
require => Package['postgresql-server'],
provider => $service_provider,
status => $service_status,
}
if ($postgresql::params::needs_initdb) {
include postgresql::initdb
Package['postgresql-server'] -> Class['postgresql::initdb'] -> Class['postgresql::config'] -> Service['postgresqld']
}
else {
Package['postgresql-server'] -> Class['postgresql::config'] -> Service['postgresqld']
}
exec { 'reload_postgresql':
path => '/usr/bin:/usr/sbin:/bin:/sbin',

View file

@ -52,12 +52,13 @@ define postgresql::validate_db_connection(
$client_package_name = '',
$database_port = 5432
) {
include postgresql::params
include postgresql::packages
include postgresql::paths
# 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::params::client_package_name
$package_name = $postgresql::packages::client_package_name
} else {
$package_name = $client_package_name
}
@ -70,7 +71,7 @@ define postgresql::validate_db_connection(
}
# TODO: port to ruby
$psql = "${postgresql::params::psql_path} --tuples-only --quiet -h ${database_host} -U ${database_username} -p ${database_port} --dbname ${database_name}"
$psql = "${postgresql::paths::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:

View file

@ -31,5 +31,4 @@
# Etienne Pelletier <epelletier@maestrodev.com>
#
class postgresql::version($version = $::postgres_default_version) {
}