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 template "/etc/logrotate.d/nominatim" do
74 source "logrotate.nominatim.erb"
84 package "postgresql-#{database_version}-postgis-#{postgis_version}"
85 package "postgresql-server-dev-#{database_version}"
86 package "build-essential"
89 package "libgeos++-dev"
95 package "libprotobuf-c0-dev"
96 package "protobuf-c-compiler"
97 package "python-psycopg2"
98 package "libboost-dev"
99 package "libboost-system-dev"
100 package "libboost-filesystem-dev"
101 package "libboost-thread-dev"
103 execute "php-pear-db" do
104 command "pear install DB"
105 not_if { File.exist?("/usr/share/php/DB") }
108 execute "compile_nominatim" do
110 command "cd #{source_directory} && ./autogen.sh && ./configure && make"
114 directory "#{source_directory}/log" do
120 template "#{source_directory}/.git/hooks/post-merge" do
121 source "update_source.erb"
125 variables :source_directory => source_directory
128 template "#{source_directory}/settings/local.php" do
129 source "nominatim.erb"
133 variables :postgres_version => database_version
136 template "#{source_directory}/settings/ip_blocks.conf" do
137 action :create_if_missing
138 source "ipblocks.erb"
144 file "#{source_directory}/settings/apache_blocks.conf" do
145 action :create_if_missing
151 file "#{source_directory}/settings/ip_blocks.map" do
152 action :create_if_missing
158 if node[:nominatim][:enabled]
159 cron_action = :create
161 cron_action = :delete
164 template "/etc/cron.d/nominatim" do
170 variables :bin_directory => "#{source_directory}/utils", :mailto => email_errors
173 template "#{source_directory}/utils/nominatim-update" do
180 template "/etc/init.d/nominatim-update" do
181 source "updater.init.erb"
185 variables :source_directory => source_directory
188 munin_plugin_conf "nominatim" do
192 munin_plugin "nominatim_importlag" do
193 target "#{source_directory}/munin/nominatim_importlag"
196 munin_plugin "nominatim_query_speed" do
197 target "#{source_directory}/munin/nominatim_query_speed_querylog"
200 munin_plugin "nominatim_requests" do
201 target "#{source_directory}/munin/nominatim_requests_querylog"
204 munin_plugin "nominatim_throttled_ips" do
205 target "#{source_directory}/munin/nominatim_throttled_ips"
209 "wikipedia_article.sql.bin",
210 "wikipedia_redirect.sql.bin",
211 "gb_postcode_data.sql.gz"
214 external_data.each do |fname|
215 remote_file "#{source_directory}/data/#{fname}" do
216 action :create_if_missing
217 source "http://www.nominatim.org/data/#{fname}"
224 additional_scripts = %w(backup-nominatim clean-db-nominatim)
226 additional_scripts.each do |fname|
227 template "/usr/local/bin/#{fname}" do
228 source "#{fname}.erb"
235 directory File.dirname(node[:nominatim][:flatnode_file]) do
242 directory "/data/postgresql-archive" do
246 only_if { node[:postgresql][:settings][:defaults][:archive_mode] == "on" }
249 apache_site "nominatim.openstreetmap.org" do
250 template "apache.erb"
251 directory source_directory
252 variables :pools => node[:nominatim][:fpm_pools]
255 apache_site "default" do
259 fail2ban_filter "nominatim" do
260 failregex '^<HOST> - - \[[^]]+\] "[^"]+" 429 '
263 fail2ban_jail "nominatim" do
265 logpath "/var/log/apache2/nominatim.openstreetmap.org-access.log"