]> git.openstreetmap.org Git - chef.git/blob - cookbooks/postgresql/recipes/default.rb
Add a load more cookbooks to the public repository
[chef.git] / cookbooks / postgresql / recipes / default.rb
1 #
2 # Cookbook Name:: postgresql
3 # Recipe:: default
4 #
5 # Copyright 2012, OpenStreetMap Foundation
6 #
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
10 #
11 #     http://www.apache.org/licenses/LICENSE-2.0
12 #
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.
18 #
19
20 package "postgresql-common"
21
22 service "postgresql" do
23   action [ :enable, :start ]
24   supports :status => true, :restart => true, :reload => true
25 end
26
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}"
32
33   defaults = node[:postgresql][:settings][:defaults] || {}
34   settings = node[:postgresql][:settings][version] || {}
35
36   template "/etc/postgresql/#{version}/main/postgresql.conf" do
37     source "postgresql.conf.erb"
38     owner "postgres"
39     group "postgres"
40     mode 0644
41     variables :version => version, :defaults => defaults, :settings => settings
42     notifies :reload, resources(:service => "postgresql")
43   end
44
45   template "/etc/postgresql/#{version}/main/pg_hba.conf" do
46     source "pg_hba.conf.erb"
47     owner "postgres"
48     group "postgres"
49     mode 0640
50     variables :early_rules => settings[:early_authentication_rules] || defaults[:early_authentication_rules],
51               :late_rules => settings[:late_authentication_rules] || defaults[:late_authentication_rules]
52     notifies :reload, resources(:service => "postgresql")
53   end
54
55   template "/etc/postgresql/#{version}/main/pg_ident.conf" do
56     source "pg_ident.conf.erb"
57     owner "postgres"
58     group "postgres"
59     mode 0640
60     variables :maps => settings[:user_name_maps] || defaults[:user_name_maps]
61     notifies :reload, resources(:service => "postgresql")
62   end
63
64   link "/var/lib/postgresql/#{version}/main/server.crt" do
65     to "/etc/ssl/certs/ssl-cert-snakeoil.pem"
66   end
67
68   link "/var/lib/postgresql/#{version}/main/server.key" do
69     to "/etc/ssl/private/ssl-cert-snakeoil.key"
70   end
71
72   restore_command = settings[:restore_command] || defaults[:restore_command]
73   standby_mode = settings[:standby_mode] || defaults[:standby_mode]
74
75   if restore_command || standby_mode == "on"
76     template "/var/lib/postgresql/#{version}/main/recovery.conf" do
77       source "recovery.conf.erb"
78       owner "postgres"
79       group "postgres"
80       mode 0640
81       variables :defaults => defaults, :settings => settings
82       notifies :reload, resources(:service => "postgresql")
83     end
84   else
85     template "/var/lib/postgresql/#{version}/main/recovery.conf" do
86       action :delete
87       notifies :reload, resources(:service => "postgresql")
88     end
89   end
90 end
91
92 ohai_plugin "postgresql" do
93   template "ohai.rb.erb"
94 end
95
96 package "ptop"
97 package "libdbd-pg-perl"
98
99 clusters = node[:postgresql][:clusters] || []
100
101 clusters.each do |name,details|
102   suffix = name.tr("/", ":")
103
104   munin_plugin "postgres_bgwriter_#{suffix}" do
105     target "postgres_bgwriter"
106     conf "munin.erb"
107     conf_variables :port => details[:port]
108   end
109
110   munin_plugin "postgres_checkpoints_#{suffix}" do
111     target "postgres_checkpoints"
112     conf "munin.erb"
113     conf_variables :port => details[:port]
114   end
115
116   munin_plugin "postgres_connections_db_#{suffix}" do
117     target "postgres_connections_db"
118     conf "munin.erb"
119     conf_variables :port => details[:port]
120   end
121
122   munin_plugin "postgres_users_#{suffix}" do
123     target "postgres_users"
124     conf "munin.erb"
125     conf_variables :port => details[:port]
126   end
127
128   munin_plugin "postgres_xlog_#{suffix}" do
129     target "postgres_xlog"
130     conf "munin.erb"
131     conf_variables :port => details[:port]
132   end
133
134   if File.exist?("/var/lib/postgresql/#{details[:version]}/main/recovery.conf")
135     munin_plugin "postgres_replication_#{suffix}" do
136       target "postgres_replication"
137       conf "munin.erb"
138       conf_variables :port => details[:port]
139     end
140   end
141 end