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.
20 include_recipe "accounts"
21 include_recipe "osmosis"
23 db_passwords = data_bag_item("db", "passwords")
25 package "postgresql-client"
37 remote_directory "/opt/flush" do
47 execute "/opt/flush/Makefile" do
53 subscribes :run, "remote_directory[/opt/flush]"
56 remote_directory "/usr/local/bin" do
57 source "replication-bin"
66 template "/usr/local/bin/users-agreed" do
67 source "users-agreed.erb"
73 template "/usr/local/bin/users-deleted" do
74 source "users-deleted.erb"
80 remote_directory "/store/planet/users_deleted" do
81 source "users_deleted"
90 remote_directory "/store/planet/replication" do
91 source "replication-cgi"
100 directory "/store/planet/replication/changesets" do
106 directory "/store/planet/replication/day" do
112 directory "/store/planet/replication/hour" do
118 directory "/store/planet/replication/minute" do
124 directory "/etc/replication" do
130 directory "/var/run/lock/changeset-replication/" do
136 template "/etc/replication/auth.conf" do
137 source "replication.auth.erb"
141 variables :password => db_passwords["planetdiff"]
144 template "/etc/replication/changesets.conf" do
145 source "changesets.conf.erb"
149 variables :password => db_passwords["planetdiff"]
152 template "/etc/replication/users-agreed.conf" do
153 source "users-agreed.conf.erb"
157 variables :password => db_passwords["planetdiff"]
160 directory "/var/lib/replication" do
166 directory "/var/lib/replication/hour" do
172 template "/var/lib/replication/hour/configuration.txt" do
173 source "replication.config.erb"
177 variables :base => "minute", :interval => 3600
180 link "/var/lib/replication/hour/data" do
181 to "/store/planet/replication/hour"
184 directory "/var/lib/replication/day" do
190 template "/var/lib/replication/day/configuration.txt" do
191 source "replication.config.erb"
195 variables :base => "hour", :interval => 86400
198 link "/var/lib/replication/day/data" do
199 to "/store/planet/replication/day"
202 if node[:planet][:replication] == "enabled"
203 cron_d "users-agreed" do
207 command "/usr/local/bin/users-agreed"
208 mailto "zerebubuth@gmail.com"
211 cron_d "users-deleted" do
215 command "/usr/local/bin/users-deleted"
216 mailto "zerebubuth@gmail.com"
219 cron_d "replication-changesets" do
221 command "/usr/local/bin/replicate-changesets /etc/replication/changesets.conf"
222 mailto "zerebubuth@gmail.com"
225 cron_d "replication-minutely" do
227 command "/usr/local/bin/osmosis -q --replicate-apidb authFile=/etc/replication/auth.conf validateSchemaVersion=false --write-replication workingDirectory=/store/planet/replication/minute"
228 mailto "brett@bretth.com"
229 environment "LD_PRELOAD" => "/opt/flush/flush.so"
232 cron_d "replication-hourly" do
235 command "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/hour"
236 mailto "brett@bretth.com"
237 environment "LD_PRELOAD" => "/opt/flush/flush.so"
240 cron_d "replication-daily" do
243 command "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/day"
244 mailto "brett@bretth.com"
245 environment "LD_PRELOAD" => "/opt/flush/flush.so"
248 cron_d "users-agreed" do
252 cron_d "users-deleted" do
256 cron_d "replication-changesets" do
260 cron_d "replication-minutely" do
264 cron_d "replication-hourly" do
268 cron_d "replication-daily" do
273 # directory "/var/lib/replication/streaming" do
279 # directory "/var/log/replication" do
285 # ["streaming-replicator", "streaming-server"].each do |name|
286 # template "/etc/init.d/#{name}" do
287 # source "streaming.init.erb"
291 # variables :service => name
294 # if node[:planet][:replication] == "enabled"
296 # action [:enable, :start]
297 # supports :restart => true, :status => true
298 # subscribes :restart, "template[/etc/init.d/#{name}]"
302 # action [:disable, :stop]
303 # supports :restart => true, :status => true