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")
42 remote_directory "/opt/flush" do
52 execute "/opt/flush/Makefile" do
58 subscribes :run, "remote_directory[/opt/flush]"
61 remote_directory "/usr/local/bin" do
62 source "replication-bin"
71 template "/usr/local/bin/replicate-minute" do
72 source "replicate-minute.erb"
78 template "/usr/local/bin/users-agreed" do
79 source "users-agreed.erb"
85 template "/usr/local/bin/users-deleted" do
86 source "users-deleted.erb"
92 remote_directory "/store/planet/users_deleted" do
93 source "users_deleted"
102 remote_directory "/store/planet/replication" do
103 source "replication-cgi"
112 directory "/store/planet/replication/changesets" do
118 directory "/store/planet/replication/day" do
124 directory "/store/planet/replication/hour" do
130 directory "/store/planet/replication/minute" do
136 directory "/store/planet/replication/test" do
142 directory "/store/planet/replication/test/day" do
148 directory "/store/planet/replication/test/hour" do
154 directory "/store/planet/replication/test/minute" do
160 directory "/store/replication" do
166 directory "/store/replication/minute" do
172 systemd_tmpfile "/run/replication" do
179 directory "/etc/replication" do
185 directory "/var/run/lock/changeset-replication/" do
191 directory "/var/lib/replication" do
197 directory "/var/lib/replication/test" do
203 template "/etc/replication/auth.conf" do
204 source "replication.auth.erb"
208 variables :password => db_passwords["planetdiff"]
213 "host" => node[:web][:database_host],
214 "dbname" => "openstreetmap",
215 "user" => "planetdiff",
216 "password" => db_passwords["planetdiff"],
217 "replication_slot" => "osmdbt"
219 "log_dir" => "/var/lib/replication/minute",
220 "changes_dir" => "/store/planet/replication/test/minute",
221 "tmp_dir" => "/store/replication/minute",
222 "run_dir" => "/run/replication"
225 file "/etc/replication/osmdbt-config.yaml" do
229 content YAML.dump(osmdbt_config)
232 systemd_service "replication-minutely" do
233 description "Minutely replication"
235 working_directory "/etc/replication"
236 exec_start "/usr/local/bin/replicate-minute"
239 protect_system "full"
241 restrict_address_families %w[AF_INET AF_INET6]
242 no_new_privileges true
245 systemd_timer "replication-minutely" do
246 description "Minutely replication"
248 on_unit_active_sec 60
252 directory "/var/lib/replication/test/hour" do
258 template "/var/lib/replication/test/hour/configuration.txt" do
259 source "replication.config.erb"
263 variables :base => "test/minute", :interval => 3600
266 link "/var/lib/replication/test/hour/data" do
267 to "/store/planet/replication/test/hour"
270 systemd_service "replication-hourly" do
271 description "Hourly replication"
273 exec_start "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/test/hour"
276 protect_system "full"
278 restrict_address_families %w[AF_INET AF_INET6]
279 no_new_privileges true
282 systemd_timer "replication-hourly" do
283 description "Daily replication"
284 on_calendar "*-*-* *:02/15:00"
287 directory "/var/lib/replication/test/day" do
293 template "/var/lib/replication/test/day/configuration.txt" do
294 source "replication.config.erb"
298 variables :base => "test/hour", :interval => 86400
301 link "/var/lib/replication/test/day/data" do
302 to "/store/planet/replication/test/day"
305 systemd_service "replication-daily" do
306 description "Daily replication"
308 exec_start "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/test/day"
311 protect_system "full"
313 restrict_address_families %w[AF_INET AF_INET6]
314 no_new_privileges true
317 systemd_timer "replication-daily" do
318 description "Daily replication"
319 on_calendar "*-*-* *:02/15:00"
322 template "/etc/replication/changesets.conf" do
323 source "changesets.conf.erb"
327 variables :password => db_passwords["planetdiff"]
330 template "/etc/replication/users-agreed.conf" do
331 source "users-agreed.conf.erb"
335 variables :password => db_passwords["planetdiff"]
338 directory "/var/lib/replication/minute" do
344 directory "/var/lib/replication/hour" do
350 template "/var/lib/replication/hour/configuration.txt" do
351 source "replication.config.erb"
355 variables :base => "minute", :interval => 3600
358 link "/var/lib/replication/hour/data" do
359 to "/store/planet/replication/hour"
362 directory "/var/lib/replication/day" do
368 template "/var/lib/replication/day/configuration.txt" do
369 source "replication.config.erb"
373 variables :base => "hour", :interval => 86400
376 link "/var/lib/replication/day/data" do
377 to "/store/planet/replication/day"
380 if node[:planet][:replication] == "enabled"
381 cron_d "users-agreed" do
385 command "/usr/local/bin/users-agreed"
386 mailto "zerebubuth@gmail.com"
389 cron_d "users-deleted" do
393 command "/usr/local/bin/users-deleted"
394 mailto "zerebubuth@gmail.com"
397 cron_d "replication-changesets" do
399 command "/usr/local/bin/replicate-changesets /etc/replication/changesets.conf"
400 mailto "zerebubuth@gmail.com"
403 service "replication-minutely.timer" do
404 action [:enable, :start]
407 service "replication-hourly.timer" do
408 action [:enable, :start]
411 service "replication-daily.timer" do
412 action [:enable, :start]
415 cron_d "replication-minutely" do
417 command "/usr/local/bin/osmosis -q --replicate-apidb authFile=/etc/replication/auth.conf validateSchemaVersion=false --write-replication workingDirectory=/store/planet/replication/minute"
418 mailto "brett@bretth.com"
419 environment "LD_PRELOAD" => "/opt/flush/flush.so"
422 cron_d "replication-hourly" do
425 command "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/hour"
426 mailto "brett@bretth.com"
427 environment "LD_PRELOAD" => "/opt/flush/flush.so"
430 cron_d "replication-daily" do
433 command "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/day"
434 mailto "brett@bretth.com"
435 environment "LD_PRELOAD" => "/opt/flush/flush.so"
438 cron_d "users-agreed" do
442 cron_d "users-deleted" do
446 cron_d "replication-changesets" do
450 service "replication-minutely.timer" do
451 action [:stop, :disable]
454 service "replication-hourly.timer" do
455 action [:stop, :disable]
458 service "replication-daily.timer" do
459 action [:stop, :disable]
462 cron_d "replication-minutely" do
466 cron_d "replication-hourly" do
470 cron_d "replication-daily" do