Skip to content

Commit

Permalink
add pgdg apt support, improved debian/ubuntu support with older postg…
Browse files Browse the repository at this point in the history
…res versions
  • Loading branch information
Jason Rutherford committed May 2, 2013
1 parent 7bd8b54 commit bea87ba
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 6 deletions.
15 changes: 11 additions & 4 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@

default['postgresql']['dir'] = "/etc/postgresql/#{node['postgresql']['version']}/main"
case
when node['platform_version'].to_f <= 10.04
when node['platform_version'].to_f < 10.04 # after 10.04
default['postgresql']['server']['service_name'] = "postgresql-#{node['postgresql']['version']}"
else
default['postgresql']['server']['service_name'] = "postgresql"
end

default['postgresql']['client']['packages'] = %w{postgresql-client libpq-dev}
default['postgresql']['server']['packages'] = %w{postgresql}
default['postgresql']['contrib']['packages'] = %w{postgresql-contrib}
default['postgresql']['client']['packages'] = ["postgresql-client-#{node['postgresql']['version']} libpq-dev"]
default['postgresql']['server']['packages'] = ["postgresql-#{node['postgresql']['version']}"]
default['postgresql']['contrib']['packages'] = ["postgresql-contrib-#{node['postgresql']['version']}-contrib"]

when "fedora"

Expand Down Expand Up @@ -154,6 +154,12 @@
default['postgresql']['config']['datestyle'] = 'iso, mdy'
default['postgresql']['config']['default_text_search_config'] = 'pg_catalog.english'
default['postgresql']['config']['ssl'] = true

if node['postgresql']['version'].to_f >= 9.2
default['postgresql']['config']['ssl_cert_file'] = '/etc/ssl/certs/ssl-cert-snakeoil.pem' # (change requires restart)
default['postgresql']['config']['ssl_key_file'] = '/etc/ssl/private/ssl-cert-snakeoil.key' # (change requires restart)
end

when 'rhel', 'fedora', 'suse'
default['postgresql']['config']['listen_addresses'] = 'localhost'
default['postgresql']['config']['max_connections'] = 100
Expand Down Expand Up @@ -182,6 +188,7 @@
default['postgresql']['password'] = Hash.new

default['postgresql']['enable_pitti_ppa'] = false
default['postgresql']['enable_postgres_apt'] = false
default['postgresql']['enable_pgdg_yum'] = false

# The PostgreSQL RPM Building Project built repository RPMs for easy
Expand Down
59 changes: 59 additions & 0 deletions recipes/apt_pgdg_postgresql.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#
# Cookbook Name:: postgresql
# Recipe:: ppa_pgdg_postgresql
#
# Author:: Jason Rutherford (<[email protected]>)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

#
# This recipe will add the PostgreSQL Global Development Group (PGDG)
# maintained APT repository of PostgreSQL packages for Debian and Ubuntu.
# This makes available several versions of Postgresql available for
# APT installation.
#
# For more information see: https://wiki.postgresql.org/wiki/Apt
#

#
# USAGE
# =====
#
# Just set node['postgresql']['enable_pgdg_ppa'] to true and you'll be able
# to install any version included the repository like 8.4, 9.1, 9.2.
#
# Vagrantfile example:
#
# ...
# chef.json = {
# :postgresql => {
# :enable_postgresql_ppa => true,
# :version => '8.4',
# :password => {
# :postgres => 'apppass'
# }
# }
# }
# ...

include_recipe 'apt'

apt_repository 'pgdg' do
uri 'http://apt.postgresql.org/pub/repos/apt/'
distribution "#{node['lsb']['codename']}-pgdg"
components %w(main)
keyserver 'keyserver.ubuntu.com'
key 'ACCC4CF8'
action :add
end
4 changes: 4 additions & 0 deletions recipes/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
include_recipe 'postgresql::ppa_pitti_postgresql'
end

if(node['postgresql']['enable_pgdg_apt'])
include_recipe 'postgresql::apt_pgdg_postgresql'
end

if(node['postgresql']['enable_pgdg_yum'])
include_recipe 'postgresql::yum_pgdg_postgresql'
end
Expand Down
7 changes: 6 additions & 1 deletion recipes/server_debian.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,10 @@
service "postgresql" do
service_name node['postgresql']['server']['service_name']
supports :restart => true, :status => true, :reload => true
action [:enable, :start]

if node['lsb']['codename'] == 'lucid'
action [:start]
else
action [:enable, :start]
end
end
4 changes: 3 additions & 1 deletion templates/default/pg_hba.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
<% end -%>

# "local" is for Unix domain socket connections only
<% if node['postgresql']['version'].to_f < 9.1 -%>
<% if node['postgresql']['version'].to_f < 8.4 -%>
local all all ident sameuser
<% elsif node['postgresql']['version'].to_f < 9.1 -%>
local all all ident
<% elsif node['postgresql']['version'].to_f >= 9.1 -%>
local all all peer
Expand Down

0 comments on commit bea87ba

Please sign in to comment.