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
315 memory_deny_write_execute false
317 "/store/planet/replication/hour",
318 "/var/lib/replication/hour"
322 systemd_timer "replication-hourly" do
323 description "Daily replication"
324 on_calendar "*-*-* *:02/15:00"
329 directory "/store/planet/replication/day" do
335 directory "/var/lib/replication/day" do
341 link "/var/lib/replication/day/data" do
342 to "/store/planet/replication/day"
345 template "/var/lib/replication/day/configuration.txt" do
346 source "replication.config.erb"
350 variables :base => "hour", :interval => 86400
353 systemd_service "replication-daily" do
354 description "Daily replication"
356 exec_start "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/day"
357 environment "LD_PRELOAD" => "/opt/flush/flush.so"
358 sandbox :enable_network => true
359 memory_deny_write_execute false
361 "/store/planet/replication/day",
362 "/var/lib/replication/day"
366 systemd_timer "replication-daily" do
367 description "Daily replication"
368 on_calendar "*-*-* *:02/15:00"
371 ## Replication cleanup
373 systemd_service "replication-cleanup" do
374 description "Cleanup replication"
376 exec_start "/usr/local/bin/replicate-cleanup"
378 read_write_paths "/var/lib/replication"
381 systemd_timer "replication-cleanup" do
382 description "Cleanup replication"
384 on_unit_active_sec 86400
388 ## Enable/disable feeds
390 if node[:planet][:replication] == "enabled"
391 service "users-agreed.timer" do
392 action [:enable, :start]
395 service "users-deleted.timer" do
396 action [:enable, :start]
399 service "replication-changesets.timer" do
400 action [:enable, :start]
403 service "replication-minutely.timer" do
404 action [:enable, :start]
407 service "replication-hourly.timer" do
408 action [:enable, :start]
411 service "replication-daily.timer" do
412 action [:enable, :start]
415 service "replication-cleanup.timer" do
416 action [:enable, :start]
419 service "users-agreed.timer" do
420 action [:stop, :disable]
423 service "users-deleted.timer" do
424 action [:stop, :disable]
427 service "replication-changesets.timer" do
428 action [:stop, :disable]
431 service "replication-minutely.timer" do
432 action [:stop, :disable]
435 service "replication-hourly.timer" do
436 action [:stop, :disable]
439 service "replication-daily.timer" do
440 action [:stop, :disable]
443 service "replication-cleanup.timer" do
444 action [:stop, :disable]