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 include_recipe "tools"
27 include_recipe "awscli"
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
212 "/store/planet/replication/changesets"
216 systemd_timer "replication-changesets" do
217 description "Changesets replication"
219 on_unit_active_sec 60
223 ## Minutely replication
225 directory "/store/planet/replication/minute" do
231 directory "/var/lib/replication/minute" do
237 directory "/store/replication/minute" do
245 "host" => node[:web][:database_host],
246 "dbname" => "openstreetmap",
247 "user" => "planetdiff",
248 "password" => db_passwords["planetdiff"],
249 "replication_slot" => "osmdbt"
251 "log_dir" => "/var/lib/replication/minute",
252 "changes_dir" => "/store/planet/replication/minute",
253 "tmp_dir" => "/store/replication/minute",
254 "run_dir" => "/run/replication"
257 file "/etc/replication/osmdbt-config.yaml" do
261 content YAML.dump(osmdbt_config)
264 systemd_service "replication-minutely" do
265 description "Minutely replication"
267 working_directory "/etc/replication"
268 exec_start "/usr/local/bin/replicate-minute"
269 sandbox :enable_network => true
273 "/var/lib/replication/minute"
277 systemd_timer "replication-minutely" do
278 description "Minutely replication"
280 on_unit_active_sec 60
284 ## Hourly replication
286 directory "/store/planet/replication/hour" do
292 directory "/var/lib/replication/hour" do
298 link "/var/lib/replication/hour/data" do
299 to "/store/planet/replication/hour"
302 template "/var/lib/replication/hour/configuration.txt" do
303 source "replication.config.erb"
307 variables :base => "minute", :interval => 3600
310 systemd_service "replication-hourly" do
311 description "Hourly replication"
313 exec_start "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/hour"
314 environment "LD_PRELOAD" => "/opt/flush/flush.so"
315 sandbox :enable_network => true
316 memory_deny_write_execute false
318 "/store/planet/replication/hour",
319 "/var/lib/replication/hour"
323 systemd_timer "replication-hourly" do
324 description "Hourly replication"
325 on_calendar "*-*-* *:02/15:00"
330 directory "/store/planet/replication/day" do
336 directory "/var/lib/replication/day" do
342 link "/var/lib/replication/day/data" do
343 to "/store/planet/replication/day"
346 template "/var/lib/replication/day/configuration.txt" do
347 source "replication.config.erb"
351 variables :base => "hour", :interval => 86400
354 systemd_service "replication-daily" do
355 description "Daily replication"
357 exec_start "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/day"
358 environment "LD_PRELOAD" => "/opt/flush/flush.so"
359 sandbox :enable_network => true
360 memory_deny_write_execute false
362 "/store/planet/replication/day",
363 "/var/lib/replication/day"
367 systemd_timer "replication-daily" do
368 description "Daily replication"
369 on_calendar "*-*-* *:02/15:00"
372 ## Replication cleanup
374 systemd_service "replication-cleanup" do
375 description "Cleanup replication"
377 exec_start "/usr/local/bin/replicate-cleanup"
379 read_write_paths "/var/lib/replication"
382 systemd_timer "replication-cleanup" do
383 description "Cleanup replication"
385 on_unit_active_sec 86400
389 ## Enable/disable feeds
391 if node[:planet][:replication] == "enabled"
392 service "users-agreed.timer" do
393 action [:enable, :start]
396 service "users-deleted.timer" do
397 action [:enable, :start]
400 service "replication-changesets.timer" do
401 action [:enable, :start]
404 service "replication-minutely.timer" do
405 action [:enable, :start]
408 service "replication-hourly.timer" do
409 action [:enable, :start]
412 service "replication-daily.timer" do
413 action [:enable, :start]
416 service "replication-cleanup.timer" do
417 action [:enable, :start]
420 service "users-agreed.timer" do
421 action [:stop, :disable]
424 service "users-deleted.timer" do
425 action [:stop, :disable]
428 service "replication-changesets.timer" do
429 action [:stop, :disable]
432 service "replication-minutely.timer" do
433 action [:stop, :disable]
436 service "replication-hourly.timer" do
437 action [:stop, :disable]
440 service "replication-daily.timer" do
441 action [:stop, :disable]
444 service "replication-cleanup.timer" do
445 action [:stop, :disable]