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 db_passwords = data_bag_item("db", "passwords")
28 ## Install required packages
44 ## Build preload library to flush files
46 remote_directory "/opt/flush" do
56 execute "/opt/flush/Makefile" do
62 subscribes :run, "remote_directory[/opt/flush]"
67 remote_directory "/usr/local/bin" do
68 source "replication-bin"
77 template "/usr/local/bin/replicate-minute" do
78 source "replicate-minute.erb"
84 template "/usr/local/bin/users-agreed" do
85 source "users-agreed.erb"
91 template "/usr/local/bin/users-deleted" do
92 source "users-deleted.erb"
98 ## Published deleted users directory
100 remote_directory "/store/planet/users_deleted" do
101 source "users_deleted"
110 ## Published replication directory
112 remote_directory "/store/planet/replication" do
113 source "replication-cgi"
122 directory "/store/planet/replication/test" do
128 ## Configuration directory
130 directory "/etc/replication" do
136 ## Transient state directory
138 systemd_tmpfile "/run/replication" do
145 ## Persistent state directory
147 directory "/var/lib/replication" do
153 directory "/var/lib/replication/test" do
161 template "/etc/replication/users-agreed.conf" do
162 source "users-agreed.conf.erb"
166 variables :password => db_passwords["planetdiff"]
169 ## Changeset replication
171 directory "/store/planet/replication/changesets" do
177 template "/etc/replication/changesets.conf" do
178 source "changesets.conf.erb"
182 variables :password => db_passwords["planetdiff"]
185 ## Minutely replication
187 directory "/store/planet/replication/minute" do
193 directory "/var/lib/replication/minute" do
199 template "/etc/replication/auth.conf" do
200 source "replication.auth.erb"
204 variables :password => db_passwords["planetdiff"]
207 ## Hourly replication
209 directory "/store/planet/replication/hour" do
215 directory "/var/lib/replication/hour" do
221 link "/var/lib/replication/hour/data" do
222 to "/store/planet/replication/hour"
225 template "/var/lib/replication/hour/configuration.txt" do
226 source "replication.config.erb"
230 variables :base => "minute", :interval => 3600
235 directory "/store/planet/replication/day" do
241 directory "/var/lib/replication/day" do
247 link "/var/lib/replication/day/data" do
248 to "/store/planet/replication/day"
251 template "/var/lib/replication/day/configuration.txt" do
252 source "replication.config.erb"
256 variables :base => "hour", :interval => 86400
259 ## Minutely replication (test feed)
261 directory "/store/planet/replication/test/minute" do
267 directory "/store/replication" do
273 directory "/store/replication/minute" do
281 "host" => node[:web][:database_host],
282 "dbname" => "openstreetmap",
283 "user" => "planetdiff",
284 "password" => db_passwords["planetdiff"],
285 "replication_slot" => "osmdbt"
287 "log_dir" => "/var/lib/replication/minute",
288 "changes_dir" => "/store/planet/replication/test/minute",
289 "tmp_dir" => "/store/replication/minute",
290 "run_dir" => "/run/replication"
293 file "/etc/replication/osmdbt-config.yaml" do
297 content YAML.dump(osmdbt_config)
300 systemd_service "replication-minutely" do
301 description "Minutely replication"
303 working_directory "/etc/replication"
304 exec_start "/usr/local/bin/replicate-minute"
307 protect_system "full"
309 restrict_address_families %w[AF_INET AF_INET6]
310 no_new_privileges true
313 systemd_timer "replication-minutely" do
314 description "Minutely replication"
316 on_unit_active_sec 60
320 ### Hourly replication (test feed)
322 directory "/store/planet/replication/test/hour" do
328 directory "/var/lib/replication/test/hour" do
334 link "/var/lib/replication/test/hour/data" do
335 to "/store/planet/replication/test/hour"
338 template "/var/lib/replication/test/hour/configuration.txt" do
339 source "replication.config.erb"
343 variables :base => "test/minute", :interval => 3600
346 systemd_service "replication-hourly" do
347 description "Hourly replication"
349 exec_start "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/test/hour"
352 protect_system "full"
354 restrict_address_families %w[AF_INET AF_INET6]
355 no_new_privileges true
358 systemd_timer "replication-hourly" do
359 description "Daily replication"
360 on_calendar "*-*-* *:02/15:00"
363 ## Daily replication (test feed)
365 directory "/store/planet/replication/test/day" do
371 directory "/var/lib/replication/test/day" do
377 link "/var/lib/replication/test/day/data" do
378 to "/store/planet/replication/test/day"
381 template "/var/lib/replication/test/day/configuration.txt" do
382 source "replication.config.erb"
386 variables :base => "test/hour", :interval => 86400
389 systemd_service "replication-daily" do
390 description "Daily replication"
392 exec_start "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/test/day"
395 protect_system "full"
397 restrict_address_families %w[AF_INET AF_INET6]
398 no_new_privileges true
401 systemd_timer "replication-daily" do
402 description "Daily replication"
403 on_calendar "*-*-* *:02/15:00"
406 ## Enable/disable feeds
408 if node[:planet][:replication] == "enabled"
409 cron_d "users-agreed" do
413 command "/usr/local/bin/users-agreed"
414 mailto "zerebubuth@gmail.com"
417 cron_d "users-deleted" do
421 command "/usr/local/bin/users-deleted"
422 mailto "zerebubuth@gmail.com"
425 cron_d "replication-changesets" do
427 command "/usr/local/bin/replicate-changesets /etc/replication/changesets.conf"
428 mailto "zerebubuth@gmail.com"
431 cron_d "replication-minutely" do
433 command "/usr/local/bin/osmosis -q --replicate-apidb authFile=/etc/replication/auth.conf validateSchemaVersion=false --write-replication workingDirectory=/store/planet/replication/minute"
434 mailto "brett@bretth.com"
435 environment "LD_PRELOAD" => "/opt/flush/flush.so"
438 cron_d "replication-hourly" do
441 command "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/hour"
442 mailto "brett@bretth.com"
443 environment "LD_PRELOAD" => "/opt/flush/flush.so"
446 cron_d "replication-daily" do
449 command "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/day"
450 mailto "brett@bretth.com"
451 environment "LD_PRELOAD" => "/opt/flush/flush.so"
454 service "replication-minutely.timer" do
455 action [:enable, :start]
458 service "replication-hourly.timer" do
459 action [:enable, :start]
462 service "replication-daily.timer" do
463 action [:enable, :start]
466 cron_d "users-agreed" do
470 cron_d "users-deleted" do
474 cron_d "replication-changesets" do
478 cron_d "replication-minutely" do
482 cron_d "replication-hourly" do
486 cron_d "replication-daily" do
490 service "replication-minutely.timer" do
491 action [:stop, :disable]
494 service "replication-hourly.timer" do
495 action [:stop, :disable]
498 service "replication-daily.timer" do
499 action [:stop, :disable]