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
43 gem_package "libxml-ruby" do
44 gem_binary node[:ruby][:gem]
48 gem_binary node[:ruby][:gem]
51 ## Build preload library to flush files
53 remote_directory "/opt/flush" do
63 execute "/opt/flush/Makefile" do
69 subscribes :run, "remote_directory[/opt/flush]"
74 remote_directory "/usr/local/bin" do
75 source "replication-bin"
84 template "/usr/local/bin/users-agreed" do
85 source "users-agreed.erb"
91 template "/usr/local/bin/users-deleted" do
92 source "users-deleted.erb"
98 template "/usr/local/bin/replicate-changesets" do
99 source "replicate-changesets.erb"
105 ## Published deleted users directory
107 remote_directory "/store/planet/users_deleted" do
108 source "users_deleted"
117 ## Published replication directory
119 remote_directory "/store/planet/replication" do
120 source "replication-cgi"
129 ## Configuration directory
131 directory "/etc/replication" do
137 ## Transient state directory
139 systemd_tmpfile "/run/replication" do
146 ## Persistent state directory
148 directory "/var/lib/replication" do
154 ## Temporary directory
156 directory "/store/replication" do
164 template "/etc/replication/users-agreed.conf" do
165 source "users-agreed.conf.erb"
169 variables :password => db_passwords["planetdiff"]
172 systemd_service "users-agreed" do
173 description "Update list of users accepting CTs"
175 exec_start "/usr/local/bin/users-agreed"
177 sandbox :enable_network => true
178 read_write_paths "/store/planet/users_agreed"
181 systemd_timer "users-agreed" do
182 description "Update list of users accepting CTs"
186 systemd_service "users-deleted" do
187 description "Update list of deleted users"
189 exec_start "/usr/local/bin/users-deleted"
191 sandbox :enable_network => true
192 read_write_paths "/store/planet/users_deleted"
195 systemd_timer "users-deleted" do
196 description "Update list of deleted users"
200 ## Changeset replication
202 directory "/store/planet/replication/changesets" do
208 template "/etc/replication/changesets.conf" do
209 source "changesets.conf.erb"
213 variables :password => db_passwords["planetdiff"]
216 systemd_service "replication-changesets" do
217 description "Changesets replication"
219 exec_start "/usr/local/bin/replicate-changesets /etc/replication/changesets.conf"
220 sandbox :enable_network => true
222 bind_paths "/home/planet"
225 "/store/planet/replication/changesets"
229 systemd_timer "replication-changesets" do
230 description "Changesets replication"
232 on_unit_active_sec 60
236 ## Minutely replication
238 directory "/store/planet/replication/minute" do
244 directory "/var/lib/replication/minute" do
250 directory "/store/replication/minute" do
258 "host" => node[:web][:database_host],
259 "dbname" => "openstreetmap",
260 "user" => "planetdiff",
261 "password" => db_passwords["planetdiff"],
262 "replication_slot" => "osmdbt"
264 "log_dir" => "/var/lib/replication/minute",
265 "changes_dir" => "/store/planet/replication/minute",
266 "tmp_dir" => "/store/replication/minute",
267 "run_dir" => "/run/replication"
270 file "/etc/replication/osmdbt-config.yaml" do
274 content YAML.dump(osmdbt_config)
277 systemd_service "replication-minutely" do
278 description "Minutely replication"
280 working_directory "/etc/replication"
281 exec_start "/usr/local/bin/replicate-minute"
282 sandbox :enable_network => true
284 bind_paths "/home/planet"
288 "/var/lib/replication/minute"
292 systemd_timer "replication-minutely" do
293 description "Minutely replication"
295 on_unit_active_sec 60
299 ## Hourly replication
301 directory "/store/planet/replication/hour" do
307 directory "/var/lib/replication/hour" do
313 link "/var/lib/replication/hour/data" do
314 to "/store/planet/replication/hour"
317 template "/var/lib/replication/hour/configuration.txt" do
318 source "replication.config.erb"
322 variables :base => "minute", :interval => 3600
325 systemd_service "replication-hourly" do
326 description "Hourly replication"
328 exec_start "/usr/local/bin/replicate-hour"
329 environment "LD_PRELOAD" => "/opt/flush/flush.so"
330 sandbox :enable_network => true
331 memory_deny_write_execute false
333 bind_paths "/home/planet"
335 "/store/planet/replication/hour",
336 "/var/lib/replication/hour"
340 systemd_timer "replication-hourly" do
341 description "Hourly replication"
342 on_calendar "*-*-* *:02/15:00"
347 directory "/store/planet/replication/day" do
353 directory "/var/lib/replication/day" do
359 link "/var/lib/replication/day/data" do
360 to "/store/planet/replication/day"
363 template "/var/lib/replication/day/configuration.txt" do
364 source "replication.config.erb"
368 variables :base => "hour", :interval => 86400
371 systemd_service "replication-daily" do
372 description "Daily replication"
374 exec_start "/usr/local/bin/replicate-day"
375 environment "LD_PRELOAD" => "/opt/flush/flush.so"
376 sandbox :enable_network => true
377 memory_deny_write_execute false
379 bind_paths "/home/planet"
381 "/store/planet/replication/day",
382 "/var/lib/replication/day"
386 systemd_timer "replication-daily" do
387 description "Daily replication"
388 on_calendar "*-*-* *:02/15:00"
391 ## Replication cleanup
393 systemd_service "replication-cleanup" do
394 description "Cleanup replication"
396 exec_start "/usr/local/bin/replicate-cleanup"
398 read_write_paths "/var/lib/replication"
401 systemd_timer "replication-cleanup" do
402 description "Cleanup replication"
404 on_unit_active_sec 86400
408 ## Enable/disable feeds
410 if node[:planet][:replication] == "enabled"
411 service "users-agreed.timer" do
412 action [:enable, :start]
415 service "users-deleted.timer" do
416 action [:enable, :start]
419 service "replication-changesets.timer" do
420 action [:enable, :start]
423 service "replication-minutely.timer" do
424 action [:enable, :start]
427 service "replication-hourly.timer" do
428 action [:enable, :start]
431 service "replication-daily.timer" do
432 action [:enable, :start]
435 service "replication-cleanup.timer" do
436 action [:enable, :start]
439 service "users-agreed.timer" do
440 action [:stop, :disable]
443 service "users-deleted.timer" do
444 action [:stop, :disable]
447 service "replication-changesets.timer" do
448 action [:stop, :disable]
451 service "replication-minutely.timer" do
452 action [:stop, :disable]
455 service "replication-hourly.timer" do
456 action [:stop, :disable]
459 service "replication-daily.timer" do
460 action [:stop, :disable]
463 service "replication-cleanup.timer" do
464 action [:stop, :disable]