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 template "/etc/replication/changesets.conf" do
220 source "changesets.conf.erb"
224 variables :password => db_passwords["planetdiff"]
227 template "/etc/replication/users-agreed.conf" do
228 source "users-agreed.conf.erb"
232 variables :password => db_passwords["planetdiff"]
235 directory "/var/lib/replication" do
241 directory "/var/lib/replication/minute" do
247 directory "/var/lib/replication/hour" do
253 template "/var/lib/replication/hour/configuration.txt" do
254 source "replication.config.erb"
258 variables :base => "minute", :interval => 3600
261 link "/var/lib/replication/hour/data" do
262 to "/store/planet/replication/hour"
265 directory "/var/lib/replication/day" do
271 template "/var/lib/replication/day/configuration.txt" do
272 source "replication.config.erb"
276 variables :base => "hour", :interval => 86400
279 link "/var/lib/replication/day/data" do
280 to "/store/planet/replication/day"
283 if node[:planet][:replication] == "enabled"
284 cron_d "users-agreed" do
288 command "/usr/local/bin/users-agreed"
289 mailto "zerebubuth@gmail.com"
292 cron_d "users-deleted" do
296 command "/usr/local/bin/users-deleted"
297 mailto "zerebubuth@gmail.com"
300 cron_d "replication-changesets" do
302 command "/usr/local/bin/replicate-changesets /etc/replication/changesets.conf"
303 mailto "zerebubuth@gmail.com"
306 systemd_timer "replication-minutely" do
307 description "Minutely replication"
309 on_unit_active_sec 60
312 cron_d "replication-minutely" do
314 command "/usr/local/bin/osmosis -q --replicate-apidb authFile=/etc/replication/auth.conf validateSchemaVersion=false --write-replication workingDirectory=/store/planet/replication/minute"
315 mailto "brett@bretth.com"
316 environment "LD_PRELOAD" => "/opt/flush/flush.so"
319 cron_d "replication-hourly" do
322 command "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/hour"
323 mailto "brett@bretth.com"
324 environment "LD_PRELOAD" => "/opt/flush/flush.so"
327 cron_d "replication-daily" do
330 command "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/day"
331 mailto "brett@bretth.com"
332 environment "LD_PRELOAD" => "/opt/flush/flush.so"
335 cron_d "users-agreed" do
339 cron_d "users-deleted" do
343 cron_d "replication-changesets" do
347 cron_d "replication-minutely" do
351 cron_d "replication-hourly" do
355 cron_d "replication-daily" do