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 ## Changeset replication
160 directory "/store/planet/replication/changesets" do
166 template "/etc/replication/changesets.conf" do
167 source "changesets.conf.erb"
171 variables :password => db_passwords["planetdiff"]
174 ## Minutely replication
176 directory "/store/planet/replication/minute" do
182 directory "/var/lib/replication/minute" do
188 directory "/store/replication/minute" do
196 "host" => node[:web][:database_host],
197 "dbname" => "openstreetmap",
198 "user" => "planetdiff",
199 "password" => db_passwords["planetdiff"],
200 "replication_slot" => "osmdbt"
202 "log_dir" => "/var/lib/replication/minute",
203 "changes_dir" => "/store/planet/replication/minute",
204 "tmp_dir" => "/store/replication/minute",
205 "run_dir" => "/run/replication"
208 file "/etc/replication/osmdbt-config.yaml" do
212 content YAML.dump(osmdbt_config)
215 systemd_service "replication-minutely" do
216 description "Minutely replication"
218 working_directory "/etc/replication"
219 exec_start "/usr/local/bin/replicate-minute"
222 protect_system "full"
224 restrict_address_families %w[AF_INET AF_INET6]
225 no_new_privileges true
228 systemd_timer "replication-minutely" do
229 description "Minutely replication"
231 on_unit_active_sec 60
235 ## Hourly replication
237 directory "/store/planet/replication/hour" do
243 directory "/var/lib/replication/hour" do
249 link "/var/lib/replication/hour/data" do
250 to "/store/planet/replication/hour"
253 template "/var/lib/replication/hour/configuration.txt" do
254 source "replication.config.erb"
258 variables :base => "minute", :interval => 3600
261 systemd_service "replication-hourly" do
262 description "Hourly replication"
264 exec_start "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/hour"
267 protect_system "full"
269 restrict_address_families %w[AF_INET AF_INET6]
270 no_new_privileges true
273 systemd_timer "replication-hourly" do
274 description "Daily replication"
275 on_calendar "*-*-* *:02/15:00"
280 directory "/store/planet/replication/day" do
286 directory "/var/lib/replication/day" do
292 link "/var/lib/replication/day/data" do
293 to "/store/planet/replication/day"
296 template "/var/lib/replication/day/configuration.txt" do
297 source "replication.config.erb"
301 variables :base => "hour", :interval => 86400
304 systemd_service "replication-daily" do
305 description "Daily replication"
307 exec_start "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/day"
310 protect_system "full"
312 restrict_address_families %w[AF_INET AF_INET6]
313 no_new_privileges true
316 systemd_timer "replication-daily" do
317 description "Daily replication"
318 on_calendar "*-*-* *:02/15:00"
321 ## Replication cleanup
323 systemd_service "replication-cleanup" do
324 description "Cleanup replication"
326 exec_start "/usr/local/bin/replicate-cleanup"
330 protect_system "full"
332 no_new_privileges true
335 systemd_timer "replication-cleanup" do
336 description "Cleanup replication"
338 on_unit_active_sec 86400
342 ## Enable/disable feeds
344 if node[:planet][:replication] == "enabled"
345 cron_d "users-agreed" do
349 command "/usr/local/bin/users-agreed"
350 mailto "zerebubuth@gmail.com"
353 cron_d "users-deleted" do
357 command "/usr/local/bin/users-deleted"
358 mailto "zerebubuth@gmail.com"
361 cron_d "replication-changesets" do
363 command "/usr/local/bin/replicate-changesets /etc/replication/changesets.conf"
364 mailto "zerebubuth@gmail.com"
367 service "replication-minutely.timer" do
368 action [:enable, :start]
371 service "replication-hourly.timer" do
372 action [:enable, :start]
375 service "replication-daily.timer" do
376 action [:enable, :start]
379 service "replication-cleanup.timer" do
380 action [:enable, :start]
383 cron_d "users-agreed" do
387 cron_d "users-deleted" do
391 cron_d "replication-changesets" do
395 service "replication-minutely.timer" do
396 action [:stop, :disable]
399 service "replication-hourly.timer" do
400 action [:stop, :disable]
403 service "replication-daily.timer" do
404 action [:stop, :disable]
407 service "replication-cleanup.timer" do
408 action [:stop, :disable]