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 db_passwords = data_bag_item("db", "passwords")
28 ## Install required packages
44 ## Build preload library to flush files
46 remote_directory "/opt/flush" do
56 execute "/opt/flush/Makefile" do
62 subscribes :run, "remote_directory[/opt/flush]"
67 remote_directory "/usr/local/bin" do
68 source "replication-bin"
77 template "/usr/local/bin/users-agreed" do
78 source "users-agreed.erb"
84 template "/usr/local/bin/users-deleted" do
85 source "users-deleted.erb"
91 ## Published deleted users directory
93 remote_directory "/store/planet/users_deleted" do
94 source "users_deleted"
103 ## Published replication directory
105 remote_directory "/store/planet/replication" do
106 source "replication-cgi"
115 ## Configuration directory
117 directory "/etc/replication" do
123 ## Transient state directory
125 systemd_tmpfile "/run/replication" do
132 ## Persistent state directory
134 directory "/var/lib/replication" do
140 ## Temporary directory
142 directory "/store/replication" do
150 template "/etc/replication/users-agreed.conf" do
151 source "users-agreed.conf.erb"
155 variables :password => db_passwords["planetdiff"]
158 systemd_service "users-agreed" do
159 description "Update list of users accepting CTs"
161 exec_start "/usr/local/bin/users-agreed"
164 protect_system "full"
166 restrict_address_families %w[AF_INET AF_INET6]
167 no_new_privileges true
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"
181 protect_system "full"
183 restrict_address_families %w[AF_INET AF_INET6]
184 no_new_privileges true
187 systemd_timer "users-deleted" do
188 description "Update list of deleted users"
192 ## Changeset replication
194 directory "/store/planet/replication/changesets" do
200 template "/etc/replication/changesets.conf" do
201 source "changesets.conf.erb"
205 variables :password => db_passwords["planetdiff"]
208 systemd_service "replication-changesets" do
209 description "Changesets replication"
211 exec_start "/usr/local/bin/replicate-changesets /etc/replication/changesets.conf"
214 protect_system "full"
216 restrict_address_families %w[AF_INET AF_INET6]
217 no_new_privileges true
220 systemd_timer "replication-changesets" do
221 description "Changesets replication"
223 on_unit_active_sec 60
227 ## Minutely replication
229 directory "/store/planet/replication/minute" do
235 directory "/var/lib/replication/minute" do
241 directory "/store/replication/minute" do
249 "host" => node[:web][:database_host],
250 "dbname" => "openstreetmap",
251 "user" => "planetdiff",
252 "password" => db_passwords["planetdiff"],
253 "replication_slot" => "osmdbt"
255 "log_dir" => "/var/lib/replication/minute",
256 "changes_dir" => "/store/planet/replication/minute",
257 "tmp_dir" => "/store/replication/minute",
258 "run_dir" => "/run/replication"
261 file "/etc/replication/osmdbt-config.yaml" do
265 content YAML.dump(osmdbt_config)
268 systemd_service "replication-minutely" do
269 description "Minutely replication"
271 working_directory "/etc/replication"
272 exec_start "/usr/local/bin/replicate-minute"
275 protect_system "full"
277 restrict_address_families %w[AF_INET AF_INET6]
278 no_new_privileges true
281 systemd_timer "replication-minutely" do
282 description "Minutely replication"
284 on_unit_active_sec 60
288 ## Hourly replication
290 directory "/store/planet/replication/hour" do
296 directory "/var/lib/replication/hour" do
302 link "/var/lib/replication/hour/data" do
303 to "/store/planet/replication/hour"
306 template "/var/lib/replication/hour/configuration.txt" do
307 source "replication.config.erb"
311 variables :base => "minute", :interval => 3600
314 systemd_service "replication-hourly" do
315 description "Hourly replication"
317 exec_start "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/hour"
320 protect_system "full"
322 restrict_address_families %w[AF_INET AF_INET6]
323 no_new_privileges true
326 systemd_timer "replication-hourly" do
327 description "Daily replication"
328 on_calendar "*-*-* *:02/15:00"
333 directory "/store/planet/replication/day" do
339 directory "/var/lib/replication/day" do
345 link "/var/lib/replication/day/data" do
346 to "/store/planet/replication/day"
349 template "/var/lib/replication/day/configuration.txt" do
350 source "replication.config.erb"
354 variables :base => "hour", :interval => 86400
357 systemd_service "replication-daily" do
358 description "Daily replication"
360 exec_start "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/day"
363 protect_system "full"
365 restrict_address_families %w[AF_INET AF_INET6]
366 no_new_privileges true
369 systemd_timer "replication-daily" do
370 description "Daily replication"
371 on_calendar "*-*-* *:02/15:00"
374 ## Replication cleanup
376 systemd_service "replication-cleanup" do
377 description "Cleanup replication"
379 exec_start "/usr/local/bin/replicate-cleanup"
383 protect_system "full"
385 no_new_privileges true
388 systemd_timer "replication-cleanup" do
389 description "Cleanup replication"
391 on_unit_active_sec 86400
395 ## Enable/disable feeds
397 if node[:planet][:replication] == "enabled"
398 service "users-agreed.timer" do
399 action [:enable, :start]
402 service "users-deleted.timer" do
403 action [:enable, :start]
406 service "replication-changesets.timer" do
407 action [:enable, :start]
410 service "replication-minutely.timer" do
411 action [:enable, :start]
414 service "replication-hourly.timer" do
415 action [:enable, :start]
418 service "replication-daily.timer" do
419 action [:enable, :start]
422 service "replication-cleanup.timer" do
423 action [:enable, :start]
426 service "users-agreed.timer" do
427 action [:stop, :disable]
430 service "users-deleted.timer" do
431 action [:stop, :disable]
434 service "replication-changesets.timer" do
435 action [:stop, :disable]
438 service "replication-minutely.timer" do
439 action [:stop, :disable]
442 service "replication-hourly.timer" do
443 action [:stop, :disable]
446 service "replication-daily.timer" do
447 action [:stop, :disable]
450 service "replication-cleanup.timer" do
451 action [:stop, :disable]