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/replicate-minute" do
78 source "replicate-minute.erb"
84 template "/usr/local/bin/replicate-cleanup" do
85 source "replicate-cleanup.erb"
91 template "/usr/local/bin/users-agreed" do
92 source "users-agreed.erb"
98 template "/usr/local/bin/users-deleted" do
99 source "users-deleted.erb"
105 ## Published deleted users directory
107 remote_directory "/store/planet/users_deleted" do
108 source "users_deleted"
117 ## Published replication directory
119 remote_directory "/store/planet/replication" do
120 source "replication-cgi"
129 ## Configuration directory
131 directory "/etc/replication" do
137 ## Transient state directory
139 systemd_tmpfile "/run/replication" do
146 ## Persistent state directory
148 directory "/var/lib/replication" do
154 ## Temporary directory
156 directory "/store/replication" do
164 template "/etc/replication/users-agreed.conf" do
165 source "users-agreed.conf.erb"
169 variables :password => db_passwords["planetdiff"]
172 ## Changeset replication
174 directory "/store/planet/replication/changesets" do
180 template "/etc/replication/changesets.conf" do
181 source "changesets.conf.erb"
185 variables :password => db_passwords["planetdiff"]
188 ## Minutely replication
190 directory "/store/planet/replication/minute" do
196 directory "/var/lib/replication/minute" do
202 directory "/store/replication/minute" do
210 "host" => node[:web][:database_host],
211 "dbname" => "openstreetmap",
212 "user" => "planetdiff",
213 "password" => db_passwords["planetdiff"],
214 "replication_slot" => "osmdbt"
216 "log_dir" => "/var/lib/replication/minute",
217 "changes_dir" => "/store/planet/replication/minute",
218 "tmp_dir" => "/store/replication/minute",
219 "run_dir" => "/run/replication"
222 file "/etc/replication/osmdbt-config.yaml" do
226 content YAML.dump(osmdbt_config)
229 systemd_service "replication-minutely" do
230 description "Minutely replication"
232 working_directory "/etc/replication"
233 exec_start "/usr/local/bin/replicate-minute"
236 protect_system "full"
238 restrict_address_families %w[AF_INET AF_INET6]
239 no_new_privileges true
242 systemd_timer "replication-minutely" do
243 description "Minutely replication"
245 on_unit_active_sec 60
249 ## Hourly replication
251 directory "/store/planet/replication/hour" do
257 directory "/var/lib/replication/hour" do
263 link "/var/lib/replication/hour/data" do
264 to "/store/planet/replication/hour"
267 template "/var/lib/replication/hour/configuration.txt" do
268 source "replication.config.erb"
272 variables :base => "minute", :interval => 3600
275 systemd_service "replication-hourly" do
276 description "Hourly replication"
278 exec_start "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/hour"
281 protect_system "full"
283 restrict_address_families %w[AF_INET AF_INET6]
284 no_new_privileges true
287 systemd_timer "replication-hourly" do
288 description "Daily replication"
289 on_calendar "*-*-* *:02/15:00"
294 directory "/store/planet/replication/day" do
300 directory "/var/lib/replication/day" do
306 link "/var/lib/replication/day/data" do
307 to "/store/planet/replication/day"
310 template "/var/lib/replication/day/configuration.txt" do
311 source "replication.config.erb"
315 variables :base => "hour", :interval => 86400
318 systemd_service "replication-daily" do
319 description "Daily replication"
321 exec_start "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/day"
324 protect_system "full"
326 restrict_address_families %w[AF_INET AF_INET6]
327 no_new_privileges true
330 systemd_timer "replication-daily" do
331 description "Daily replication"
332 on_calendar "*-*-* *:02/15:00"
335 ## Replication cleanup
337 systemd_service "replication-cleanup" do
338 description "Cleanup replication"
340 exec_start "/usr/local/bin/replicate-cleanup"
344 protect_system "full"
346 no_new_privileges true
349 systemd_timer "replication-cleanup" do
350 description "Cleanup replication"
352 on_unit_active_sec 86400
356 ## Enable/disable feeds
358 if node[:planet][:replication] == "enabled"
359 cron_d "users-agreed" do
363 command "/usr/local/bin/users-agreed"
364 mailto "zerebubuth@gmail.com"
367 cron_d "users-deleted" do
371 command "/usr/local/bin/users-deleted"
372 mailto "zerebubuth@gmail.com"
375 cron_d "replication-changesets" do
377 command "/usr/local/bin/replicate-changesets /etc/replication/changesets.conf"
378 mailto "zerebubuth@gmail.com"
381 service "replication-minutely.timer" do
382 action [:enable, :start]
385 service "replication-hourly.timer" do
386 action [:enable, :start]
389 service "replication-daily.timer" do
390 action [:enable, :start]
393 service "replication-cleanup.timer" do
394 action [:enable, :start]
397 cron_d "users-agreed" do
401 cron_d "users-deleted" do
405 cron_d "replication-changesets" do
409 service "replication-minutely.timer" do
410 action [:stop, :disable]
413 service "replication-hourly.timer" do
414 action [:stop, :disable]
417 service "replication-daily.timer" do
418 action [:stop, :disable]
421 service "replication-cleanup.timer" do
422 action [:stop, :disable]