5 # Copyright:: 2013, 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 # https://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.
22 include_recipe "accounts"
24 include_recipe "osmosis"
26 include_recipe "tools"
28 db_passwords = data_bag_item("db", "passwords")
30 ## Install required packages
43 gem_binary node[:ruby][:gem]
46 ## Build preload library to flush files
48 remote_directory "/opt/flush" do
58 execute "/opt/flush/Makefile" do
64 subscribes :run, "remote_directory[/opt/flush]"
69 remote_directory "/usr/local/bin" do
70 source "replication-bin"
79 template "/usr/local/bin/users-agreed" do
80 source "users-agreed.erb"
86 template "/usr/local/bin/users-deleted" do
87 source "users-deleted.erb"
93 ## Published deleted users directory
95 remote_directory "/store/planet/users_deleted" do
96 source "users_deleted"
105 ## Published replication directory
107 remote_directory "/store/planet/replication" do
108 source "replication-cgi"
117 ## Configuration directory
119 directory "/etc/replication" do
125 ## Transient state directory
127 systemd_tmpfile "/run/replication" do
134 ## Persistent state directory
136 directory "/var/lib/replication" do
142 ## Temporary directory
144 directory "/store/replication" do
152 template "/etc/replication/users-agreed.conf" do
153 source "users-agreed.conf.erb"
157 variables :password => db_passwords["planetdiff"]
160 systemd_service "users-agreed" do
161 description "Update list of users accepting CTs"
163 exec_start "/usr/local/bin/users-agreed"
166 protect_system "full"
168 restrict_address_families %w[AF_INET AF_INET6]
169 no_new_privileges true
172 systemd_timer "users-agreed" do
173 description "Update list of users accepting CTs"
177 systemd_service "users-deleted" do
178 description "Update list of deleted users"
180 exec_start "/usr/local/bin/users-deleted"
183 protect_system "full"
185 restrict_address_families %w[AF_INET AF_INET6]
186 no_new_privileges true
189 systemd_timer "users-deleted" do
190 description "Update list of deleted users"
194 ## Changeset replication
196 directory "/store/planet/replication/changesets" do
202 template "/etc/replication/changesets.conf" do
203 source "changesets.conf.erb"
207 variables :password => db_passwords["planetdiff"]
210 systemd_service "replication-changesets" do
211 description "Changesets replication"
213 exec_start "/usr/local/bin/replicate-changesets /etc/replication/changesets.conf"
216 protect_system "full"
218 restrict_address_families %w[AF_INET AF_INET6]
219 no_new_privileges true
222 systemd_timer "replication-changesets" do
223 description "Changesets replication"
225 on_unit_active_sec 60
229 ## Minutely replication
231 directory "/store/planet/replication/minute" do
237 directory "/var/lib/replication/minute" do
243 directory "/store/replication/minute" do
251 "host" => node[:web][:database_host],
252 "dbname" => "openstreetmap",
253 "user" => "planetdiff",
254 "password" => db_passwords["planetdiff"],
255 "replication_slot" => "osmdbt"
257 "log_dir" => "/var/lib/replication/minute",
258 "changes_dir" => "/store/planet/replication/minute",
259 "tmp_dir" => "/store/replication/minute",
260 "run_dir" => "/run/replication"
263 file "/etc/replication/osmdbt-config.yaml" do
267 content YAML.dump(osmdbt_config)
270 systemd_service "replication-minutely" do
271 description "Minutely replication"
273 working_directory "/etc/replication"
274 exec_start "/usr/local/bin/replicate-minute"
277 protect_system "full"
279 restrict_address_families %w[AF_INET AF_INET6]
280 no_new_privileges true
283 systemd_timer "replication-minutely" do
284 description "Minutely replication"
286 on_unit_active_sec 60
290 ## Hourly replication
292 directory "/store/planet/replication/hour" do
298 directory "/var/lib/replication/hour" do
304 link "/var/lib/replication/hour/data" do
305 to "/store/planet/replication/hour"
308 template "/var/lib/replication/hour/configuration.txt" do
309 source "replication.config.erb"
313 variables :base => "minute", :interval => 3600
316 systemd_service "replication-hourly" do
317 description "Hourly replication"
319 exec_start "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/hour"
322 protect_system "full"
324 restrict_address_families %w[AF_INET AF_INET6]
325 no_new_privileges true
328 systemd_timer "replication-hourly" do
329 description "Daily replication"
330 on_calendar "*-*-* *:02/15:00"
335 directory "/store/planet/replication/day" do
341 directory "/var/lib/replication/day" do
347 link "/var/lib/replication/day/data" do
348 to "/store/planet/replication/day"
351 template "/var/lib/replication/day/configuration.txt" do
352 source "replication.config.erb"
356 variables :base => "hour", :interval => 86400
359 systemd_service "replication-daily" do
360 description "Daily replication"
362 exec_start "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/day"
365 protect_system "full"
367 restrict_address_families %w[AF_INET AF_INET6]
368 no_new_privileges true
371 systemd_timer "replication-daily" do
372 description "Daily replication"
373 on_calendar "*-*-* *:02/15:00"
376 ## Replication cleanup
378 systemd_service "replication-cleanup" do
379 description "Cleanup replication"
381 exec_start "/usr/local/bin/replicate-cleanup"
385 protect_system "full"
387 no_new_privileges true
390 systemd_timer "replication-cleanup" do
391 description "Cleanup replication"
393 on_unit_active_sec 86400
397 ## Enable/disable feeds
399 if node[:planet][:replication] == "enabled"
400 service "users-agreed.timer" do
401 action [:enable, :start]
404 service "users-deleted.timer" do
405 action [:enable, :start]
408 service "replication-changesets.timer" do
409 action [:enable, :start]
412 service "replication-minutely.timer" do
413 action [:enable, :start]
416 service "replication-hourly.timer" do
417 action [:enable, :start]
420 service "replication-daily.timer" do
421 action [:enable, :start]
424 service "replication-cleanup.timer" do
425 action [:enable, :start]
428 service "users-agreed.timer" do
429 action [:stop, :disable]
432 service "users-deleted.timer" do
433 action [:stop, :disable]
436 service "replication-changesets.timer" do
437 action [:stop, :disable]
440 service "replication-minutely.timer" do
441 action [:stop, :disable]
444 service "replication-hourly.timer" do
445 action [:stop, :disable]
448 service "replication-daily.timer" do
449 action [:stop, :disable]
452 service "replication-cleanup.timer" do
453 action [:stop, :disable]