]> git.openstreetmap.org Git - chef.git/blob - cookbooks/planet/recipes/replication.rb
fef4e017ed51235b09ff1228b2e9a12a578649db
[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 #     http://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 remote_directory "/usr/local/bin" do
34   source "replication-bin"
35   owner "root"
36   group "root"
37   mode 0755
38   files_owner "root"
39   files_group "root"
40   files_mode 0755
41 end
42
43 remote_directory "/store/planet/replication" do
44   source "replication-cgi"
45   owner "root"
46   group "root"
47   mode 0755
48   files_owner "root"
49   files_group "root"
50   files_mode 0755
51 end
52
53 directory "/store/planet/replication/changesets" do
54   owner "planet"
55   group "planet"
56   mode 0755
57 end
58
59 directory "/store/planet/replication/day" do
60   owner "planet"
61   group "planet"
62   mode 0755
63 end
64
65 directory "/store/planet/replication/hour" do
66   owner "planet"
67   group "planet"
68   mode 0755
69 end
70
71 directory "/store/planet/replication/minute" do
72   owner "planet"
73   group "planet"
74   mode 0755
75 end
76
77 directory "/etc/replication" do
78   owner "root"
79   group "root"
80   mode 0755
81 end
82
83 template "/etc/replication/auth.conf" do
84   source "replication.auth.erb"
85   user "root"
86   group "planet"
87   mode 0640
88   variables :password => db_passwords["planetdiff"]
89 end
90
91 template "/etc/replication/changesets.conf" do
92   source "changesets.conf.erb"
93   user "root"
94   group "planet"
95   mode 0640
96   variables :password => db_passwords["planetdiff"]
97 end
98
99 template "/etc/replication/users-agreed.conf" do
100   source "users-agreed.conf.erb"
101   user "planet"
102   group "planet"
103   mode 0600
104   variables :password => db_passwords["planetdiff"]
105 end
106
107 directory "/var/lib/replication" do
108   owner "planet"
109   group "planet"
110   mode 0755
111 end
112
113 directory "/var/lib/replication/hour" do
114   owner "planet"
115   group "planet"
116   mode 0755
117 end
118
119 template "/var/lib/replication/hour/configuration.txt" do
120   source "replication.config.erb"
121   owner "planet"
122   group "planet"
123   mode 0644
124   variables :base => "minute", :interval => 3600
125 end
126
127 link "/var/lib/replication/hour/data" do
128   to "/store/planet/replication/hour"
129 end
130
131 directory "/var/lib/replication/day" do
132   owner "planet"
133   group "planet"
134   mode 0755
135 end
136
137 template "/var/lib/replication/day/configuration.txt" do
138   source "replication.config.erb"
139   owner "planet"
140   group "planet"
141   mode 0644
142   variables :base => "hour", :interval => 86400
143 end
144
145 link "/var/lib/replication/day/data" do
146   to "/store/planet/replication/day"
147 end
148
149 if node[:planet][:replication] == "enabled"
150   template "/etc/cron.d/replication" do
151     source "replication.cron.erb"
152     owner "root"
153     group "root"
154     mode 0644
155   end
156 else
157   file "/etc/cron.d/replication" do
158     action :delete
159   end
160 end
161
162 directory "/var/lib/replication/streaming" do
163   owner "planet"
164   group "planet"
165   mode 0755
166 end
167
168 directory "/var/log/replication" do
169   owner "planet"
170   group "planet"
171   mode 0755
172 end
173
174 ["streaming-replicator", "streaming-server"].each do |name|
175   template "/etc/init.d/#{name}" do
176     source "streaming.init.erb"
177     owner "root"
178     group "root"
179     mode 0755
180     variables :service => name
181   end
182
183   if node[:planet][:replication] == "enabled"
184     service name do
185       action [:enable, :start]
186       supports :restart => true, :status => true
187       subscribes :restart, "template[/etc/init.d/#{name}]"
188     end
189   else
190     service name do
191       action [:disable, :stop]
192       supports :restart => true, :status => true
193     end
194   end
195 end