]> git.openstreetmap.org Git - chef.git/blob - cookbooks/db/recipes/master.rb
Disable RemoveIPC for reindex services
[chef.git] / cookbooks / db / recipes / master.rb
1 #
2 # Cookbook:: db
3 # Recipe:: master
4 #
5 # Copyright:: 2011, 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 #     https://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 include_recipe "db::base"
21
22 passwords = data_bag_item("db", "passwords")
23
24 postgresql_user "tomh" do
25   cluster node[:db][:cluster]
26   superuser true
27 end
28
29 postgresql_user "matt" do
30   cluster node[:db][:cluster]
31   superuser true
32 end
33
34 postgresql_user "openstreetmap" do
35   cluster node[:db][:cluster]
36   password passwords["openstreetmap"]
37 end
38
39 postgresql_user "rails" do
40   cluster node[:db][:cluster]
41   password passwords["rails"]
42 end
43
44 postgresql_user "cgimap" do
45   cluster node[:db][:cluster]
46   password passwords["cgimap"]
47 end
48
49 postgresql_user "planetdump" do
50   cluster node[:db][:cluster]
51   password passwords["planetdump"]
52 end
53
54 postgresql_user "planetdiff" do
55   cluster node[:db][:cluster]
56   password passwords["planetdiff"]
57   replication true
58 end
59
60 postgresql_user "backup" do
61   cluster node[:db][:cluster]
62   password passwords["backup"]
63 end
64
65 postgresql_user "munin" do
66   cluster node[:db][:cluster]
67   password passwords["munin"]
68 end
69
70 postgresql_user "replication" do
71   cluster node[:db][:cluster]
72   password passwords["replication"]
73   replication true
74 end
75
76 postgresql_database "openstreetmap" do
77   cluster node[:db][:cluster]
78   owner "openstreetmap"
79 end
80
81 postgresql_extension "btree_gist" do
82   cluster node[:db][:cluster]
83   database "openstreetmap"
84   only_if { node[:postgresql][:clusters][node[:db][:cluster]] && node[:postgresql][:clusters][node[:db][:cluster]][:version] >= 9.0 }
85 end
86
87 CGIMAP_PERMISSIONS = {
88   "changeset_comments" => [:select],
89   "changeset_tags" => [:select],
90   "changesets" => [:select, :update],
91   "client_applications" => [:select],
92   "current_node_tags" => [:select, :insert, :delete],
93   "current_nodes" => [:select, :insert, :update],
94   "current_nodes_id_seq" => [:update],
95   "current_relation_members" => [:select, :insert, :delete],
96   "current_relation_tags" => [:select, :insert, :delete],
97   "current_relations" => [:select, :insert, :update],
98   "current_relations_id_seq" => [:update],
99   "current_way_nodes" => [:select, :insert, :delete],
100   "current_way_tags" => [:select, :insert, :delete],
101   "current_ways" => [:select, :insert, :update],
102   "current_ways_id_seq" => [:update],
103   "node_tags" => [:select, :insert],
104   "nodes" => [:select, :insert],
105   "oauth_access_grants" => [:select],
106   "oauth_access_tokens" => [:select],
107   "oauth_applications" => [:select],
108   "oauth_nonces" => [:select, :insert],
109   "oauth_nonces_id_seq" => [:update],
110   "oauth_tokens" => [:select],
111   "relation_members" => [:select, :insert],
112   "relation_tags" => [:select, :insert],
113   "relations" => [:select, :insert],
114   "user_blocks" => [:select],
115   "user_roles" => [:select],
116   "users" => [:select],
117   "way_nodes" => [:select, :insert],
118   "way_tags" => [:select, :insert],
119   "ways" => [:select, :insert]
120 }.freeze
121
122 PLANETDUMP_PERMISSIONS = {
123   "note_comments" => :select,
124   "notes" => :select,
125   "users" => :select
126 }.freeze
127
128 PLANETDIFF_PERMISSIONS = {
129   "changeset_comments" => :select,
130   "changeset_tags" => :select,
131   "changesets" => :select,
132   "node_tags" => :select,
133   "nodes" => :select,
134   "relation_members" => :select,
135   "relation_tags" => :select,
136   "relations" => :select,
137   "users" => :select,
138   "way_nodes" => :select,
139   "way_tags" => :select,
140   "ways" => :select
141 }.freeze
142
143 PROMETHEUS_PERMISSIONS = {
144   "delayed_jobs" => :select
145 }.freeze
146
147 %w[
148   acls
149   active_storage_attachments
150   active_storage_blobs
151   active_storage_variant_records
152   ar_internal_metadata
153   changeset_comments
154   changeset_tags
155   changesets
156   changesets_subscribers
157   client_applications
158   current_node_tags
159   current_nodes
160   current_relation_members
161   current_relation_tags
162   current_relations
163   current_way_nodes
164   current_way_tags
165   current_ways
166   delayed_jobs
167   diary_comments
168   diary_entries
169   diary_entry_subscriptions
170   friends
171   gps_points
172   gpx_file_tags
173   gpx_files
174   issue_comments
175   issues
176   languages
177   messages
178   node_tags
179   nodes
180   note_comments
181   notes
182   oauth_access_grants
183   oauth_access_tokens
184   oauth_applications
185   oauth_nonces
186   oauth_openid_requests
187   oauth_tokens
188   redactions
189   relation_members
190   relation_tags
191   relations
192   reports
193   schema_migrations
194   user_blocks
195   user_preferences
196   user_roles
197   user_tokens
198   users
199   way_nodes
200   way_tags
201   ways
202 ].each do |table|
203   postgresql_table table do
204     cluster node[:db][:cluster]
205     database "openstreetmap"
206     owner "openstreetmap"
207     permissions "openstreetmap" => [:all],
208                 "rails" => [:select, :insert, :update, :delete],
209                 "cgimap" => CGIMAP_PERMISSIONS[table],
210                 "planetdump" => PLANETDUMP_PERMISSIONS[table],
211                 "planetdiff" => PLANETDIFF_PERMISSIONS[table],
212                 "prometheus" => PROMETHEUS_PERMISSIONS[table],
213                 "backup" => [:select]
214   end
215 end
216
217 %w[
218   acls_id_seq
219   active_storage_attachments_id_seq
220   active_storage_blobs_id_seq
221   active_storage_variant_records_id_seq
222   changeset_comments_id_seq
223   changesets_id_seq
224   client_applications_id_seq
225   current_nodes_id_seq
226   current_relations_id_seq
227   current_ways_id_seq
228   delayed_jobs_id_seq
229   diary_comments_id_seq
230   diary_entries_id_seq
231   friends_id_seq
232   gpx_file_tags_id_seq
233   gpx_files_id_seq
234   issue_comments_id_seq
235   issues_id_seq
236   messages_id_seq
237   note_comments_id_seq
238   notes_id_seq
239   oauth_access_grants_id_seq
240   oauth_access_tokens_id_seq
241   oauth_applications_id_seq
242   oauth_nonces_id_seq
243   oauth_openid_requests_id_seq
244   oauth_tokens_id_seq
245   redactions_id_seq
246   reports_id_seq
247   user_blocks_id_seq
248   user_roles_id_seq
249   user_tokens_id_seq
250   users_id_seq
251 ].each do |sequence|
252   postgresql_sequence sequence do
253     cluster node[:db][:cluster]
254     database "openstreetmap"
255     owner "openstreetmap"
256     permissions "openstreetmap" => [:all],
257                 "rails" => [:usage],
258                 "cgimap" => CGIMAP_PERMISSIONS[sequence],
259                 "backup" => [:select]
260   end
261 end
262
263 cookbook_file "/usr/local/share/monthly-reindex.sql" do
264   owner "root"
265   group "root"
266   mode "644"
267 end
268
269 systemd_service "monthly-reindex" do
270   description "Monthly database reindex"
271   exec_start "/usr/bin/psql -f /usr/local/share/monthly-reindex.sql openstreetmap"
272   user "postgres"
273   sandbox true
274   restrict_address_families "AF_UNIX"
275   remove_ipc false
276 end
277
278 systemd_timer "monthly-reindex" do
279   description "Monthly database reindex"
280   on_calendar "Sun *-*-1..7 02:00"
281 end
282
283 service "monthly-reindex.timer" do
284   action [:enable, :start]
285 end
286
287 cookbook_file "/usr/local/share/yearly-reindex.sql" do
288   owner "root"
289   group "root"
290   mode "644"
291 end
292
293 systemd_service "yearly-reindex" do
294   description "Yearly database reindex"
295   exec_start "/usr/bin/psql -f /usr/local/share/yearly-reindex.sql openstreetmap"
296   user "postgres"
297   sandbox true
298   restrict_address_families "AF_UNIX"
299   remove_ipc false
300 end
301
302 systemd_timer "yearly-reindex" do
303   description "Yearly database reindex"
304   on_calendar "Fri *-1-8..14 02:00"
305 end
306
307 service "yearly-reindex.timer" do
308   action [:enable, :start]
309 end
310
311 template "/etc/prometheus/exporters/sql_rails.collector.yml" do
312   source "sql_rails.yml.erb"
313   owner "root"
314   group "root"
315   mode "0644"
316 end