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"
23 include_recipe "osmosis"
25 db_passwords = data_bag_item("db", "passwords")
40 remote_directory "/opt/flush" do
50 execute "/opt/flush/Makefile" do
56 subscribes :run, "remote_directory[/opt/flush]"
59 remote_directory "/usr/local/bin" do
60 source "replication-bin"
69 template "/usr/local/bin/replicate-minute" do
70 source "replicate-minute.erb"
76 template "/usr/local/bin/users-agreed" do
77 source "users-agreed.erb"
83 template "/usr/local/bin/users-deleted" do
84 source "users-deleted.erb"
90 remote_directory "/store/planet/users_deleted" do
91 source "users_deleted"
100 remote_directory "/store/planet/replication" do
101 source "replication-cgi"
110 directory "/store/planet/replication/changesets" do
116 directory "/store/planet/replication/day" do
122 directory "/store/planet/replication/hour" do
128 directory "/store/planet/replication/minute" do
134 directory "/store/planet/replication/test" do
140 directory "/store/planet/replication/test/minute" do
146 directory "/store/replication" do
152 directory "/store/replication/minute" do
158 systemd_tmpfile "/run/replication" do
165 directory "/etc/replication" do
171 directory "/var/run/lock/changeset-replication/" do
177 template "/etc/replication/auth.conf" do
178 source "replication.auth.erb"
182 variables :password => db_passwords["planetdiff"]
187 "host" => node[:web][:database_host],
188 "dbname" => "openstreetmap",
189 "user" => "planetdiff",
190 "password" => db_passwords["planetdiff"],
191 "replication_slot" => "osmdbt"
193 "log_dir" => "/var/lib/replication/minute",
194 "changes_dir" => "/store/planet/replication/test/minute",
195 "tmp_dir" => "/store/replication/minute",
196 "run_dir" => "/run/replication"
199 file "/etc/replication/osmdbt-config.yaml" do
203 content YAML.dump(osmdbt_config)
206 systemd_service "replication-minutely" do
207 description "Minutely replication"
209 working_directory "/etc/replication"
210 exec_start "/usr/local/bin/replicate-minute"
213 protect_system "full"
215 restrict_address_families %w[AF_INET AF_INET6]
216 no_new_privileges true
219 systemd_timer "replication-minutely" do
220 description "Minutely replication"
222 on_unit_active_sec 60
226 template "/etc/replication/changesets.conf" do
227 source "changesets.conf.erb"
231 variables :password => db_passwords["planetdiff"]
234 template "/etc/replication/users-agreed.conf" do
235 source "users-agreed.conf.erb"
239 variables :password => db_passwords["planetdiff"]
242 directory "/var/lib/replication" do
248 directory "/var/lib/replication/minute" do
254 directory "/var/lib/replication/hour" do
260 template "/var/lib/replication/hour/configuration.txt" do
261 source "replication.config.erb"
265 variables :base => "minute", :interval => 3600
268 link "/var/lib/replication/hour/data" do
269 to "/store/planet/replication/hour"
272 directory "/var/lib/replication/day" do
278 template "/var/lib/replication/day/configuration.txt" do
279 source "replication.config.erb"
283 variables :base => "hour", :interval => 86400
286 link "/var/lib/replication/day/data" do
287 to "/store/planet/replication/day"
290 if node[:planet][:replication] == "enabled"
291 cron_d "users-agreed" do
295 command "/usr/local/bin/users-agreed"
296 mailto "zerebubuth@gmail.com"
299 cron_d "users-deleted" do
303 command "/usr/local/bin/users-deleted"
304 mailto "zerebubuth@gmail.com"
307 cron_d "replication-changesets" do
309 command "/usr/local/bin/replicate-changesets /etc/replication/changesets.conf"
310 mailto "zerebubuth@gmail.com"
313 service "replication-minutely.timer" do
314 action [:enable, :start]
317 cron_d "replication-minutely" do
319 command "/usr/local/bin/osmosis -q --replicate-apidb authFile=/etc/replication/auth.conf validateSchemaVersion=false --write-replication workingDirectory=/store/planet/replication/minute"
320 mailto "brett@bretth.com"
321 environment "LD_PRELOAD" => "/opt/flush/flush.so"
324 cron_d "replication-hourly" do
327 command "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/hour"
328 mailto "brett@bretth.com"
329 environment "LD_PRELOAD" => "/opt/flush/flush.so"
332 cron_d "replication-daily" do
335 command "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/day"
336 mailto "brett@bretth.com"
337 environment "LD_PRELOAD" => "/opt/flush/flush.so"
340 cron_d "users-agreed" do
344 cron_d "users-deleted" do
348 cron_d "replication-changesets" do
352 service "replication-minutely.timer" do
353 action [:stop, :disable]
356 cron_d "replication-minutely" do
360 cron_d "replication-hourly" do
364 cron_d "replication-daily" do