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 apache_site "nominatim.openstreetmap.org" do
54 directory source_directory
55 variables :pools => node[:nominatim][:fpm_pools]
58 apache_site "default" do
62 node[:nominatim][:fpm_pools].each do |name, data|
63 template "/etc/php5/fpm/pool.d/#{name}.conf" do
68 variables data.merge(:name => name, :port => data[:port])
69 notifies :reload, "service[php5-fpm]"
73 postgresql_munin "nominatim" do
74 cluster database_cluster
75 database database_name
78 directory "/var/log/nominatim" do
84 template "/etc/logrotate.d/nominatim" do
85 source "logrotate.nominatim.erb"
95 package "postgresql-#{database_version}-postgis-#{postgis_version}"
96 package "postgresql-server-dev-#{database_version}"
97 package "build-essential"
100 package "libgeos++-dev"
105 package "libproj-dev"
106 package "libprotobuf-c0-dev"
107 package "protobuf-c-compiler"
108 package "python-psycopg2"
109 package "libboost-dev"
110 package "libboost-system-dev"
111 package "libboost-filesystem-dev"
112 package "libboost-thread-dev"
114 execute "php-pear-db" do
115 command "pear install DB"
116 not_if { File.exist?("/usr/share/php/DB") }
119 execute "compile_nominatim" do
121 command "cd #{source_directory} && ./autogen.sh && ./configure && make"
125 directory "#{source_directory}/log" do
131 template "#{source_directory}/.git/hooks/post-merge" do
132 source "update_source.erb"
136 variables :source_directory => source_directory
139 template "#{source_directory}/settings/local.php" do
140 source "nominatim.erb"
144 variables :postgres_version => database_version
147 template "#{source_directory}/settings/ip_blocks.conf" do
148 action :create_if_missing
149 source "ipblocks.erb"
155 file "#{source_directory}/settings/apache_blocks.conf" do
156 action :create_if_missing
162 file "#{source_directory}/settings/ip_blocks.map" do
163 action :create_if_missing
169 if node[:nominatim][:enabled]
170 cron_action = :create
172 cron_action = :delete
175 template "/etc/cron.d/nominatim" do
181 variables :bin_directory => "#{source_directory}/utils", :mailto => email_errors
184 template "#{source_directory}/utils/nominatim-update" do
191 template "/etc/init.d/nominatim-update" do
192 source "updater.init.erb"
196 variables :source_directory => source_directory
199 munin_plugin_conf "nominatim" do
203 munin_plugin "nominatim_importlag" do
204 target "#{source_directory}/munin/nominatim_importlag"
207 munin_plugin "nominatim_query_speed" do
208 target "#{source_directory}/munin/nominatim_query_speed_querylog"
211 munin_plugin "nominatim_requests" do
212 target "#{source_directory}/munin/nominatim_requests_querylog"
215 munin_plugin "nominatim_throttled_ips" do
216 target "#{source_directory}/munin/nominatim_throttled_ips"
220 "wikipedia_article.sql.bin",
221 "wikipedia_redirect.sql.bin",
222 "gb_postcode_data.sql.gz"
225 external_data.each do |fname|
226 remote_file "#{source_directory}/data/#{fname}" do
227 action :create_if_missing
228 source "http://www.nominatim.org/data/#{fname}"
235 additional_scripts = %w(backup-nominatim clean-db-nominatim)
237 additional_scripts.each do |fname|
238 template "/usr/local/bin/#{fname}" do
239 source "#{fname}.erb"
246 directory File.dirname(node[:nominatim][:flatnode_file]) do
253 directory "/data/postgresql-archive" do
257 only_if { node[:postgresql][:settings][:defaults][:archive_mode] == "on" }
260 fail2ban_filter "nominatim" do
261 failregex '^<HOST> - - \[[^]]+\] "[^"]+" 429 '
264 fail2ban_jail "nominatim" do
266 logpath "/var/log/apache2/nominatim.openstreetmap.org-access.log"