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 :logfile => "#{node[:nominatim][:logdir]}/update.log",
199 :branch => node[:nominatim][:revision],
200 :update_stop_file => "#{basedir}/status/updates_disabled"
203 template "/etc/init.d/nominatim-update" do
204 source "updater.init.erb"
208 variables :source_directory => source_directory
211 munin_plugin_conf "nominatim" do
213 variables :db => node[:nominatim][:database][:dbname],
214 :querylog => "#{node[:nominatim][:logdir]}/query.log"
217 munin_plugin "nominatim_importlag" do
218 target "#{source_directory}/munin/nominatim_importlag"
221 munin_plugin "nominatim_query_speed" do
222 target "#{source_directory}/munin/nominatim_query_speed_querylog"
225 munin_plugin "nominatim_requests" do
226 target "#{source_directory}/munin/nominatim_requests_querylog"
229 munin_plugin "nominatim_throttled_ips" do
230 target "#{source_directory}/munin/nominatim_throttled_ips"
234 "wikipedia_article.sql.bin",
235 "wikipedia_redirect.sql.bin",
236 "gb_postcode_data.sql.gz"
239 external_data.each do |fname|
240 remote_file "#{source_directory}/data/#{fname}" do
241 action :create_if_missing
242 source "http://www.nominatim.org/data/#{fname}"
249 additional_scripts = %w(backup-nominatim vacuum-db-nominatim)
251 additional_scripts.each do |fname|
252 template "/usr/local/bin/#{fname}" do
253 source "#{fname}.erb"
257 variables :db => node[:nominatim][:database][:dbname]
261 directory File.dirname(node[:nominatim][:flatnode_file]) do
268 apache_site "nominatim.openstreetmap.org" do
269 template "apache.erb"
270 directory source_directory
271 variables :pools => node[:nominatim][:fpm_pools]
274 apache_site "default" do
278 fail2ban_filter "nominatim" do
279 failregex '^<HOST> - - \[[^]]+\] "[^"]+" 429 '
282 fail2ban_jail "nominatim" do
284 logpath "/var/log/apache2/nominatim.openstreetmap.org-access.log"