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
198 variables :bindir => source_directory,
199 :logfile => "#{node[:nominatim][:logdir]}/update.log",
200 :branch => node[:nominatim][:revision],
201 :update_stop_file => "#{home_directory}/status/updates_disabled"
204 template "/etc/init.d/nominatim-update" do
205 source "updater.init.erb"
209 variables :source_directory => source_directory
212 munin_plugin_conf "nominatim" do
214 variables :db => node[:nominatim][:database][:dbname],
215 :querylog => "#{node[:nominatim][:logdir]}/query.log"
218 munin_plugin "nominatim_importlag" do
219 target "#{source_directory}/munin/nominatim_importlag"
222 munin_plugin "nominatim_query_speed" do
223 target "#{source_directory}/munin/nominatim_query_speed_querylog"
226 munin_plugin "nominatim_requests" do
227 target "#{source_directory}/munin/nominatim_requests_querylog"
230 munin_plugin "nominatim_throttled_ips" do
231 target "#{source_directory}/munin/nominatim_throttled_ips"
235 "wikipedia_article.sql.bin",
236 "wikipedia_redirect.sql.bin",
237 "gb_postcode_data.sql.gz"
240 external_data.each do |fname|
241 remote_file "#{source_directory}/data/#{fname}" do
242 action :create_if_missing
243 source "http://www.nominatim.org/data/#{fname}"
250 additional_scripts = %w(backup-nominatim vacuum-db-nominatim)
252 additional_scripts.each do |fname|
253 template "/usr/local/bin/#{fname}" do
254 source "#{fname}.erb"
258 variables :db => node[:nominatim][:database][:dbname]
262 directory File.dirname(node[:nominatim][:flatnode_file]) do
269 apache_site "nominatim.openstreetmap.org" do
270 template "apache.erb"
271 directory source_directory
272 variables :pools => node[:nominatim][:fpm_pools]
275 apache_site "default" do
279 fail2ban_filter "nominatim" do
280 failregex '^<HOST> - - \[[^]]+\] "[^"]+" 429 '
283 fail2ban_jail "nominatim" do
285 logpath "/var/log/apache2/nominatim.openstreetmap.org-access.log"