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 directory "#{home_directory}/status" do
80 template "/etc/logrotate.d/nominatim" do
81 source "logrotate.nominatim.erb"
91 package "postgresql-#{database_version}-postgis-#{postgis_version}"
92 package "postgresql-server-dev-#{database_version}"
93 package "build-essential"
95 package "libexpat-dev"
97 package "libgeos++-dev"
102 package "libproj-dev"
103 package "libprotobuf-c0-dev"
104 package "protobuf-c-compiler"
105 package "python-psycopg2"
106 package "libboost-dev"
107 package "libboost-system-dev"
108 package "libboost-filesystem-dev"
109 package "libboost-thread-dev"
111 execute "compile_nominatim" do
113 command "cd #{source_directory} && ./autogen.sh && ./configure && make"
117 directory "#{source_directory}/log" do
123 template "#{source_directory}/.git/hooks/post-merge" do
124 source "update_source.erb"
128 variables :source_directory => source_directory
131 template "#{source_directory}/settings/local.php" do
132 source "nominatim.erb"
136 variables :postgres_version => database_version
139 template "#{source_directory}/settings/ip_blocks.conf" do
140 action :create_if_missing
141 source "ipblocks.erb"
147 file "#{source_directory}/settings/apache_blocks.conf" do
148 action :create_if_missing
154 file "#{source_directory}/settings/ip_blocks.map" do
155 action :create_if_missing
161 if node[:nominatim][:enabled]
162 cron_action = :create
164 cron_action = :delete
167 template "/etc/cron.d/nominatim" do
173 variables :bin_directory => "#{source_directory}/utils", :mailto => email_errors
176 template "#{source_directory}/utils/nominatim-update" do
183 template "/etc/init.d/nominatim-update" do
184 source "updater.init.erb"
188 variables :source_directory => source_directory
191 munin_plugin_conf "nominatim" do
195 munin_plugin "nominatim_importlag" do
196 target "#{source_directory}/munin/nominatim_importlag"
199 munin_plugin "nominatim_query_speed" do
200 target "#{source_directory}/munin/nominatim_query_speed_querylog"
203 munin_plugin "nominatim_requests" do
204 target "#{source_directory}/munin/nominatim_requests_querylog"
207 munin_plugin "nominatim_throttled_ips" do
208 target "#{source_directory}/munin/nominatim_throttled_ips"
212 "wikipedia_article.sql.bin",
213 "wikipedia_redirect.sql.bin",
214 "gb_postcode_data.sql.gz"
217 external_data.each do |fname|
218 remote_file "#{source_directory}/data/#{fname}" do
219 action :create_if_missing
220 source "http://www.nominatim.org/data/#{fname}"
227 additional_scripts = %w(backup-nominatim vacuum-db-nominatim)
229 additional_scripts.each do |fname|
230 template "/usr/local/bin/#{fname}" do
231 source "#{fname}.erb"
238 directory File.dirname(node[:nominatim][:flatnode_file]) do
245 apache_site "nominatim.openstreetmap.org" do
246 template "apache.erb"
247 directory source_directory
248 variables :pools => node[:nominatim][:fpm_pools]
251 apache_site "default" do
255 fail2ban_filter "nominatim" do
256 failregex '^<HOST> - - \[[^]]+\] "[^"]+" 429 '
259 fail2ban_jail "nominatim" do
261 logpath "/var/log/apache2/nominatim.openstreetmap.org-access.log"