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 systemd_tmpfile "/run/replication" do
153 directory "/etc/replication" do
159 directory "/var/run/lock/changeset-replication/" do
165 template "/etc/replication/auth.conf" do
166 source "replication.auth.erb"
170 variables :password => db_passwords["planetdiff"]
175 "host" => node[:web][:database_host],
176 "dbname" => "openstreetmap",
177 "user" => "planetdiff",
178 "password" => db_passwords["planetdiff"],
179 "replication_slot" => "osmdbt"
181 "log_dir" => "/var/lib/replication/minute",
182 "changes_dir" => "/store/planet/replication/test/minute",
184 "run_dir" => "/run/replication"
187 file "/etc/replication/osmdbt-config.yaml" do
191 content YAML.dump(osmdbt_config)
194 systemd_service "replication-minutely" do
195 description "Minutely replication"
197 working_directory "/etc/replication"
198 exec_start "/usr/local/bin/replicate-minute"
201 protect_system "full"
203 restrict_address_families %w[AF_INET AF_INET6]
204 no_new_privileges true
207 template "/etc/replication/changesets.conf" do
208 source "changesets.conf.erb"
212 variables :password => db_passwords["planetdiff"]
215 template "/etc/replication/users-agreed.conf" do
216 source "users-agreed.conf.erb"
220 variables :password => db_passwords["planetdiff"]
223 directory "/var/lib/replication" do
229 directory "/var/lib/replication/minute" do
235 directory "/var/lib/replication/hour" do
241 template "/var/lib/replication/hour/configuration.txt" do
242 source "replication.config.erb"
246 variables :base => "minute", :interval => 3600
249 link "/var/lib/replication/hour/data" do
250 to "/store/planet/replication/hour"
253 directory "/var/lib/replication/day" do
259 template "/var/lib/replication/day/configuration.txt" do
260 source "replication.config.erb"
264 variables :base => "hour", :interval => 86400
267 link "/var/lib/replication/day/data" do
268 to "/store/planet/replication/day"
271 if node[:planet][:replication] == "enabled"
272 cron_d "users-agreed" do
276 command "/usr/local/bin/users-agreed"
277 mailto "zerebubuth@gmail.com"
280 cron_d "users-deleted" do
284 command "/usr/local/bin/users-deleted"
285 mailto "zerebubuth@gmail.com"
288 cron_d "replication-changesets" do
290 command "/usr/local/bin/replicate-changesets /etc/replication/changesets.conf"
291 mailto "zerebubuth@gmail.com"
294 systemd_timer "replication-minutely" do
295 description "Minutely replication"
297 on_unit_active_sec 60
300 cron_d "replication-minutely" do
302 command "/usr/local/bin/osmosis -q --replicate-apidb authFile=/etc/replication/auth.conf validateSchemaVersion=false --write-replication workingDirectory=/store/planet/replication/minute"
303 mailto "brett@bretth.com"
304 environment "LD_PRELOAD" => "/opt/flush/flush.so"
307 cron_d "replication-hourly" do
310 command "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/hour"
311 mailto "brett@bretth.com"
312 environment "LD_PRELOAD" => "/opt/flush/flush.so"
315 cron_d "replication-daily" do
318 command "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/day"
319 mailto "brett@bretth.com"
320 environment "LD_PRELOAD" => "/opt/flush/flush.so"
323 cron_d "users-agreed" do
327 cron_d "users-deleted" do
331 cron_d "replication-changesets" do
335 cron_d "replication-minutely" do
339 cron_d "replication-hourly" do
343 cron_d "replication-daily" do