]> git.openstreetmap.org Git - chef.git/blob - cookbooks/nominatim/recipes/default.rb
6134c1d7674cc27d10d9fe744d731838ab9bea54
[chef.git] / cookbooks / nominatim / recipes / default.rb
1 #
2 # Cookbook Name:: nominatim
3 # Recipe:: default
4 #
5 # Copyright 2012, 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 "apache::ssl"
21 include_recipe "postgresql"
22 include_recipe "git"
23
24 package "php5"
25 package "php5-cli"
26 package "php5-pgsql"
27 package "php5-fpm"
28 package "php-pear"
29 package "php-apc"
30
31 apache_module "rewrite"
32 apache_module "proxy"
33 apache_module "proxy_fcgi"
34
35 home_directory = data_bag_item("accounts", "nominatim")["home"]
36 source_directory = "#{home_directory}/nominatim"
37 email_errors = data_bag_item("accounts", "lonvia")["email"]
38
39 database_cluster = node[:nominatim][:database][:cluster]
40 database_version = database_cluster.sub(/\/.*/, "")
41 database_name = node[:nominatim][:database][:dbname]
42
43 postgis_version = node[:nominatim][:database][:postgis]
44
45 service "php5-fpm" do
46   provider Chef::Provider::Service::Upstart
47   action [:enable, :start]
48   supports :status => true, :restart => true, :reload => true
49 end
50
51 apache_site "nominatim.openstreetmap.org" do
52   template "apache.erb"
53   directory source_directory
54   variables :pools => node[:nominatim][:fpm_pools]
55 end
56
57 apache_site "default" do
58   action [:disable]
59 end
60
61 node[:nominatim][:fpm_pools].each do |name, data|
62   template "/etc/php5/fpm/pool.d/#{name}.conf" do
63     source "fpm.conf.erb"
64     owner "root"
65     group "root"
66     mode 0644
67     variables data.merge(:name => name, :port => data[:port])
68     notifies :reload, "service[php5-fpm]"
69   end
70 end
71
72 postgresql_user "tomh" do
73   cluster database_cluster
74   superuser true
75 end
76
77 postgresql_user "lonvia" do
78   cluster database_cluster
79   superuser true
80 end
81
82 postgresql_user "twain" do
83   cluster database_cluster
84   superuser true
85 end
86
87 postgresql_user "nominatim" do
88   cluster database_cluster
89   superuser true
90 end
91
92 postgresql_user "www-data" do
93   cluster database_cluster
94 end
95
96 postgresql_munin "nominatim" do
97   cluster database_cluster
98   database database_name
99 end
100
101 directory "/var/log/nominatim" do
102   owner "nominatim"
103   group "nominatim"
104   mode 0755
105 end
106
107 template "/etc/logrotate.d/nominatim" do
108   source "logrotate.nominatim.erb"
109   owner "root"
110   group "root"
111   mode 0644
112 end
113
114 package "osmosis"
115 package "gcc"
116 package "proj-bin"
117 package "libgeos-c1"
118 package "postgresql-#{database_version}-postgis-#{postgis_version}"
119 package "postgresql-server-dev-#{database_version}"
120 package "build-essential"
121 package "libxml2-dev"
122 package "libgeos-dev"
123 package "libgeos++-dev"
124 package "libpq-dev"
125 package "libbz2-dev"
126 package "libtool"
127 package "automake"
128 package "libproj-dev"
129 package "libprotobuf-c0-dev"
130 package "protobuf-c-compiler"
131 package "python-psycopg2"
132 package "libboost-dev"
133 package "libboost-system-dev"
134 package "libboost-filesystem-dev"
135 package "libboost-thread-dev"
136
137 execute "php-pear-db" do
138   command "pear install DB"
139   not_if { File.exist?("/usr/share/php/DB") }
140 end
141
142 execute "compile_nominatim" do
143   action :nothing
144   command "cd #{source_directory} && ./autogen.sh && ./configure && make"
145   user "nominatim"
146 end
147
148 git source_directory do
149   action :checkout
150   repository node[:nominatim][:repository]
151   enable_submodules true
152   user "nominatim"
153   group "nominatim"
154   notifies :run, "execute[compile_nominatim]"
155 end
156
157 directory "#{source_directory}/log" do
158   owner "nominatim"
159   group "nominatim"
160   mode 0755
161 end
162
163 template "#{source_directory}/.git/hooks/post-merge" do
164   source "update_source.erb"
165   owner "nominatim"
166   group "nominatim"
167   mode 0755
168   variables :source_directory => source_directory
169 end
170
171 template "#{source_directory}/settings/local.php" do
172   source "nominatim.erb"
173   owner "nominatim"
174   group "nominatim"
175   mode 0664
176   variables :postgres_version => database_version
177 end
178
179 template "#{source_directory}/settings/ip_blocks.conf" do
180   action :create_if_missing
181   source "ipblocks.erb"
182   owner "nominatim"
183   group "nominatim"
184   mode 0664
185 end
186
187 file "#{source_directory}/settings/apache_blocks.conf" do
188   action :create_if_missing
189   owner "nominatim"
190   group "nominatim"
191   mode 0664
192 end
193
194 file "#{source_directory}/settings/ip_blocks.map" do
195   action :create_if_missing
196   owner "nominatim"
197   group "nominatim"
198   mode 0664
199 end
200
201 if node[:nominatim][:enabled]
202   cron_action = :create
203 else
204   cron_action = :delete
205 end
206
207 template "/etc/cron.d/nominatim" do
208   action cron_action
209   source "cron.erb"
210   owner "root"
211   group "root"
212   mode "0644"
213   variables :bin_directory => "#{source_directory}/utils", :mailto => email_errors
214 end
215
216 template "#{source_directory}/utils/nominatim-update" do
217   source "updater.erb"
218   user "nominatim"
219   group "nominatim"
220   mode 0755
221 end
222
223 template "/etc/init.d/nominatim-update" do
224   source "updater.init.erb"
225   user "nominatim"
226   group "nominatim"
227   mode 0755
228   variables :source_directory => source_directory
229 end
230
231 munin_plugin_conf "nominatim" do
232   template "munin.erb"
233 end
234
235 munin_plugin "nominatim_importlag" do
236   target "#{source_directory}/munin/nominatim_importlag"
237 end
238
239 munin_plugin "nominatim_query_speed" do
240   target "#{source_directory}/munin/nominatim_query_speed_querylog"
241 end
242
243 munin_plugin "nominatim_requests" do
244   target "#{source_directory}/munin/nominatim_requests_querylog"
245 end
246
247 munin_plugin "nominatim_throttled_ips" do
248   target "#{source_directory}/munin/nominatim_throttled_ips"
249 end
250
251 remote_file "#{source_directory}/data/wikipedia_article.sql.bin" do
252   action :create_if_missing
253   source "http://www.nominatim.org/data/wikipedia_article.sql.bin"
254   owner "nominatim"
255   group "nominatim"
256   mode 0644
257 end
258
259 remote_file "#{source_directory}/data/wikipedia_redirect.sql.bin" do
260   action :create_if_missing
261   source "http://www.nominatim.org/data/wikipedia_redirect.sql.bin"
262   owner "nominatim"
263   group "nominatim"
264   mode 0644
265 end
266
267 remote_file "#{source_directory}/data/gb_postcode_data.sql.gz" do
268   action :create_if_missing
269   source "http://www.nominatim.org/data/gb_postcode_data.sql.gz"
270   owner "nominatim"
271   group "nominatim"
272   mode 0644
273 end
274
275 template "/usr/local/bin/backup-nominatim" do
276   source "backup-nominatim.erb"
277   owner "root"
278   group "root"
279   mode 0755
280 end
281
282 directory File.dirname(node[:nominatim][:flatnode_file]) do
283   owner "nominatim"
284   group "nominatim"
285   mode 0755
286   recursive true
287 end