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 basedir = data_bag_item("accounts", "nominatim")["home"]
21 email_errors = data_bag_item("accounts", "lonvia")["email"]
30 directory node[:nominatim][:logdir] do
37 file "#{node[:nominatim][:logdir]}/query.log" do
38 action :create_if_missing
44 file "#{node[:nominatim][:logdir]}/update.log" do
45 action :create_if_missing
53 include_recipe "postgresql"
57 node[:nominatim][:dbadmins].each do |user|
58 postgresql_user user do
59 cluster node[:nominatim][:dbcluster]
61 only_if { node[:nominatim][:state] != "slave" }
65 postgresql_user "nominatim" do
66 cluster node[:nominatim][:dbcluster]
68 only_if { node[:nominatim][:state] != "slave" }
71 postgresql_user "www-data" do
72 cluster node[:nominatim][:dbcluster]
73 only_if { node[:nominatim][:state] != "slave" }
76 postgresql_munin "nominatim" do
77 cluster node[:nominatim][:dbcluster]
78 database node[:nominatim][:dbname]
81 directory "#{basedir}/tablespaces" do
87 # Note: tablespaces must be exactly in the same location on each
88 # Nominatim instance when replication is in use. Therefore
89 # use symlinks to canonical directory locations.
90 node[:nominatim][:tablespaces].each do |name, location|
98 link "#{basedir}/tablespaces/#{name}" do
102 postgresql_tablespace name do
103 cluster node[:nominatim][:dbcluster]
104 location "#{basedir}/tablespaces/#{name}"
108 if node[:nominatim][:state] == "master" # ~FC023
109 postgresql_user "replication" do
110 cluster node[:nominatim][:dbcluster]
111 password data_bag_item("nominatim", "passwords")["replication"]
115 directory node[:rsyncd][:modules][:archive][:path] do
121 template "/usr/local/bin/clean-db-nominatim" do
122 source "clean-db-nominatim.erb"
126 variables :archive_dir => node[:rsyncd][:modules][:archive][:path],
127 :update_stop_file => "#{basedir}/status/updates_disabled",
128 :streaming_clients => search(:node, "nominatim_state:slave").map { |slave| slave[:fqdn] }.join(" ")
136 package "build-essential"
139 package "libboost-dev"
140 package "libboost-system-dev"
141 package "libboost-filesystem-dev"
142 package "libexpat1-dev"
144 package "libxml2-dev"
147 package "libgeos++-dev"
148 package "libproj-dev"
151 source_directory = "#{basedir}/nominatim"
152 build_directory = "#{basedir}/bin"
154 directory build_directory do
161 # Normally syncing via chef is a bad idea because syncing might involve
162 # an update of database functions which should not be done while an update
163 # is ongoing. Therefore we sync in between update cycles. There is an
164 # exception for slaves: they get DB function updates from the master, so
165 # only the source code needs to be updated, which chef may do.
166 git source_directory do
167 action node[:nominatim][:state] == "slave" ? :sync : :checkout
168 repository node[:nominatim][:repository]
169 revision node[:nominatim][:revision]
170 enable_submodules true
173 notifies :run, "execute[compile_nominatim]", :immediately
176 execute "compile_nominatim" do
180 command "cmake #{source_directory} && make"
183 template "#{source_directory}/.git/hooks/post-merge" do
184 source "git-post-merge-hook.erb"
188 variables :srcdir => source_directory,
189 :builddir => build_directory,
190 :dbname => node[:nominatim][:dbname]
193 template "#{build_directory}/settings/local.php" do
194 source "settings.erb"
198 variables :base_url => node[:nominatim][:state] == "off" ? node[:fqdn] : "nominatim.openstreetmap.org",
199 :dbname => node[:nominatim][:dbname],
200 :flatnode_file => node[:nominatim][:flatnode_file],
201 :log_file => "#{node[:nominatim][:logdir]}/query.log"
204 if node[:nominatim][:flatnode_file] # ~FC023
205 directory File.dirname(node[:nominatim][:flatnode_file]) do
210 template "/etc/logrotate.d/nominatim" do
211 source "logrotate.nominatim.erb"
218 "wikipedia_article.sql.bin",
219 "wikipedia_redirect.sql.bin",
220 "gb_postcode_data.sql.gz"
223 external_data.each do |fname|
224 remote_file "#{source_directory}/data/#{fname}" do
225 action :create_if_missing
226 source "http://www.nominatim.org/data/#{fname}"
233 template "/etc/cron.d/nominatim" do
234 action node[:nominatim][:state] == :off ? :delete : :create
235 source "nominatim.cron.erb"
239 variables :bin_directory => "#{source_directory}/utils", :mailto => email_errors
242 template "#{source_directory}/utils/nominatim-update" do
247 variables :bindir => build_directory,
248 :srcdir => source_directory,
249 :logfile => "#{node[:nominatim][:logdir]}/update.log",
250 :branch => node[:nominatim][:revision],
251 :update_stop_file => "#{basedir}/status/updates_disabled"
254 template "/etc/init.d/nominatim-update" do
255 source "updater.init.erb"
259 variables :source_directory => source_directory
262 %w(backup-nominatim vacuum-db-nominatim).each do |fname|
263 template "/usr/local/bin/#{fname}" do
264 source "#{fname}.erb"
268 variables :db => node[:nominatim][:dbname]
272 ## webserver frontend
274 template "#{build_directory}/settings/ip_blocks.conf" do
275 action :create_if_missing
276 source "ipblocks.erb"
282 file "#{build_directory}/settings/apache_blocks.conf" do
283 action :create_if_missing
289 file "#{build_directory}/settings/ip_blocks.map" do
290 action :create_if_missing
296 include_recipe "apache::ssl"
304 apache_module "rewrite"
305 apache_module "proxy"
306 apache_module "proxy_fcgi"
307 apache_module "proxy_http"
308 apache_module "headers"
310 service "php5-fpm" do
311 if node[:lsb][:release].to_f >= 15.10
312 provider Chef::Provider::Service::Systemd
313 service_name "php7.0-fpm"
314 elsif node[:lsb][:release].to_f >= 14.04
315 provider Chef::Provider::Service::Upstart
317 action [:enable, :start]
318 supports :status => true, :restart => true, :reload => true
321 php_confdir = node[:lsb][:release].to_f >= 15.10 ? "/etc/php/7.0" : "/etc/php5"
323 node[:nominatim][:fpm_pools].each do |name, data|
324 template "#{php_confdir}/fpm/pool.d/#{name}.conf" do
325 source "fpm.conf.erb"
329 variables data.merge(:name => name)
330 notifies :reload, "service[php5-fpm]"
334 apache_site "nominatim.openstreetmap.org" do
335 template "apache.erb"
336 directory build_directory
337 variables :pools => node[:nominatim][:fpm_pools]
340 apache_site "default" do
344 template "/etc/logrotate.d/apache2" do
345 source "logrotate.apache.erb"
351 include_recipe "fail2ban"
353 fail2ban_filter "nominatim" do
354 failregex '^<HOST> - - \[\] "[^"]+" 429 '
357 fail2ban_jail "nominatim" do
359 logpath "/var/log/apache2/nominatim.openstreetmap.org-access.log"
364 munin_plugin_conf "nominatim" do
366 variables :db => node[:nominatim][:dbname],
367 :querylog => "#{node[:nominatim][:logdir]}/query.log"
370 munin_plugin "nominatim_importlag" do
371 target "#{source_directory}/munin/nominatim_importlag"
374 munin_plugin "nominatim_query_speed" do
375 target "#{source_directory}/munin/nominatim_query_speed_querylog"
378 munin_plugin "nominatim_requests" do
379 target "#{source_directory}/munin/nominatim_requests_querylog"
382 munin_plugin "nominatim_throttled_ips" do
383 target "#{source_directory}/munin/nominatim_throttled_ips"
386 directory "#{basedir}/status" do