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"
28 db_passwords = data_bag_item("db", "passwords")
30 ## Install required packages
43 gem_binary node[:ruby][:gem]
46 ## Build preload library to flush files
48 remote_directory "/opt/flush" do
58 execute "/opt/flush/Makefile" do
64 subscribes :run, "remote_directory[/opt/flush]"
69 remote_directory "/usr/local/bin" do
70 source "replication-bin"
79 template "/usr/local/bin/users-agreed" do
80 source "users-agreed.erb"
86 template "/usr/local/bin/users-deleted" do
87 source "users-deleted.erb"
93 ## Published deleted users directory
95 remote_directory "/store/planet/users_deleted" do
96 source "users_deleted"
105 ## Published replication directory
107 remote_directory "/store/planet/replication" do
108 source "replication-cgi"
117 ## Configuration directory
119 directory "/etc/replication" do
125 ## Transient state directory
127 systemd_tmpfile "/run/replication" do
134 ## Persistent state directory
136 directory "/var/lib/replication" do
142 ## Temporary directory
144 directory "/store/replication" do
152 template "/etc/replication/users-agreed.conf" do
153 source "users-agreed.conf.erb"
157 variables :password => db_passwords["planetdiff"]
160 systemd_service "users-agreed" do
161 description "Update list of users accepting CTs"
163 exec_start "/usr/local/bin/users-agreed"
165 sandbox :enable_network => true
166 read_write_paths "/store/planet/users_agreed"
169 systemd_timer "users-agreed" do
170 description "Update list of users accepting CTs"
174 systemd_service "users-deleted" do
175 description "Update list of deleted users"
177 exec_start "/usr/local/bin/users-deleted"
179 sandbox :enable_network => true
180 read_write_paths "/store/planet/users_deleted"
183 systemd_timer "users-deleted" do
184 description "Update list of deleted users"
188 ## Changeset replication
190 directory "/store/planet/replication/changesets" do
196 template "/etc/replication/changesets.conf" do
197 source "changesets.conf.erb"
201 variables :password => db_passwords["planetdiff"]
204 systemd_service "replication-changesets" do
205 description "Changesets replication"
207 exec_start "/usr/local/bin/replicate-changesets /etc/replication/changesets.conf"
208 sandbox :enable_network => true
211 "/store/planet/replication/changesets"
215 systemd_timer "replication-changesets" do
216 description "Changesets replication"
218 on_unit_active_sec 60
222 ## Minutely replication
224 directory "/store/planet/replication/minute" do
230 directory "/var/lib/replication/minute" do
236 directory "/store/replication/minute" do
244 "host" => node[:web][:database_host],
245 "dbname" => "openstreetmap",
246 "user" => "planetdiff",
247 "password" => db_passwords["planetdiff"],
248 "replication_slot" => "osmdbt"
250 "log_dir" => "/var/lib/replication/minute",
251 "changes_dir" => "/store/planet/replication/minute",
252 "tmp_dir" => "/store/replication/minute",
253 "run_dir" => "/run/replication"
256 file "/etc/replication/osmdbt-config.yaml" do
260 content YAML.dump(osmdbt_config)
263 systemd_service "replication-minutely" do
264 description "Minutely replication"
266 working_directory "/etc/replication"
267 exec_start "/usr/local/bin/replicate-minute"
268 sandbox :enable_network => true
272 "/var/lib/replication/minute"
276 systemd_timer "replication-minutely" do
277 description "Minutely replication"
279 on_unit_active_sec 60
283 ## Hourly replication
285 directory "/store/planet/replication/hour" do
291 directory "/var/lib/replication/hour" do
297 link "/var/lib/replication/hour/data" do
298 to "/store/planet/replication/hour"
301 template "/var/lib/replication/hour/configuration.txt" do
302 source "replication.config.erb"
306 variables :base => "minute", :interval => 3600
309 systemd_service "replication-hourly" do
310 description "Hourly replication"
312 exec_start "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/hour"
313 environment "LD_PRELOAD" => "/opt/flush/flush.so"
314 sandbox :enable_network => true
316 "/store/planet/replication/hour",
317 "/var/lib/replication/hour"
321 systemd_timer "replication-hourly" do
322 description "Daily replication"
323 on_calendar "*-*-* *:02/15:00"
328 directory "/store/planet/replication/day" do
334 directory "/var/lib/replication/day" do
340 link "/var/lib/replication/day/data" do
341 to "/store/planet/replication/day"
344 template "/var/lib/replication/day/configuration.txt" do
345 source "replication.config.erb"
349 variables :base => "hour", :interval => 86400
352 systemd_service "replication-daily" do
353 description "Daily replication"
355 exec_start "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/day"
356 environment "LD_PRELOAD" => "/opt/flush/flush.so"
357 sandbox :enable_network => true
359 "/store/planet/replication/day",
360 "/var/lib/replication/day"
364 systemd_timer "replication-daily" do
365 description "Daily replication"
366 on_calendar "*-*-* *:02/15:00"
369 ## Replication cleanup
371 systemd_service "replication-cleanup" do
372 description "Cleanup replication"
374 exec_start "/usr/local/bin/replicate-cleanup"
376 read_write_paths "/var/lib/replication"
379 systemd_timer "replication-cleanup" do
380 description "Cleanup replication"
382 on_unit_active_sec 86400
386 ## Enable/disable feeds
388 if node[:planet][:replication] == "enabled"
389 service "users-agreed.timer" do
390 action [:enable, :start]
393 service "users-deleted.timer" do
394 action [:enable, :start]
397 service "replication-changesets.timer" do
398 action [:enable, :start]
401 service "replication-minutely.timer" do
402 action [:enable, :start]
405 service "replication-hourly.timer" do
406 action [:enable, :start]
409 service "replication-daily.timer" do
410 action [:enable, :start]
413 service "replication-cleanup.timer" do
414 action [:enable, :start]
417 service "users-agreed.timer" do
418 action [:stop, :disable]
421 service "users-deleted.timer" do
422 action [:stop, :disable]
425 service "replication-changesets.timer" do
426 action [:stop, :disable]
429 service "replication-minutely.timer" do
430 action [:stop, :disable]
433 service "replication-hourly.timer" do
434 action [:stop, :disable]
437 service "replication-daily.timer" do
438 action [:stop, :disable]
441 service "replication-cleanup.timer" do
442 action [:stop, :disable]