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"
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]
47 provider Chef::Provider::Service::Upstart
48 action [:enable, :start]
49 supports :status => true, :restart => true, :reload => true
52 node[:nominatim][:fpm_pools].each do |name, data|
53 template "/etc/php5/fpm/pool.d/#{name}.conf" do
58 variables data.merge(:name => name, :port => data[:port])
59 notifies :reload, "service[php5-fpm]"
63 postgresql_munin "nominatim" do
64 cluster database_cluster
65 database database_name
68 directory node[:nominatim][:logdir] do
75 file "#{node[:nominatim][:logdir]}/query.log" do
76 action :create_if_missing
82 file "#{node[:nominatim][:logdir]}/update.log" do
83 action :create_if_missing
89 directory "#{home_directory}/status" do
95 template "/etc/logrotate.d/nominatim" do
96 source "logrotate.nominatim.erb"
102 template "/etc/logrotate.d/apache2" do
103 source "logrotate.apache.erb"
113 package "postgresql-#{database_version}-postgis-#{postgis_version}"
114 package "postgresql-server-dev-#{database_version}"
115 package "build-essential"
116 package "libxml2-dev"
117 package "libexpat-dev"
118 package "libgeos-dev"
119 package "libgeos++-dev"
124 package "libproj-dev"
125 package "libprotobuf-c0-dev"
126 package "protobuf-c-compiler"
127 package "python-psycopg2"
128 package "libboost-dev"
129 package "libboost-system-dev"
130 package "libboost-filesystem-dev"
131 package "libboost-thread-dev"
133 execute "compile_nominatim" do
135 command "cd #{source_directory} && ./autogen.sh && ./configure && make"
139 template "#{source_directory}/.git/hooks/post-merge" do
140 source "update_source.erb"
144 variables :source_directory => source_directory
147 template "#{source_directory}/settings/local.php" do
148 source "nominatim.erb"
152 variables :postgres_version => database_version
155 template "#{source_directory}/settings/ip_blocks.conf" do
156 action :create_if_missing
157 source "ipblocks.erb"
163 file "#{source_directory}/settings/apache_blocks.conf" do
164 action :create_if_missing
170 file "#{source_directory}/settings/ip_blocks.map" do
171 action :create_if_missing
177 cron_action = if node[:nominatim][:enabled]
183 template "/etc/cron.d/nominatim" do
189 variables :bin_directory => "#{source_directory}/utils", :mailto => email_errors
192 template "#{source_directory}/utils/nominatim-update" do
199 template "/etc/init.d/nominatim-update" do
200 source "updater.init.erb"
204 variables :source_directory => source_directory
207 munin_plugin_conf "nominatim" do
211 munin_plugin "nominatim_importlag" do
212 target "#{source_directory}/munin/nominatim_importlag"
215 munin_plugin "nominatim_query_speed" do
216 target "#{source_directory}/munin/nominatim_query_speed_querylog"
219 munin_plugin "nominatim_requests" do
220 target "#{source_directory}/munin/nominatim_requests_querylog"
223 munin_plugin "nominatim_throttled_ips" do
224 target "#{source_directory}/munin/nominatim_throttled_ips"
228 "wikipedia_article.sql.bin",
229 "wikipedia_redirect.sql.bin",
230 "gb_postcode_data.sql.gz"
233 external_data.each do |fname|
234 remote_file "#{source_directory}/data/#{fname}" do
235 action :create_if_missing
236 source "http://www.nominatim.org/data/#{fname}"
243 additional_scripts = %w(backup-nominatim vacuum-db-nominatim)
245 additional_scripts.each do |fname|
246 template "/usr/local/bin/#{fname}" do
247 source "#{fname}.erb"
254 directory File.dirname(node[:nominatim][:flatnode_file]) do
261 apache_site "nominatim.openstreetmap.org" do
262 template "apache.erb"
263 directory source_directory
264 variables :pools => node[:nominatim][:fpm_pools]
267 apache_site "default" do
271 fail2ban_filter "nominatim" do
272 failregex '^<HOST> - - \[[^]]+\] "[^"]+" 429 '
275 fail2ban_jail "nominatim" do
277 logpath "/var/log/apache2/nominatim.openstreetmap.org-access.log"