]> git.openstreetmap.org Git - chef.git/blob - cookbooks/nominatim/recipes/default.rb
ebcc5d7835ccf24b46659e5858c1d5a2fa40d562
[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
115 package "osmosis"
116 package "gcc"
117 package "proj-bin"
118 package "libgeos-c1"
119 package "postgresql-#{database_version}-postgis-#{postgis_version}"
120 package "postgresql-server-dev-#{database_version}"
121 package "build-essential"
122 package "libxml2-dev"
123 package "libgeos-dev"
124 package "libgeos++-dev"
125 package "libpq-dev"
126 package "libbz2-dev"
127 package "libtool"
128 package "automake"
129 package "libproj-dev"
130 package "libprotobuf-c0-dev"
131 package "protobuf-c-compiler"
132 package "python-psycopg2"
133
134 execute "php-pear-db" do
135   command "pear install DB"
136   not_if { File.exists?("/usr/share/php/DB") }
137 end
138
139 execute "compile_nominatim" do
140   action :nothing
141   command "cd #{source_directory} && ./autogen.sh && ./configure && make"
142   user "nominatim"
143 end
144
145 git source_directory do
146   action :checkout
147   repository node[:nominatim][:repository]
148   enable_submodules true
149   user "nominatim"
150   group "nominatim"
151   notifies :run, "execute[compile_nominatim]"
152 end
153
154 directory "#{source_directory}/log" do
155   owner "nominatim"
156   group "nominatim"
157   mode 0755
158 end
159
160
161 template "#{source_directory}/.git/hooks/post-merge" do
162   source "update_source.erb"
163   owner  "nominatim"
164   group  "nominatim"
165   mode   0755
166   variables :source_directory => source_directory
167 end
168
169 template "#{source_directory}/settings/local.php" do
170   source "nominatim.erb"
171   owner "nominatim"
172   group "nominatim"
173   mode 0664
174   variables :postgres_version => database_version
175 end
176
177 template "#{source_directory}/settings/ip_blocks.conf" do
178   action :create_if_missing
179   source "ipblocks.erb"
180   owner "nominatim"
181   group "nominatim"
182   mode 0664
183 end
184
185 file "#{source_directory}/settings/apache_blocks.conf" do
186   action :create_if_missing
187   owner "nominatim"
188   group "nominatim"
189   mode 0664
190 end
191
192 file "#{source_directory}/settings/ip_blocks.map" do
193   action :create_if_missing
194   owner "nominatim"
195   group "nominatim"
196   mode 0664
197 end
198
199 if node[:nominatim][:enabled]
200   cron_action = :create
201 else
202   cron_action = :delete
203 end
204
205 template "/etc/cron.d/nominatim" do
206   action cron_action
207   source "cron.erb"
208   owner "root"
209   group "root"
210   mode "0644"
211   variables :bin_directory => "#{source_directory}/utils", :mailto => email_errors
212 end
213
214
215 template "#{source_directory}/utils/nominatim-update" do
216   source "updater.erb"
217   user   "nominatim"
218   group  "nominatim"
219   mode   0755
220 end
221
222 template "/etc/init.d/nominatim-update" do
223   source "updater.init.erb"
224   user   "nominatim"
225   group  "nominatim"
226   mode   0755
227   variables :source_directory => source_directory
228 end
229
230 munin_plugin_conf "nominatim" do
231   template "munin.erb"
232 end
233
234 munin_plugin "nominatim_importlag" do
235   target "#{source_directory}/munin/nominatim_importlag"
236 end
237
238 munin_plugin "nominatim_query_speed" do
239   target "#{source_directory}/munin/nominatim_query_speed_querylog"
240 end
241
242 munin_plugin "nominatim_requests" do
243   target "#{source_directory}/munin/nominatim_requests_querylog"
244 end
245
246 munin_plugin "nominatim_throttled_ips" do
247   target "#{source_directory}/munin/nominatim_throttled_ips"
248 end
249
250 remote_file "#{source_directory}/data/wikipedia_article.sql.bin" do
251   action :create_if_missing
252   source "http://www.nominatim.org/data/wikipedia_article.sql.bin"
253   owner  "nominatim"
254   group  "nominatim"
255   mode   0644
256 end
257
258 remote_file "#{source_directory}/data/wikipedia_redirect.sql.bin" do
259   action :create_if_missing
260   source "http://www.nominatim.org/data/wikipedia_redirect.sql.bin"
261   owner  "nominatim"
262   group  "nominatim"
263   mode   0644
264 end
265
266 remote_file "#{source_directory}/data/gb_postcode_data.sql.gz" do
267   action :create_if_missing
268   source "http://www.nominatim.org/data/gb_postcode_data.sql.gz"
269   owner  "nominatim"
270   group  "nominatim"
271   mode   0644
272 end
273
274 template "/usr/local/bin/backup-nominatim" do
275   source "backup-nominatim.erb"
276   owner "root"
277   group "root"
278   mode 0755
279 end
280
281 directory File.dirname(node[:nominatim][:flatnode_file]) do
282   owner "nominatim"
283   group "nominatim"
284   mode 0755
285   recursive true
286 end
287