2 # Cookbook Name:: postgresql
5 # Copyright 2012, OpenStreetMap Foundation
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
20 if File.exists?("/etc/init.d/postgresql")
21 service "postgresql" do
22 action [ :enable, :start ]
23 supports :status => true, :restart => true, :reload => true
27 node[:postgresql][:versions].each do |version|
28 package "postgresql-#{version}"
29 package "postgresql-client-#{version}"
30 package "postgresql-contrib-#{version}"
31 package "postgresql-server-dev-#{version}"
33 if File.exists?("/etc/init.d/postgresql-#{version}")
34 service "postgresql-#{version}" do
35 action [ :enable, :start ]
36 supports :status => true, :restart => true, :reload => true
40 defaults = node[:postgresql][:settings][:defaults] || {}
41 settings = node[:postgresql][:settings][version] || {}
43 template "/etc/postgresql/#{version}/main/postgresql.conf" do
44 source "postgresql.conf.erb"
48 variables :version => version, :defaults => defaults, :settings => settings
49 if File.exists?("/etc/init.d/postgresql-#{version}")
50 notifies :reload, resources(:service => "postgresql-#{version}")
52 notifies :reload, resources(:service => "postgresql")
56 template "/etc/postgresql/#{version}/main/pg_hba.conf" do
57 source "pg_hba.conf.erb"
61 variables :early_rules => settings[:early_authentication_rules] || defaults[:early_authentication_rules],
62 :late_rules => settings[:late_authentication_rules] || defaults[:late_authentication_rules]
63 if File.exists?("/etc/init.d/postgresql-#{version}")
64 notifies :reload, resources(:service => "postgresql-#{version}")
66 notifies :reload, resources(:service => "postgresql")
70 template "/etc/postgresql/#{version}/main/pg_ident.conf" do
71 source "pg_ident.conf.erb"
75 variables :maps => settings[:user_name_maps] || defaults[:user_name_maps]
76 if File.exists?("/etc/init.d/postgresql-#{version}")
77 notifies :reload, resources(:service => "postgresql-#{version}")
79 notifies :reload, resources(:service => "postgresql")
83 link "/var/lib/postgresql/#{version}/main/server.crt" do
84 to "/etc/ssl/certs/ssl-cert-snakeoil.pem"
87 link "/var/lib/postgresql/#{version}/main/server.key" do
88 to "/etc/ssl/private/ssl-cert-snakeoil.key"
91 restore_command = settings[:restore_command] || defaults[:restore_command]
92 standby_mode = settings[:standby_mode] || defaults[:standby_mode]
94 if restore_command || standby_mode == "on"
95 template "/var/lib/postgresql/#{version}/main/recovery.conf" do
96 source "recovery.conf.erb"
100 variables :defaults => defaults, :settings => settings
101 if File.exists?("/etc/init.d/postgresql-#{version}")
102 notifies :reload, resources(:service => "postgresql-#{version}")
104 notifies :reload, resources(:service => "postgresql")
108 template "/var/lib/postgresql/#{version}/main/recovery.conf" do
110 if File.exists?("/etc/init.d/postgresql-#{version}")
111 notifies :reload, resources(:service => "postgresql-#{version}")
113 notifies :reload, resources(:service => "postgresql")
119 ohai_plugin "postgresql" do
120 template "ohai.rb.erb"
124 package "libdbd-pg-perl"
126 clusters = node[:postgresql][:clusters] || []
128 clusters.each do |name,details|
129 suffix = name.tr("/", ":")
131 munin_plugin "postgres_bgwriter_#{suffix}" do
132 target "postgres_bgwriter"
134 conf_variables :port => details[:port]
137 munin_plugin "postgres_checkpoints_#{suffix}" do
138 target "postgres_checkpoints"
140 conf_variables :port => details[:port]
143 munin_plugin "postgres_connections_db_#{suffix}" do
144 target "postgres_connections_db"
146 conf_variables :port => details[:port]
149 munin_plugin "postgres_users_#{suffix}" do
150 target "postgres_users"
152 conf_variables :port => details[:port]
155 munin_plugin "postgres_xlog_#{suffix}" do
156 target "postgres_xlog"
158 conf_variables :port => details[:port]
161 if File.exist?("/var/lib/postgresql/#{details[:version]}/main/recovery.conf")
162 munin_plugin "postgres_replication_#{suffix}" do
163 target "postgres_replication"
165 conf_variables :port => details[:port]