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/users-agreed" do
85 source "users-agreed.erb"
91 template "/usr/local/bin/users-deleted" do
92 source "users-deleted.erb"
98 ## Published deleted users directory
100 remote_directory "/store/planet/users_deleted" do
101 source "users_deleted"
110 ## Published replication directory
112 remote_directory "/store/planet/replication" do
113 source "replication-cgi"
122 ## Configuration directory
124 directory "/etc/replication" do
130 ## Transient state directory
132 systemd_tmpfile "/run/replication" do
139 ## Persistent state directory
141 directory "/var/lib/replication" do
147 ## Temporary directory
149 directory "/store/replication" do
157 template "/etc/replication/users-agreed.conf" do
158 source "users-agreed.conf.erb"
162 variables :password => db_passwords["planetdiff"]
165 ## Changeset replication
167 directory "/store/planet/replication/changesets" do
173 template "/etc/replication/changesets.conf" do
174 source "changesets.conf.erb"
178 variables :password => db_passwords["planetdiff"]
181 ## Minutely replication
183 directory "/store/planet/replication/minute" do
189 directory "/var/lib/replication/minute" do
195 directory "/store/replication/minute" do
203 "host" => node[:web][:database_host],
204 "dbname" => "openstreetmap",
205 "user" => "planetdiff",
206 "password" => db_passwords["planetdiff"],
207 "replication_slot" => "osmdbt"
209 "log_dir" => "/var/lib/replication/minute",
210 "changes_dir" => "/store/planet/replication/minute",
211 "tmp_dir" => "/store/replication/minute",
212 "run_dir" => "/run/replication"
215 file "/etc/replication/osmdbt-config.yaml" do
219 content YAML.dump(osmdbt_config)
222 systemd_service "replication-minutely" do
223 description "Minutely replication"
225 working_directory "/etc/replication"
226 exec_start "/usr/local/bin/replicate-minute"
229 protect_system "full"
231 restrict_address_families %w[AF_INET AF_INET6]
232 no_new_privileges true
235 systemd_timer "replication-minutely" do
236 description "Minutely replication"
238 on_unit_active_sec 60
242 ## Hourly replication
244 directory "/store/planet/replication/hour" do
250 directory "/var/lib/replication/hour" do
256 link "/var/lib/replication/hour/data" do
257 to "/store/planet/replication/hour"
260 template "/var/lib/replication/hour/configuration.txt" do
261 source "replication.config.erb"
265 variables :base => "minute", :interval => 3600
268 systemd_service "replication-hourly" do
269 description "Hourly replication"
271 exec_start "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/hour"
274 protect_system "full"
276 restrict_address_families %w[AF_INET AF_INET6]
277 no_new_privileges true
280 systemd_timer "replication-hourly" do
281 description "Daily replication"
282 on_calendar "*-*-* *:02/15:00"
287 directory "/store/planet/replication/day" do
293 directory "/var/lib/replication/day" do
299 link "/var/lib/replication/day/data" do
300 to "/store/planet/replication/day"
303 template "/var/lib/replication/day/configuration.txt" do
304 source "replication.config.erb"
308 variables :base => "hour", :interval => 86400
311 systemd_service "replication-daily" do
312 description "Daily replication"
314 exec_start "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/day"
317 protect_system "full"
319 restrict_address_families %w[AF_INET AF_INET6]
320 no_new_privileges true
323 systemd_timer "replication-daily" do
324 description "Daily replication"
325 on_calendar "*-*-* *:02/15:00"
328 ## Enable/disable feeds
330 if node[:planet][:replication] == "enabled"
331 cron_d "users-agreed" do
335 command "/usr/local/bin/users-agreed"
336 mailto "zerebubuth@gmail.com"
339 cron_d "users-deleted" do
343 command "/usr/local/bin/users-deleted"
344 mailto "zerebubuth@gmail.com"
347 cron_d "replication-changesets" do
349 command "/usr/local/bin/replicate-changesets /etc/replication/changesets.conf"
350 mailto "zerebubuth@gmail.com"
353 service "replication-minutely.timer" do
354 action [:enable, :start]
357 service "replication-hourly.timer" do
358 action [:enable, :start]
361 service "replication-daily.timer" do
362 action [:enable, :start]
365 cron_d "users-agreed" do
369 cron_d "users-deleted" do
373 cron_d "replication-changesets" do
377 service "replication-minutely.timer" do
378 action [:stop, :disable]
381 service "replication-hourly.timer" do
382 action [:stop, :disable]
385 service "replication-daily.timer" do
386 action [:stop, :disable]