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"
290 "/var/lib/replication/minute"
292 restrict_address_families %w[AF_INET AF_INET6]
293 no_new_privileges true
296 systemd_timer "replication-minutely" do
297 description "Minutely replication"
299 on_unit_active_sec 60
303 ## Hourly replication
305 directory "/store/planet/replication/hour" do
311 directory "/var/lib/replication/hour" do
317 link "/var/lib/replication/hour/data" do
318 to "/store/planet/replication/hour"
321 template "/var/lib/replication/hour/configuration.txt" do
322 source "replication.config.erb"
326 variables :base => "minute", :interval => 3600
329 systemd_service "replication-hourly" do
330 description "Hourly replication"
332 exec_start "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/hour"
333 environment "LD_PRELOAD" => "/opt/flush/flush.so"
336 protect_system "strict"
339 "/store/planet/replication/hour",
340 "/var/lib/replication/hour"
342 restrict_address_families %w[AF_INET AF_INET6]
343 no_new_privileges true
346 systemd_timer "replication-hourly" do
347 description "Daily replication"
348 on_calendar "*-*-* *:02/15:00"
353 directory "/store/planet/replication/day" do
359 directory "/var/lib/replication/day" do
365 link "/var/lib/replication/day/data" do
366 to "/store/planet/replication/day"
369 template "/var/lib/replication/day/configuration.txt" do
370 source "replication.config.erb"
374 variables :base => "hour", :interval => 86400
377 systemd_service "replication-daily" do
378 description "Daily replication"
380 exec_start "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/day"
381 environment "LD_PRELOAD" => "/opt/flush/flush.so"
384 protect_system "strict"
387 "/store/planet/replication/day",
388 "/var/lib/replication/day"
390 restrict_address_families %w[AF_INET AF_INET6]
391 no_new_privileges true
394 systemd_timer "replication-daily" do
395 description "Daily replication"
396 on_calendar "*-*-* *:02/15:00"
399 ## Replication cleanup
401 systemd_service "replication-cleanup" do
402 description "Cleanup replication"
404 exec_start "/usr/local/bin/replicate-cleanup"
408 protect_system "strict"
410 read_write_paths "/var/lib/replication"
411 no_new_privileges true
414 systemd_timer "replication-cleanup" do
415 description "Cleanup replication"
417 on_unit_active_sec 86400
421 ## Enable/disable feeds
423 if node[:planet][:replication] == "enabled"
424 service "users-agreed.timer" do
425 action [:enable, :start]
428 service "users-deleted.timer" do
429 action [:enable, :start]
432 service "replication-changesets.timer" do
433 action [:enable, :start]
436 service "replication-minutely.timer" do
437 action [:enable, :start]
440 service "replication-hourly.timer" do
441 action [:enable, :start]
444 service "replication-daily.timer" do
445 action [:enable, :start]
448 service "replication-cleanup.timer" do
449 action [:enable, :start]
452 service "users-agreed.timer" do
453 action [:stop, :disable]
456 service "users-deleted.timer" do
457 action [:stop, :disable]
460 service "replication-changesets.timer" do
461 action [:stop, :disable]
464 service "replication-minutely.timer" do
465 action [:stop, :disable]
468 service "replication-hourly.timer" do
469 action [:stop, :disable]
472 service "replication-daily.timer" do
473 action [:stop, :disable]
476 service "replication-cleanup.timer" do
477 action [:stop, :disable]