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
275 "/var/lib/replication/minute"
279 systemd_timer "replication-minutely" do
280 description "Minutely replication"
282 on_unit_active_sec 60
286 ## Hourly replication
288 directory "/store/planet/replication/hour" do
294 directory "/var/lib/replication/hour" do
300 link "/var/lib/replication/hour/data" do
301 to "/store/planet/replication/hour"
304 template "/var/lib/replication/hour/configuration.txt" do
305 source "replication.config.erb"
309 variables :base => "minute", :interval => 3600
312 systemd_service "replication-hourly" do
313 description "Hourly replication"
315 exec_start "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/hour"
316 environment "LD_PRELOAD" => "/opt/flush/flush.so"
317 sandbox :enable_network => true
318 memory_deny_write_execute false
320 "/store/planet/replication/hour",
321 "/var/lib/replication/hour"
325 systemd_timer "replication-hourly" do
326 description "Hourly replication"
327 on_calendar "*-*-* *:02/15:00"
332 directory "/store/planet/replication/day" do
338 directory "/var/lib/replication/day" do
344 link "/var/lib/replication/day/data" do
345 to "/store/planet/replication/day"
348 template "/var/lib/replication/day/configuration.txt" do
349 source "replication.config.erb"
353 variables :base => "hour", :interval => 86400
356 systemd_service "replication-daily" do
357 description "Daily replication"
359 exec_start "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/day"
360 environment "LD_PRELOAD" => "/opt/flush/flush.so"
361 sandbox :enable_network => true
362 memory_deny_write_execute false
364 "/store/planet/replication/day",
365 "/var/lib/replication/day"
369 systemd_timer "replication-daily" do
370 description "Daily replication"
371 on_calendar "*-*-* *:02/15:00"
374 ## Replication cleanup
376 systemd_service "replication-cleanup" do
377 description "Cleanup replication"
379 exec_start "/usr/local/bin/replicate-cleanup"
381 read_write_paths "/var/lib/replication"
384 systemd_timer "replication-cleanup" do
385 description "Cleanup replication"
387 on_unit_active_sec 86400
391 ## Enable/disable feeds
393 if node[:planet][:replication] == "enabled"
394 service "users-agreed.timer" do
395 action [:enable, :start]
398 service "users-deleted.timer" do
399 action [:enable, :start]
402 service "replication-changesets.timer" do
403 action [:enable, :start]
406 service "replication-minutely.timer" do
407 action [:enable, :start]
410 service "replication-hourly.timer" do
411 action [:enable, :start]
414 service "replication-daily.timer" do
415 action [:enable, :start]
418 service "replication-cleanup.timer" do
419 action [:enable, :start]
422 service "users-agreed.timer" do
423 action [:stop, :disable]
426 service "users-deleted.timer" do
427 action [:stop, :disable]
430 service "replication-changesets.timer" do
431 action [:stop, :disable]
434 service "replication-minutely.timer" do
435 action [:stop, :disable]
438 service "replication-hourly.timer" do
439 action [:stop, :disable]
442 service "replication-daily.timer" do
443 action [:stop, :disable]
446 service "replication-cleanup.timer" do
447 action [:stop, :disable]