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"
167 protect_system "strict"
169 read_write_paths "/store/planet/users_agreed"
170 restrict_address_families %w[AF_INET AF_INET6]
171 no_new_privileges true
174 systemd_timer "users-agreed" do
175 description "Update list of users accepting CTs"
179 systemd_service "users-deleted" do
180 description "Update list of deleted users"
182 exec_start "/usr/local/bin/users-deleted"
186 protect_system "strict"
188 read_write_paths "/store/planet/users_deleted"
189 restrict_address_families %w[AF_INET AF_INET6]
190 no_new_privileges true
193 systemd_timer "users-deleted" do
194 description "Update list of deleted users"
198 ## Changeset replication
200 directory "/store/planet/replication/changesets" do
206 template "/etc/replication/changesets.conf" do
207 source "changesets.conf.erb"
211 variables :password => db_passwords["planetdiff"]
214 systemd_service "replication-changesets" do
215 description "Changesets replication"
217 exec_start "/usr/local/bin/replicate-changesets /etc/replication/changesets.conf"
220 protect_system "strict"
224 "/store/planet/replication/changesets"
226 restrict_address_families %w[AF_INET AF_INET6]
227 no_new_privileges true
230 systemd_timer "replication-changesets" do
231 description "Changesets replication"
233 on_unit_active_sec 60
237 ## Minutely replication
239 directory "/store/planet/replication/minute" do
245 directory "/var/lib/replication/minute" do
251 directory "/store/replication/minute" do
259 "host" => node[:web][:database_host],
260 "dbname" => "openstreetmap",
261 "user" => "planetdiff",
262 "password" => db_passwords["planetdiff"],
263 "replication_slot" => "osmdbt"
265 "log_dir" => "/var/lib/replication/minute",
266 "changes_dir" => "/store/planet/replication/minute",
267 "tmp_dir" => "/store/replication/minute",
268 "run_dir" => "/run/replication"
271 file "/etc/replication/osmdbt-config.yaml" do
275 content YAML.dump(osmdbt_config)
278 systemd_service "replication-minutely" do
279 description "Minutely replication"
281 working_directory "/etc/replication"
282 exec_start "/usr/local/bin/replicate-minute"
285 protect_system "strict"
289 "/store/replication/minute",
290 "/store/planet/replication/minute",
291 "/var/lib/replication/minute"
293 restrict_address_families %w[AF_INET AF_INET6]
294 no_new_privileges true
297 systemd_timer "replication-minutely" do
298 description "Minutely replication"
300 on_unit_active_sec 60
304 ## Hourly replication
306 directory "/store/planet/replication/hour" do
312 directory "/var/lib/replication/hour" do
318 link "/var/lib/replication/hour/data" do
319 to "/store/planet/replication/hour"
322 template "/var/lib/replication/hour/configuration.txt" do
323 source "replication.config.erb"
327 variables :base => "minute", :interval => 3600
330 systemd_service "replication-hourly" do
331 description "Hourly replication"
333 exec_start "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/hour"
334 environment "LD_PRELOAD" => "/opt/flush/flush.so"
337 protect_system "strict"
340 "/store/planet/replication/hour",
341 "/var/lib/replication/hour"
343 restrict_address_families %w[AF_INET AF_INET6]
344 no_new_privileges true
347 systemd_timer "replication-hourly" do
348 description "Daily replication"
349 on_calendar "*-*-* *:02/15:00"
354 directory "/store/planet/replication/day" do
360 directory "/var/lib/replication/day" do
366 link "/var/lib/replication/day/data" do
367 to "/store/planet/replication/day"
370 template "/var/lib/replication/day/configuration.txt" do
371 source "replication.config.erb"
375 variables :base => "hour", :interval => 86400
378 systemd_service "replication-daily" do
379 description "Daily replication"
381 exec_start "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/day"
382 environment "LD_PRELOAD" => "/opt/flush/flush.so"
385 protect_system "strict"
388 "/store/planet/replication/day",
389 "/var/lib/replication/day"
391 restrict_address_families %w[AF_INET AF_INET6]
392 no_new_privileges true
395 systemd_timer "replication-daily" do
396 description "Daily replication"
397 on_calendar "*-*-* *:02/15:00"
400 ## Replication cleanup
402 systemd_service "replication-cleanup" do
403 description "Cleanup replication"
405 exec_start "/usr/local/bin/replicate-cleanup"
409 protect_system "strict"
411 read_write_paths "/var/lib/replication"
412 no_new_privileges true
415 systemd_timer "replication-cleanup" do
416 description "Cleanup replication"
418 on_unit_active_sec 86400
422 ## Enable/disable feeds
424 if node[:planet][:replication] == "enabled"
425 service "users-agreed.timer" do
426 action [:enable, :start]
429 service "users-deleted.timer" do
430 action [:enable, :start]
433 service "replication-changesets.timer" do
434 action [:enable, :start]
437 service "replication-minutely.timer" do
438 action [:enable, :start]
441 service "replication-hourly.timer" do
442 action [:enable, :start]
445 service "replication-daily.timer" do
446 action [:enable, :start]
449 service "replication-cleanup.timer" do
450 action [:enable, :start]
453 service "users-agreed.timer" do
454 action [:stop, :disable]
457 service "users-deleted.timer" do
458 action [:stop, :disable]
461 service "replication-changesets.timer" do
462 action [:stop, :disable]
465 service "replication-minutely.timer" do
466 action [:stop, :disable]
469 service "replication-hourly.timer" do
470 action [:stop, :disable]
473 service "replication-daily.timer" do
474 action [:stop, :disable]
477 service "replication-cleanup.timer" do
478 action [:stop, :disable]