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")
41 remote_directory "/opt/flush" do
51 execute "/opt/flush/Makefile" do
57 subscribes :run, "remote_directory[/opt/flush]"
60 remote_directory "/usr/local/bin" do
61 source "replication-bin"
70 template "/usr/local/bin/replicate-minute" do
71 source "replicate-minute.erb"
77 template "/usr/local/bin/users-agreed" do
78 source "users-agreed.erb"
84 template "/usr/local/bin/users-deleted" do
85 source "users-deleted.erb"
91 remote_directory "/store/planet/users_deleted" do
92 source "users_deleted"
101 remote_directory "/store/planet/replication" do
102 source "replication-cgi"
111 directory "/store/planet/replication/changesets" do
117 directory "/store/planet/replication/day" do
123 directory "/store/planet/replication/hour" do
129 directory "/store/planet/replication/minute" do
135 directory "/store/planet/replication/test" do
141 directory "/store/planet/replication/test/day" do
147 directory "/store/planet/replication/test/hour" do
153 directory "/store/planet/replication/test/minute" do
159 directory "/store/replication" do
165 directory "/store/replication/minute" do
171 systemd_tmpfile "/run/replication" do
178 directory "/etc/replication" do
184 directory "/var/run/lock/changeset-replication/" do
190 directory "/var/lib/replication" do
196 directory "/var/lib/replication/test" do
202 template "/etc/replication/auth.conf" do
203 source "replication.auth.erb"
207 variables :password => db_passwords["planetdiff"]
212 "host" => node[:web][:database_host],
213 "dbname" => "openstreetmap",
214 "user" => "planetdiff",
215 "password" => db_passwords["planetdiff"],
216 "replication_slot" => "osmdbt"
218 "log_dir" => "/var/lib/replication/minute",
219 "changes_dir" => "/store/planet/replication/test/minute",
220 "tmp_dir" => "/store/replication/minute",
221 "run_dir" => "/run/replication"
224 file "/etc/replication/osmdbt-config.yaml" do
228 content YAML.dump(osmdbt_config)
231 systemd_service "replication-minutely" do
232 description "Minutely replication"
234 working_directory "/etc/replication"
235 exec_start "/usr/local/bin/replicate-minute"
238 protect_system "full"
240 restrict_address_families %w[AF_INET AF_INET6]
241 no_new_privileges true
244 systemd_timer "replication-minutely" do
245 description "Minutely replication"
247 on_unit_active_sec 60
251 directory "/var/lib/replication/test/hour" do
257 template "/var/lib/replication/test/hour/configuration.txt" do
258 source "replication.config.erb"
262 variables :base => "test/minute", :interval => 3600
265 link "/var/lib/replication/test/hour/data" do
266 to "/store/planet/replication/test/hour"
269 systemd_service "replication-hourly" do
270 description "Hourly replication"
272 exec_start "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/test/hour"
275 protect_system "full"
277 restrict_address_families %w[AF_INET AF_INET6]
278 no_new_privileges true
281 systemd_timer "replication-hourly" do
282 description "Daily replication"
283 on_calendar "*-*-* *:02/15:00"
286 directory "/var/lib/replication/test/day" do
292 template "/var/lib/replication/test/day/configuration.txt" do
293 source "replication.config.erb"
297 variables :base => "test/hour", :interval => 86400
300 link "/var/lib/replication/test/day/data" do
301 to "/store/planet/replication/test/day"
304 systemd_service "replication-daily" do
305 description "Daily replication"
307 exec_start "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/test/day"
310 protect_system "full"
312 restrict_address_families %w[AF_INET AF_INET6]
313 no_new_privileges true
316 systemd_timer "replication-daily" do
317 description "Daily replication"
318 on_calendar "*-*-* *:02/15:00"
321 template "/etc/replication/changesets.conf" do
322 source "changesets.conf.erb"
326 variables :password => db_passwords["planetdiff"]
329 template "/etc/replication/users-agreed.conf" do
330 source "users-agreed.conf.erb"
334 variables :password => db_passwords["planetdiff"]
337 directory "/var/lib/replication/minute" do
343 directory "/var/lib/replication/hour" do
349 template "/var/lib/replication/hour/configuration.txt" do
350 source "replication.config.erb"
354 variables :base => "minute", :interval => 3600
357 link "/var/lib/replication/hour/data" do
358 to "/store/planet/replication/hour"
361 directory "/var/lib/replication/day" do
367 template "/var/lib/replication/day/configuration.txt" do
368 source "replication.config.erb"
372 variables :base => "hour", :interval => 86400
375 link "/var/lib/replication/day/data" do
376 to "/store/planet/replication/day"
379 if node[:planet][:replication] == "enabled"
380 cron_d "users-agreed" do
384 command "/usr/local/bin/users-agreed"
385 mailto "zerebubuth@gmail.com"
388 cron_d "users-deleted" do
392 command "/usr/local/bin/users-deleted"
393 mailto "zerebubuth@gmail.com"
396 cron_d "replication-changesets" do
398 command "/usr/local/bin/replicate-changesets /etc/replication/changesets.conf"
399 mailto "zerebubuth@gmail.com"
402 service "replication-minutely.timer" do
403 action [:enable, :start]
406 service "replication-hourly.timer" do
407 action [:enable, :start]
410 service "replication-daily.timer" do
411 action [:enable, :start]
414 cron_d "replication-minutely" do
416 command "/usr/local/bin/osmosis -q --replicate-apidb authFile=/etc/replication/auth.conf validateSchemaVersion=false --write-replication workingDirectory=/store/planet/replication/minute"
417 mailto "brett@bretth.com"
418 environment "LD_PRELOAD" => "/opt/flush/flush.so"
421 cron_d "replication-hourly" do
424 command "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/hour"
425 mailto "brett@bretth.com"
426 environment "LD_PRELOAD" => "/opt/flush/flush.so"
429 cron_d "replication-daily" do
432 command "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/day"
433 mailto "brett@bretth.com"
434 environment "LD_PRELOAD" => "/opt/flush/flush.so"
437 cron_d "users-agreed" do
441 cron_d "users-deleted" do
445 cron_d "replication-changesets" do
449 service "replication-minutely.timer" do
450 action [:stop, :disable]
453 service "replication-hourly.timer" do
454 action [:stop, :disable]
457 service "replication-daily.timer" do
458 action [:stop, :disable]
461 cron_d "replication-minutely" do
465 cron_d "replication-hourly" do
469 cron_d "replication-daily" do