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"
23 include_recipe "osmosis"
25 db_passwords = data_bag_item("db", "passwords")
40 remote_directory "/opt/flush" do
50 execute "/opt/flush/Makefile" do
56 subscribes :run, "remote_directory[/opt/flush]"
59 remote_directory "/usr/local/bin" do
60 source "replication-bin"
69 template "/usr/local/bin/replicate-minute" do
70 source "replicate-minute.erb"
76 template "/usr/local/bin/users-agreed" do
77 source "users-agreed.erb"
83 template "/usr/local/bin/users-deleted" do
84 source "users-deleted.erb"
90 remote_directory "/store/planet/users_deleted" do
91 source "users_deleted"
100 remote_directory "/store/planet/replication" do
101 source "replication-cgi"
110 directory "/store/planet/replication/changesets" do
116 directory "/store/planet/replication/day" do
122 directory "/store/planet/replication/hour" do
128 directory "/store/planet/replication/minute" do
134 directory "/store/planet/replication/test" do
140 directory "/store/planet/replication/test/day" do
146 directory "/store/planet/replication/test/hour" do
152 directory "/store/planet/replication/test/minute" do
158 directory "/store/replication" do
164 directory "/store/replication/minute" do
170 systemd_tmpfile "/run/replication" do
177 directory "/etc/replication" do
183 directory "/var/run/lock/changeset-replication/" do
189 directory "/var/lib/replication" do
195 directory "/var/lib/replication/test" do
201 template "/etc/replication/auth.conf" do
202 source "replication.auth.erb"
206 variables :password => db_passwords["planetdiff"]
211 "host" => node[:web][:database_host],
212 "dbname" => "openstreetmap",
213 "user" => "planetdiff",
214 "password" => db_passwords["planetdiff"],
215 "replication_slot" => "osmdbt"
217 "log_dir" => "/var/lib/replication/minute",
218 "changes_dir" => "/store/planet/replication/test/minute",
219 "tmp_dir" => "/store/replication/minute",
220 "run_dir" => "/run/replication"
223 file "/etc/replication/osmdbt-config.yaml" do
227 content YAML.dump(osmdbt_config)
230 systemd_service "replication-minutely" do
231 description "Minutely replication"
233 working_directory "/etc/replication"
234 exec_start "/usr/local/bin/replicate-minute"
237 protect_system "full"
239 restrict_address_families %w[AF_INET AF_INET6]
240 no_new_privileges true
243 systemd_timer "replication-minutely" do
244 description "Minutely replication"
246 on_unit_active_sec 60
250 directory "/var/lib/replication/test/hour" do
256 template "/var/lib/replication/test/hour/configuration.txt" do
257 source "replication.config.erb"
261 variables :base => "test/minute", :interval => 3600
264 link "/var/lib/replication/test/hour/data" do
265 to "/store/planet/replication/test/hour"
268 systemd_service "replication-hourly" do
269 description "Hourly replication"
271 exec_start "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/test/hour"
274 protect_system "full"
276 restrict_address_families %w[AF_INET AF_INET6]
277 no_new_privileges true
280 systemd_timer "replication-hourly" do
281 description "Daily replication"
282 on_calendar "*-*-* *:02/15:00"
285 directory "/var/lib/replication/test/day" do
291 template "/var/lib/replication/test/day/configuration.txt" do
292 source "replication.config.erb"
296 variables :base => "test/hour", :interval => 86400
299 link "/var/lib/replication/test/day/data" do
300 to "/store/planet/replication/test/day"
303 systemd_service "replication-daily" do
304 description "Daily replication"
306 exec_start "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/test/day"
309 protect_system "full"
311 restrict_address_families %w[AF_INET AF_INET6]
312 no_new_privileges true
315 systemd_timer "replication-daily" do
316 description "Daily replication"
317 on_calendar "*-*-* *:02/15:00"
320 template "/etc/replication/changesets.conf" do
321 source "changesets.conf.erb"
325 variables :password => db_passwords["planetdiff"]
328 template "/etc/replication/users-agreed.conf" do
329 source "users-agreed.conf.erb"
333 variables :password => db_passwords["planetdiff"]
336 directory "/var/lib/replication/minute" do
342 directory "/var/lib/replication/hour" do
348 template "/var/lib/replication/hour/configuration.txt" do
349 source "replication.config.erb"
353 variables :base => "minute", :interval => 3600
356 link "/var/lib/replication/hour/data" do
357 to "/store/planet/replication/hour"
360 directory "/var/lib/replication/day" do
366 template "/var/lib/replication/day/configuration.txt" do
367 source "replication.config.erb"
371 variables :base => "hour", :interval => 86400
374 link "/var/lib/replication/day/data" do
375 to "/store/planet/replication/day"
378 if node[:planet][:replication] == "enabled"
379 cron_d "users-agreed" do
383 command "/usr/local/bin/users-agreed"
384 mailto "zerebubuth@gmail.com"
387 cron_d "users-deleted" do
391 command "/usr/local/bin/users-deleted"
392 mailto "zerebubuth@gmail.com"
395 cron_d "replication-changesets" do
397 command "/usr/local/bin/replicate-changesets /etc/replication/changesets.conf"
398 mailto "zerebubuth@gmail.com"
401 service "replication-minutely.timer" do
402 action [:enable, :start]
405 service "replication-hourly.timer" do
406 action [:enable, :start]
409 service "replication-daily.timer" do
410 action [:enable, :start]
413 cron_d "replication-minutely" do
415 command "/usr/local/bin/osmosis -q --replicate-apidb authFile=/etc/replication/auth.conf validateSchemaVersion=false --write-replication workingDirectory=/store/planet/replication/minute"
416 mailto "brett@bretth.com"
417 environment "LD_PRELOAD" => "/opt/flush/flush.so"
420 cron_d "replication-hourly" do
423 command "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/hour"
424 mailto "brett@bretth.com"
425 environment "LD_PRELOAD" => "/opt/flush/flush.so"
428 cron_d "replication-daily" do
431 command "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/day"
432 mailto "brett@bretth.com"
433 environment "LD_PRELOAD" => "/opt/flush/flush.so"
436 cron_d "users-agreed" do
440 cron_d "users-deleted" do
444 cron_d "replication-changesets" do
448 service "replication-minutely.timer" do
449 action [:stop, :disable]
452 service "replication-hourly.timer" do
453 action [:stop, :disable]
456 service "replication-daily.timer" do
457 action [:stop, :disable]
460 cron_d "replication-minutely" do
464 cron_d "replication-hourly" do
468 cron_d "replication-daily" do