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"
25 include_recipe "planet::aws"
27 include_recipe "tools"
29 db_passwords = data_bag_item("db", "passwords")
31 ## Install required packages
44 gem_binary node[:ruby][:gem]
47 ## Build preload library to flush files
49 remote_directory "/opt/flush" do
59 execute "/opt/flush/Makefile" do
65 subscribes :run, "remote_directory[/opt/flush]"
70 remote_directory "/usr/local/bin" do
71 source "replication-bin"
80 template "/usr/local/bin/users-agreed" do
81 source "users-agreed.erb"
87 template "/usr/local/bin/users-deleted" do
88 source "users-deleted.erb"
94 ## Published deleted users directory
96 remote_directory "/store/planet/users_deleted" do
97 source "users_deleted"
106 ## Published replication directory
108 remote_directory "/store/planet/replication" do
109 source "replication-cgi"
118 ## Configuration directory
120 directory "/etc/replication" do
126 ## Transient state directory
128 systemd_tmpfile "/run/replication" do
135 ## Persistent state directory
137 directory "/var/lib/replication" do
143 ## Temporary directory
145 directory "/store/replication" do
153 template "/etc/replication/users-agreed.conf" do
154 source "users-agreed.conf.erb"
158 variables :password => db_passwords["planetdiff"]
161 systemd_service "users-agreed" do
162 description "Update list of users accepting CTs"
164 exec_start "/usr/local/bin/users-agreed"
166 sandbox :enable_network => true
167 read_write_paths "/store/planet/users_agreed"
170 systemd_timer "users-agreed" do
171 description "Update list of users accepting CTs"
175 systemd_service "users-deleted" do
176 description "Update list of deleted users"
178 exec_start "/usr/local/bin/users-deleted"
180 sandbox :enable_network => true
181 read_write_paths "/store/planet/users_deleted"
184 systemd_timer "users-deleted" do
185 description "Update list of deleted users"
189 ## Changeset replication
191 directory "/store/planet/replication/changesets" do
197 template "/etc/replication/changesets.conf" do
198 source "changesets.conf.erb"
202 variables :password => db_passwords["planetdiff"]
205 systemd_service "replication-changesets" do
206 description "Changesets replication"
208 exec_start "/usr/local/bin/replicate-changesets /etc/replication/changesets.conf"
209 sandbox :enable_network => true
211 bind_paths "/home/planet"
214 "/store/planet/replication/changesets"
218 systemd_timer "replication-changesets" do
219 description "Changesets replication"
221 on_unit_active_sec 60
225 ## Minutely replication
227 directory "/store/planet/replication/minute" do
233 directory "/var/lib/replication/minute" do
239 directory "/store/replication/minute" do
247 "host" => node[:web][:database_host],
248 "dbname" => "openstreetmap",
249 "user" => "planetdiff",
250 "password" => db_passwords["planetdiff"],
251 "replication_slot" => "osmdbt"
253 "log_dir" => "/var/lib/replication/minute",
254 "changes_dir" => "/store/planet/replication/minute",
255 "tmp_dir" => "/store/replication/minute",
256 "run_dir" => "/run/replication"
259 file "/etc/replication/osmdbt-config.yaml" do
263 content YAML.dump(osmdbt_config)
266 systemd_service "replication-minutely" do
267 description "Minutely replication"
269 working_directory "/etc/replication"
270 exec_start "/usr/local/bin/replicate-minute"
271 sandbox :enable_network => true
273 bind_paths "/home/planet"
277 "/var/lib/replication/minute"
281 systemd_timer "replication-minutely" do
282 description "Minutely replication"
284 on_unit_active_sec 60
288 ## Hourly replication
290 directory "/store/planet/replication/hour" do
296 directory "/var/lib/replication/hour" do
302 link "/var/lib/replication/hour/data" do
303 to "/store/planet/replication/hour"
306 template "/var/lib/replication/hour/configuration.txt" do
307 source "replication.config.erb"
311 variables :base => "minute", :interval => 3600
314 systemd_service "replication-hourly" do
315 description "Hourly replication"
317 exec_start "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/hour"
318 environment "LD_PRELOAD" => "/opt/flush/flush.so"
319 sandbox :enable_network => true
320 memory_deny_write_execute false
322 "/store/planet/replication/hour",
323 "/var/lib/replication/hour"
327 systemd_timer "replication-hourly" do
328 description "Hourly replication"
329 on_calendar "*-*-* *:02/15:00"
334 directory "/store/planet/replication/day" do
340 directory "/var/lib/replication/day" do
346 link "/var/lib/replication/day/data" do
347 to "/store/planet/replication/day"
350 template "/var/lib/replication/day/configuration.txt" do
351 source "replication.config.erb"
355 variables :base => "hour", :interval => 86400
358 systemd_service "replication-daily" do
359 description "Daily replication"
361 exec_start "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/day"
362 environment "LD_PRELOAD" => "/opt/flush/flush.so"
363 sandbox :enable_network => true
364 memory_deny_write_execute false
366 "/store/planet/replication/day",
367 "/var/lib/replication/day"
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"
383 read_write_paths "/var/lib/replication"
386 systemd_timer "replication-cleanup" do
387 description "Cleanup replication"
389 on_unit_active_sec 86400
393 ## Enable/disable feeds
395 if node[:planet][:replication] == "enabled"
396 service "users-agreed.timer" do
397 action [:enable, :start]
400 service "users-deleted.timer" do
401 action [:enable, :start]
404 service "replication-changesets.timer" do
405 action [:enable, :start]
408 service "replication-minutely.timer" do
409 action [:enable, :start]
412 service "replication-hourly.timer" do
413 action [:enable, :start]
416 service "replication-daily.timer" do
417 action [:enable, :start]
420 service "replication-cleanup.timer" do
421 action [:enable, :start]
424 service "users-agreed.timer" do
425 action [:stop, :disable]
428 service "users-deleted.timer" do
429 action [:stop, :disable]
432 service "replication-changesets.timer" do
433 action [:stop, :disable]
436 service "replication-minutely.timer" do
437 action [:stop, :disable]
440 service "replication-hourly.timer" do
441 action [:stop, :disable]
444 service "replication-daily.timer" do
445 action [:stop, :disable]
448 service "replication-cleanup.timer" do
449 action [:stop, :disable]