2 # Cookbook Name:: nominatim
5 # Copyright 2015, OpenStreetMap Foundation
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
11 # http://www.apache.org/licenses/LICENSE-2.0
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.
20 include_recipe "apache::ssl"
21 include_recipe "postgresql"
31 apache_module "rewrite"
33 apache_module "proxy_fcgi"
34 apache_module "proxy_http"
35 apache_module "headers"
37 home_directory = data_bag_item("accounts", "nominatim")["home"]
38 source_directory = "#{home_directory}/nominatim"
39 email_errors = data_bag_item("accounts", "lonvia")["email"]
41 database_cluster = node[:nominatim][:database][:cluster]
42 database_version = database_cluster.sub(%r{/.*}, "")
43 database_name = node[:nominatim][:database][:dbname]
45 postgis_version = node[:nominatim][:database][:postgis]
48 provider Chef::Provider::Service::Upstart
49 action [:enable, :start]
50 supports :status => true, :restart => true, :reload => true
53 node[:nominatim][:fpm_pools].each do |name, data|
54 template "/etc/php5/fpm/pool.d/#{name}.conf" do
59 variables data.merge(:name => name, :port => data[:port])
60 notifies :reload, "service[php5-fpm]"
64 postgresql_munin "nominatim" do
65 cluster database_cluster
66 database database_name
69 directory node[:nominatim][:logdir] do
76 file "#{node[:nominatim][:logdir]}/query.log" do
77 action :create_if_missing
83 file "#{node[:nominatim][:logdir]}/update.log" do
84 action :create_if_missing
90 directory "#{home_directory}/status" do
96 template "/etc/logrotate.d/nominatim" do
97 source "logrotate.nominatim.erb"
103 template "/etc/logrotate.d/apache2" do
104 source "logrotate.apache.erb"
114 package "postgresql-#{database_version}-postgis-#{postgis_version}"
115 package "postgresql-server-dev-#{database_version}"
116 package "build-essential"
117 package "libxml2-dev"
118 package "libexpat-dev"
119 package "libgeos-dev"
120 package "libgeos++-dev"
125 package "libproj-dev"
126 package "libprotobuf-c0-dev"
127 package "protobuf-c-compiler"
128 package "python-psycopg2"
129 package "libboost-dev"
130 package "libboost-system-dev"
131 package "libboost-filesystem-dev"
132 package "libboost-thread-dev"
134 execute "compile_nominatim" do
136 command "cd #{source_directory} && ./autogen.sh && ./configure && make"
140 template "#{source_directory}/.git/hooks/post-merge" do
141 source "update_source.erb"
145 variables :source_directory => source_directory
148 template "#{source_directory}/settings/local.php" do
149 source "nominatim.erb"
153 variables :postgres_version => database_version
156 template "#{source_directory}/settings/ip_blocks.conf" do
157 action :create_if_missing
158 source "ipblocks.erb"
164 file "#{source_directory}/settings/apache_blocks.conf" do
165 action :create_if_missing
171 file "#{source_directory}/settings/ip_blocks.map" do
172 action :create_if_missing
178 cron_action = if node[:nominatim][:enabled]
184 template "/etc/cron.d/nominatim" do
190 variables :bin_directory => "#{source_directory}/utils", :mailto => email_errors
193 template "#{source_directory}/utils/nominatim-update" do
200 template "/etc/init.d/nominatim-update" do
201 source "updater.init.erb"
205 variables :source_directory => source_directory
208 munin_plugin_conf "nominatim" do
212 munin_plugin "nominatim_importlag" do
213 target "#{source_directory}/munin/nominatim_importlag"
216 munin_plugin "nominatim_query_speed" do
217 target "#{source_directory}/munin/nominatim_query_speed_querylog"
220 munin_plugin "nominatim_requests" do
221 target "#{source_directory}/munin/nominatim_requests_querylog"
224 munin_plugin "nominatim_throttled_ips" do
225 target "#{source_directory}/munin/nominatim_throttled_ips"
229 "wikipedia_article.sql.bin",
230 "wikipedia_redirect.sql.bin",
231 "gb_postcode_data.sql.gz"
234 external_data.each do |fname|
235 remote_file "#{source_directory}/data/#{fname}" do
236 action :create_if_missing
237 source "http://www.nominatim.org/data/#{fname}"
244 additional_scripts = %w(backup-nominatim vacuum-db-nominatim)
246 additional_scripts.each do |fname|
247 template "/usr/local/bin/#{fname}" do
248 source "#{fname}.erb"
255 directory File.dirname(node[:nominatim][:flatnode_file]) do
262 apache_site "nominatim.openstreetmap.org" do
263 template "apache.erb"
264 directory source_directory
265 variables :pools => node[:nominatim][:fpm_pools]
268 apache_site "default" do
272 fail2ban_filter "nominatim" do
273 failregex '^<HOST> - - \[[^]]+\] "[^"]+" 429 '
276 fail2ban_jail "nominatim" do
278 logpath "/var/log/apache2/nominatim.openstreetmap.org-access.log"