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