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"
35 home_directory = data_bag_item("accounts", "nominatim")["home"]
36 source_directory = "#{home_directory}/nominatim"
37 email_errors = data_bag_item("accounts", "lonvia")["email"]
39 database_cluster = node[:nominatim][:database][:cluster]
40 database_version = database_cluster.sub(%r{/.*}, "")
41 database_name = node[:nominatim][:database][:dbname]
43 postgis_version = node[:nominatim][:database][:postgis]
46 provider Chef::Provider::Service::Upstart
47 action [:enable, :start]
48 supports :status => true, :restart => true, :reload => true
51 node[:nominatim][:fpm_pools].each do |name, data|
52 template "/etc/php5/fpm/pool.d/#{name}.conf" do
57 variables data.merge(:name => name, :port => data[:port])
58 notifies :reload, "service[php5-fpm]"
62 postgresql_munin "nominatim" do
63 cluster database_cluster
64 database database_name
67 directory "/var/log/nominatim" do
73 directory "#{home_directory}/status" do
79 template "/etc/logrotate.d/nominatim" do
80 source "logrotate.nominatim.erb"
90 package "postgresql-#{database_version}-postgis-#{postgis_version}"
91 package "postgresql-server-dev-#{database_version}"
92 package "build-essential"
95 package "libgeos++-dev"
100 package "libproj-dev"
101 package "libprotobuf-c0-dev"
102 package "protobuf-c-compiler"
103 package "python-psycopg2"
104 package "libboost-dev"
105 package "libboost-system-dev"
106 package "libboost-filesystem-dev"
107 package "libboost-thread-dev"
109 execute "php-pear-db" do
110 command "pear install DB"
111 not_if { File.exist?("/usr/share/php/DB") }
114 execute "compile_nominatim" do
116 command "cd #{source_directory} && ./autogen.sh && ./configure && make"
120 directory "#{source_directory}/log" do
126 template "#{source_directory}/.git/hooks/post-merge" do
127 source "update_source.erb"
131 variables :source_directory => source_directory
134 template "#{source_directory}/settings/local.php" do
135 source "nominatim.erb"
139 variables :postgres_version => database_version
142 template "#{source_directory}/settings/ip_blocks.conf" do
143 action :create_if_missing
144 source "ipblocks.erb"
150 file "#{source_directory}/settings/apache_blocks.conf" do
151 action :create_if_missing
157 file "#{source_directory}/settings/ip_blocks.map" do
158 action :create_if_missing
164 if node[:nominatim][:enabled]
165 cron_action = :create
167 cron_action = :delete
170 template "/etc/cron.d/nominatim" do
176 variables :bin_directory => "#{source_directory}/utils", :mailto => email_errors
179 template "#{source_directory}/utils/nominatim-update" do
186 template "/etc/init.d/nominatim-update" do
187 source "updater.init.erb"
191 variables :source_directory => source_directory
194 munin_plugin_conf "nominatim" do
198 munin_plugin "nominatim_importlag" do
199 target "#{source_directory}/munin/nominatim_importlag"
202 munin_plugin "nominatim_query_speed" do
203 target "#{source_directory}/munin/nominatim_query_speed_querylog"
206 munin_plugin "nominatim_requests" do
207 target "#{source_directory}/munin/nominatim_requests_querylog"
210 munin_plugin "nominatim_throttled_ips" do
211 target "#{source_directory}/munin/nominatim_throttled_ips"
215 "wikipedia_article.sql.bin",
216 "wikipedia_redirect.sql.bin",
217 "gb_postcode_data.sql.gz"
220 external_data.each do |fname|
221 remote_file "#{source_directory}/data/#{fname}" do
222 action :create_if_missing
223 source "http://www.nominatim.org/data/#{fname}"
230 additional_scripts = %w(backup-nominatim vacuum-db-nominatim)
232 additional_scripts.each do |fname|
233 template "/usr/local/bin/#{fname}" do
234 source "#{fname}.erb"
241 directory File.dirname(node[:nominatim][:flatnode_file]) do
248 apache_site "nominatim.openstreetmap.org" do
249 template "apache.erb"
250 directory source_directory
251 variables :pools => node[:nominatim][:fpm_pools]
254 apache_site "default" do
258 fail2ban_filter "nominatim" do
259 failregex '^<HOST> - - \[[^]]+\] "[^"]+" 429 '
262 fail2ban_jail "nominatim" do
264 logpath "/var/log/apache2/nominatim.openstreetmap.org-access.log"