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
213 "/store/planet/replication/changesets"
217 systemd_timer "replication-changesets" do
218 description "Changesets replication"
220 on_unit_active_sec 60
224 ## Minutely replication
226 directory "/store/planet/replication/minute" do
232 directory "/var/lib/replication/minute" do
238 directory "/store/replication/minute" do
246 "host" => node[:web][:database_host],
247 "dbname" => "openstreetmap",
248 "user" => "planetdiff",
249 "password" => db_passwords["planetdiff"],
250 "replication_slot" => "osmdbt"
252 "log_dir" => "/var/lib/replication/minute",
253 "changes_dir" => "/store/planet/replication/minute",
254 "tmp_dir" => "/store/replication/minute",
255 "run_dir" => "/run/replication"
258 file "/etc/replication/osmdbt-config.yaml" do
262 content YAML.dump(osmdbt_config)
265 systemd_service "replication-minutely" do
266 description "Minutely replication"
268 working_directory "/etc/replication"
269 exec_start "/usr/local/bin/replicate-minute"
270 sandbox :enable_network => true
274 "/var/lib/replication/minute"
278 systemd_timer "replication-minutely" do
279 description "Minutely replication"
281 on_unit_active_sec 60
285 ## Hourly replication
287 directory "/store/planet/replication/hour" do
293 directory "/var/lib/replication/hour" do
299 link "/var/lib/replication/hour/data" do
300 to "/store/planet/replication/hour"
303 template "/var/lib/replication/hour/configuration.txt" do
304 source "replication.config.erb"
308 variables :base => "minute", :interval => 3600
311 systemd_service "replication-hourly" do
312 description "Hourly replication"
314 exec_start "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/hour"
315 environment "LD_PRELOAD" => "/opt/flush/flush.so"
316 sandbox :enable_network => true
317 memory_deny_write_execute false
319 "/store/planet/replication/hour",
320 "/var/lib/replication/hour"
324 systemd_timer "replication-hourly" do
325 description "Hourly replication"
326 on_calendar "*-*-* *:02/15:00"
331 directory "/store/planet/replication/day" do
337 directory "/var/lib/replication/day" do
343 link "/var/lib/replication/day/data" do
344 to "/store/planet/replication/day"
347 template "/var/lib/replication/day/configuration.txt" do
348 source "replication.config.erb"
352 variables :base => "hour", :interval => 86400
355 systemd_service "replication-daily" do
356 description "Daily replication"
358 exec_start "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/day"
359 environment "LD_PRELOAD" => "/opt/flush/flush.so"
360 sandbox :enable_network => true
361 memory_deny_write_execute false
363 "/store/planet/replication/day",
364 "/var/lib/replication/day"
368 systemd_timer "replication-daily" do
369 description "Daily replication"
370 on_calendar "*-*-* *:02/15:00"
373 ## Replication cleanup
375 systemd_service "replication-cleanup" do
376 description "Cleanup replication"
378 exec_start "/usr/local/bin/replicate-cleanup"
380 read_write_paths "/var/lib/replication"
383 systemd_timer "replication-cleanup" do
384 description "Cleanup replication"
386 on_unit_active_sec 86400
390 ## Enable/disable feeds
392 if node[:planet][:replication] == "enabled"
393 service "users-agreed.timer" do
394 action [:enable, :start]
397 service "users-deleted.timer" do
398 action [:enable, :start]
401 service "replication-changesets.timer" do
402 action [:enable, :start]
405 service "replication-minutely.timer" do
406 action [:enable, :start]
409 service "replication-hourly.timer" do
410 action [:enable, :start]
413 service "replication-daily.timer" do
414 action [:enable, :start]
417 service "replication-cleanup.timer" do
418 action [:enable, :start]
421 service "users-agreed.timer" do
422 action [:stop, :disable]
425 service "users-deleted.timer" do
426 action [:stop, :disable]
429 service "replication-changesets.timer" do
430 action [:stop, :disable]
433 service "replication-minutely.timer" do
434 action [:stop, :disable]
437 service "replication-hourly.timer" do
438 action [:stop, :disable]
441 service "replication-daily.timer" do
442 action [:stop, :disable]
445 service "replication-cleanup.timer" do
446 action [:stop, :disable]