]> git.openstreetmap.org Git - chef.git/blob - cookbooks/planet/recipes/replication.rb
Merge remote-tracking branch 'github/pull/185'
[chef.git] / cookbooks / planet / recipes / replication.rb
1 #
2 # Cookbook Name:: planet
3 # Recipe:: dump
4 #
5 # Copyright 2013, OpenStreetMap Foundation
6 #
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
10 #
11 #     https://www.apache.org/licenses/LICENSE-2.0
12 #
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.
18 #
19
20 include_recipe "osmosis"
21
22 db_passwords = data_bag_item("db", "passwords")
23
24 package "postgresql-client"
25
26 package "ruby"
27 package "ruby-dev"
28 package "ruby-libxml"
29
30 package "libpq-dev"
31 gem_package "pg"
32
33 package "make"
34 package "gcc"
35
36 remote_directory "/opt/flush" do
37   source "flush"
38   owner "root"
39   group "root"
40   mode 0o755
41   files_owner "root"
42   files_group "root"
43   files_mode 0o755
44 end
45
46 execute "/opt/flush/Makefile" do
47   action :nothing
48   command "make"
49   cwd "/opt/flush"
50   user "root"
51   group "root"
52   subscribes :run, "remote_directory[/opt/flush]"
53 end
54
55 remote_directory "/usr/local/bin" do
56   source "replication-bin"
57   owner "root"
58   group "root"
59   mode 0o755
60   files_owner "root"
61   files_group "root"
62   files_mode 0o755
63 end
64
65 template "/usr/local/bin/users-agreed" do
66   source "users-agreed.erb"
67   owner "root"
68   group "root"
69   mode 0o755
70 end
71
72 template "/usr/local/bin/users-deleted" do
73   source "users-deleted.erb"
74   owner "root"
75   group "root"
76   mode 0o755
77 end
78
79 remote_directory "/store/planet/replication" do
80   source "replication-cgi"
81   owner "root"
82   group "root"
83   mode 0o755
84   files_owner "root"
85   files_group "root"
86   files_mode 0o755
87 end
88
89 directory "/store/planet/replication/changesets" do
90   owner "planet"
91   group "planet"
92   mode 0o755
93 end
94
95 directory "/store/planet/replication/day" do
96   owner "planet"
97   group "planet"
98   mode 0o755
99 end
100
101 directory "/store/planet/replication/hour" do
102   owner "planet"
103   group "planet"
104   mode 0o755
105 end
106
107 directory "/store/planet/replication/minute" do
108   owner "planet"
109   group "planet"
110   mode 0o755
111 end
112
113 directory "/etc/replication" do
114   owner "root"
115   group "root"
116   mode 0o755
117 end
118
119 template "/etc/replication/auth.conf" do
120   source "replication.auth.erb"
121   user "root"
122   group "planet"
123   mode 0o640
124   variables :password => db_passwords["planetdiff"]
125 end
126
127 template "/etc/replication/changesets.conf" do
128   source "changesets.conf.erb"
129   user "root"
130   group "planet"
131   mode 0o640
132   variables :password => db_passwords["planetdiff"]
133 end
134
135 template "/etc/replication/users-agreed.conf" do
136   source "users-agreed.conf.erb"
137   user "planet"
138   group "planet"
139   mode 0o600
140   variables :password => db_passwords["planetdiff"]
141 end
142
143 directory "/var/lib/replication" do
144   owner "planet"
145   group "planet"
146   mode 0o755
147 end
148
149 directory "/var/lib/replication/hour" do
150   owner "planet"
151   group "planet"
152   mode 0o755
153 end
154
155 template "/var/lib/replication/hour/configuration.txt" do
156   source "replication.config.erb"
157   owner "planet"
158   group "planet"
159   mode 0o644
160   variables :base => "minute", :interval => 3600
161 end
162
163 link "/var/lib/replication/hour/data" do
164   to "/store/planet/replication/hour"
165 end
166
167 directory "/var/lib/replication/day" do
168   owner "planet"
169   group "planet"
170   mode 0o755
171 end
172
173 template "/var/lib/replication/day/configuration.txt" do
174   source "replication.config.erb"
175   owner "planet"
176   group "planet"
177   mode 0o644
178   variables :base => "hour", :interval => 86400
179 end
180
181 link "/var/lib/replication/day/data" do
182   to "/store/planet/replication/day"
183 end
184
185 if node[:planet][:replication] == "enabled"
186   template "/etc/cron.d/replication" do
187     source "replication.cron.erb"
188     owner "root"
189     group "root"
190     mode 0o644
191   end
192 else
193   file "/etc/cron.d/replication" do
194     action :delete
195   end
196 end
197
198 # directory "/var/lib/replication/streaming" do
199 #   owner "planet"
200 #   group "planet"
201 #   mode 0o755
202 # end
203 #
204 # directory "/var/log/replication" do
205 #   owner "planet"
206 #   group "planet"
207 #   mode 0o755
208 # end
209 #
210 # ["streaming-replicator", "streaming-server"].each do |name|
211 #   template "/etc/init.d/#{name}" do
212 #     source "streaming.init.erb"
213 #     owner "root"
214 #     group "root"
215 #     mode 0o755
216 #     variables :service => name
217 #   end
218 #
219 #   if node[:planet][:replication] == "enabled"
220 #     service name do
221 #       action [:enable, :start]
222 #       supports :restart => true, :status => true
223 #       subscribes :restart, "template[/etc/init.d/#{name}]"
224 #     end
225 #   else
226 #     service name do
227 #       action [:disable, :stop]
228 #       supports :restart => true, :status => true
229 #     end
230 #   end
231 # end