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"
30 apache_module "rewrite"
32 apache_module "proxy_fcgi"
33 apache_module "proxy_http"
34 apache_module "headers"
36 home_directory = data_bag_item("accounts", "nominatim")["home"]
37 source_directory = "#{home_directory}/nominatim"
38 email_errors = data_bag_item("accounts", "lonvia")["email"]
40 database_cluster = node[:nominatim][:database][:cluster]
41 database_version = database_cluster.sub(%r{/.*}, "")
42 database_name = node[:nominatim][:database][:dbname]
44 postgis_version = node[:nominatim][:database][:postgis]
46 service "php7.0-fpm" do
47 action [:enable, :start]
50 node[:nominatim][:fpm_pools].each do |name, data|
51 template "/etc/php/7.0/fpm/pool.d/#{name}.conf" do
56 variables data.merge(:name => name, :port => data[:port])
57 notifies :reload, "service[php7.0-fpm]"
61 postgresql_munin "nominatim" do
62 cluster database_cluster
63 database database_name
66 directory node[:nominatim][:logdir] do
73 file "#{node[:nominatim][:logdir]}/query.log" do
74 action :create_if_missing
80 file "#{node[:nominatim][:logdir]}/update.log" do
81 action :create_if_missing
87 directory "#{home_directory}/status" do
93 template "/etc/logrotate.d/nominatim" do
94 source "logrotate.nominatim.erb"
100 template "/etc/logrotate.d/apache2" do
101 source "logrotate.apache.erb"
110 package "libgeos-c1v5"
111 package "postgresql-#{database_version}-postgis-#{postgis_version}"
112 package "postgresql-server-dev-#{database_version}"
113 package "build-essential"
114 package "libxml2-dev"
115 package "libexpat-dev"
116 package "libgeos-dev"
117 package "libgeos++-dev"
122 package "libproj-dev"
123 package "libprotobuf-c0-dev"
124 package "protobuf-c-compiler"
125 package "python-psycopg2"
126 package "libboost-dev"
127 package "libboost-system-dev"
128 package "libboost-filesystem-dev"
129 package "libboost-thread-dev"
131 execute "compile_nominatim" do
133 command "cd #{source_directory} && ./autogen.sh && ./configure && make"
137 template "#{source_directory}/.git/hooks/post-merge" do
138 source "update_source.erb"
142 variables :source_directory => source_directory
145 template "#{source_directory}/settings/local.php" do
146 source "nominatim.erb"
150 variables :postgres_version => database_version
153 template "#{source_directory}/settings/ip_blocks.conf" do
154 action :create_if_missing
155 source "ipblocks.erb"
161 file "#{source_directory}/settings/apache_blocks.conf" do
162 action :create_if_missing
168 file "#{source_directory}/settings/ip_blocks.map" do
169 action :create_if_missing
175 cron_action = if node[:nominatim][:enabled]
181 template "/etc/cron.d/nominatim" do
187 variables :bin_directory => "#{source_directory}/utils", :mailto => email_errors
190 template "#{source_directory}/utils/nominatim-update" do
195 variables :bindir => source_directory,
196 :srcdir => source_directory,
197 :logfile => "#{node[:nominatim][:logdir]}/update.log",
198 :branch => node[:nominatim][:revision],
199 :update_stop_file => "#{home_directory}/status/updates_disabled"
202 template "/etc/init.d/nominatim-update" do
203 source "updater.init.erb"
207 variables :source_directory => source_directory
210 munin_plugin_conf "nominatim" do
212 variables :db => node[:nominatim][:database][:dbname],
213 :querylog => "#{node[:nominatim][:logdir]}/query.log"
216 munin_plugin "nominatim_importlag" do
217 target "#{source_directory}/munin/nominatim_importlag"
220 munin_plugin "nominatim_query_speed" do
221 target "#{source_directory}/munin/nominatim_query_speed_querylog"
224 munin_plugin "nominatim_requests" do
225 target "#{source_directory}/munin/nominatim_requests_querylog"
228 munin_plugin "nominatim_throttled_ips" do
229 target "#{source_directory}/munin/nominatim_throttled_ips"
233 "wikipedia_article.sql.bin",
234 "wikipedia_redirect.sql.bin",
235 "gb_postcode_data.sql.gz"
238 external_data.each do |fname|
239 remote_file "#{source_directory}/data/#{fname}" do
240 action :create_if_missing
241 source "http://www.nominatim.org/data/#{fname}"
248 additional_scripts = %w(backup-nominatim vacuum-db-nominatim)
250 additional_scripts.each do |fname|
251 template "/usr/local/bin/#{fname}" do
252 source "#{fname}.erb"
256 variables :db => node[:nominatim][:database][:dbname]
260 directory File.dirname(node[:nominatim][:flatnode_file]) do
267 apache_site "nominatim.openstreetmap.org" do
268 template "apache.erb"
269 directory source_directory
270 variables :pools => node[:nominatim][:fpm_pools]
273 apache_site "default" do
277 fail2ban_filter "nominatim" do
278 failregex '^<HOST> - - \[[^]]+\] "[^"]+" 429 '
281 fail2ban_jail "nominatim" do
283 logpath "/var/log/apache2/nominatim.openstreetmap.org-access.log"