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 "/var/log/nominatim" do
74 template "/etc/logrotate.d/nominatim" do
75 source "logrotate.nominatim.erb"
85 package "postgresql-#{database_version}-postgis-#{postgis_version}"
86 package "postgresql-server-dev-#{database_version}"
87 package "build-essential"
90 package "libgeos++-dev"
96 package "libprotobuf-c0-dev"
97 package "protobuf-c-compiler"
98 package "python-psycopg2"
99 package "libboost-dev"
100 package "libboost-system-dev"
101 package "libboost-filesystem-dev"
102 package "libboost-thread-dev"
104 execute "php-pear-db" do
105 command "pear install DB"
106 not_if { File.exist?("/usr/share/php/DB") }
109 execute "compile_nominatim" do
111 command "cd #{source_directory} && ./autogen.sh && ./configure && make"
115 directory "#{source_directory}/log" do
121 template "#{source_directory}/.git/hooks/post-merge" do
122 source "update_source.erb"
126 variables :source_directory => source_directory
129 template "#{source_directory}/settings/local.php" do
130 source "nominatim.erb"
134 variables :postgres_version => database_version
137 template "#{source_directory}/settings/ip_blocks.conf" do
138 action :create_if_missing
139 source "ipblocks.erb"
145 file "#{source_directory}/settings/apache_blocks.conf" do
146 action :create_if_missing
152 file "#{source_directory}/settings/ip_blocks.map" do
153 action :create_if_missing
159 if node[:nominatim][:enabled]
160 cron_action = :create
162 cron_action = :delete
165 template "/etc/cron.d/nominatim" do
171 variables :bin_directory => "#{source_directory}/utils", :mailto => email_errors
174 template "#{source_directory}/utils/nominatim-update" do
181 template "/etc/init.d/nominatim-update" do
182 source "updater.init.erb"
186 variables :source_directory => source_directory
189 munin_plugin_conf "nominatim" do
193 munin_plugin "nominatim_importlag" do
194 target "#{source_directory}/munin/nominatim_importlag"
197 munin_plugin "nominatim_query_speed" do
198 target "#{source_directory}/munin/nominatim_query_speed_querylog"
201 munin_plugin "nominatim_requests" do
202 target "#{source_directory}/munin/nominatim_requests_querylog"
205 munin_plugin "nominatim_throttled_ips" do
206 target "#{source_directory}/munin/nominatim_throttled_ips"
210 "wikipedia_article.sql.bin",
211 "wikipedia_redirect.sql.bin",
212 "gb_postcode_data.sql.gz"
215 external_data.each do |fname|
216 remote_file "#{source_directory}/data/#{fname}" do
217 action :create_if_missing
218 source "http://www.nominatim.org/data/#{fname}"
225 additional_scripts = %w(backup-nominatim clean-db-nominatim)
227 additional_scripts.each do |fname|
228 template "/usr/local/bin/#{fname}" do
229 source "#{fname}.erb"
236 directory File.dirname(node[:nominatim][:flatnode_file]) do
243 directory "/data/postgresql-archive" do
247 only_if { node[:postgresql][:settings][:defaults][:archive_mode] == "on" }
250 apache_site "nominatim.openstreetmap.org" do
251 template "apache.erb"
252 directory source_directory
253 variables :pools => node[:nominatim][:fpm_pools]
256 apache_site "default" do
260 fail2ban_filter "nominatim" do
261 failregex '^<HOST> - - \[[^]]+\] "[^"]+" 429 '
264 fail2ban_jail "nominatim" do
266 logpath "/var/log/apache2/nominatim.openstreetmap.org-access.log"