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 # https://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"
55 postgresql_version = node[:nominatim][:dbcluster].split("/").first
56 postgis_version = node[:nominatim][:postgis]
59 package "postgresql-#{postgresql_version}-postgis-#{postgis_version}"
61 node[:nominatim][:dbadmins].each do |user|
62 postgresql_user user do
63 cluster node[:nominatim][:dbcluster]
65 only_if { node[:nominatim][:state] != "slave" }
69 postgresql_user "nominatim" do
70 cluster node[:nominatim][:dbcluster]
72 only_if { node[:nominatim][:state] != "slave" }
75 postgresql_user "www-data" do
76 cluster node[:nominatim][:dbcluster]
77 only_if { node[:nominatim][:state] != "slave" }
80 postgresql_munin "nominatim" do
81 cluster node[:nominatim][:dbcluster]
82 database node[:nominatim][:dbname]
85 directory "#{basedir}/tablespaces" do
91 # Note: tablespaces must be exactly in the same location on each
92 # Nominatim instance when replication is in use. Therefore
93 # use symlinks to canonical directory locations.
94 node[:nominatim][:tablespaces].each do |name, location|
102 link "#{basedir}/tablespaces/#{name}" do
106 postgresql_tablespace name do
107 cluster node[:nominatim][:dbcluster]
108 location "#{basedir}/tablespaces/#{name}"
112 if node[:nominatim][:state] == "master" # ~FC023
113 postgresql_user "replication" do
114 cluster node[:nominatim][:dbcluster]
115 password data_bag_item("nominatim", "passwords")["replication"]
119 directory node[:rsyncd][:modules][:archive][:path] do
125 template "/usr/local/bin/clean-db-nominatim" do
126 source "clean-db-nominatim.erb"
130 variables :archive_dir => node[:rsyncd][:modules][:archive][:path],
131 :update_stop_file => "#{basedir}/status/updates_disabled",
132 :streaming_clients => search(:node, "nominatim_state:slave").map { |slave| slave[:fqdn] }.join(" ")
139 include_recipe "python"
141 package "build-essential"
144 package "libboost-dev"
145 package "libboost-system-dev"
146 package "libboost-filesystem-dev"
147 package "libexpat1-dev"
149 package "libxml2-dev"
152 package "libgeos++-dev"
153 package "libproj-dev"
156 if node[:lsb][:release].to_f >= 18.04
159 package "libboost-python-dev"
160 python_package "osmium"
163 source_directory = "#{basedir}/nominatim"
164 build_directory = "#{basedir}/bin"
166 directory build_directory do
173 # Normally syncing via chef is a bad idea because syncing might involve
174 # an update of database functions which should not be done while an update
175 # is ongoing. Therefore we sync in between update cycles. There is an
176 # exception for slaves: they get DB function updates from the master, so
177 # only the source code needs to be updated, which chef may do.
178 git source_directory do
179 action node[:nominatim][:state] == "slave" ? :sync : :checkout
180 repository node[:nominatim][:repository]
181 revision node[:nominatim][:revision]
182 enable_submodules true
185 not_if { node[:nominatim][:state] != "slave" && File.exist?("#{source_directory}/README.md") }
186 notifies :run, "execute[compile_nominatim]", :immediately
189 execute "compile_nominatim" do
193 command "cmake #{source_directory} && make"
196 template "#{source_directory}/.git/hooks/post-merge" do
197 source "git-post-merge-hook.erb"
201 variables :srcdir => source_directory,
202 :builddir => build_directory,
203 :dbname => node[:nominatim][:dbname]
206 template "#{build_directory}/settings/local.php" do
207 source "settings.erb"
211 variables :base_url => node[:nominatim][:state] == "off" ? node[:fqdn] : "nominatim.openstreetmap.org",
212 :dbname => node[:nominatim][:dbname],
213 :flatnode_file => node[:nominatim][:flatnode_file],
214 :log_file => "#{node[:nominatim][:logdir]}/query.log"
217 if node[:nominatim][:flatnode_file] # ~FC023
218 directory File.dirname(node[:nominatim][:flatnode_file]) do
223 template "/etc/logrotate.d/nominatim" do
224 source "logrotate.nominatim.erb"
231 "wikipedia_article.sql.bin",
232 "wikipedia_redirect.sql.bin",
233 "gb_postcode_data.sql.gz"
236 external_data.each do |fname|
237 remote_file "#{source_directory}/data/#{fname}" do
238 action :create_if_missing
239 source "https://www.nominatim.org/data/#{fname}"
246 remote_file "#{source_directory}/data/country_osm_grid.sql.gz" do
247 action :create_if_missing
248 source "https://www.nominatim.org/data/country_grid.sql.gz"
254 template "/etc/cron.d/nominatim" do
255 action node[:nominatim][:state] == :off ? :delete : :create
256 source "nominatim.cron.erb"
260 variables :bin_directory => "#{source_directory}/utils",
261 :mailto => email_errors,
262 :update_maintenance_trigger => "#{basedir}/status/update_maintenance"
265 template "#{source_directory}/utils/nominatim-update" do
270 variables :bindir => build_directory,
271 :srcdir => source_directory,
272 :logfile => "#{node[:nominatim][:logdir]}/update.log",
273 :branch => node[:nominatim][:revision],
274 :update_stop_file => "#{basedir}/status/updates_disabled",
275 :update_maintenance_trigger => "#{basedir}/status/update_maintenance"
278 template "/etc/init.d/nominatim-update" do
279 source "updater.init.erb"
283 variables :source_directory => source_directory
286 %w[backup-nominatim vacuum-db-nominatim].each do |fname|
287 template "/usr/local/bin/#{fname}" do
288 source "#{fname}.erb"
292 variables :db => node[:nominatim][:dbname]
296 ## webserver frontend
298 template "#{build_directory}/settings/ip_blocks.conf" do
299 action :create_if_missing
300 source "ipblocks.erb"
306 file "#{build_directory}/settings/apache_blocks.conf" do
307 action :create_if_missing
313 file "#{build_directory}/settings/ip_blocks.map" do
314 action :create_if_missing
320 include_recipe "apache"
329 apache_module "rewrite"
330 apache_module "proxy"
331 apache_module "proxy_fcgi"
332 apache_module "proxy_http"
333 apache_module "headers"
335 php_version = if node[:lsb][:release].to_f >= 18.04
341 service "php#{php_version}-fpm" do
342 action [:enable, :start]
343 supports :status => true, :restart => true, :reload => true
346 node[:nominatim][:fpm_pools].each do |name, data|
347 template "/etc/php/#{php_version}/fpm/pool.d/#{name}.conf" do
348 source "fpm.conf.erb"
352 variables data.merge(:name => name)
353 notifies :reload, "service[php#{php_version}-fpm]"
357 ssl_certificate "nominatim.openstreetmap.org" do
358 domains ["nominatim.openstreetmap.org",
360 "nominatim.openstreetmap.com",
361 "nominatim.openstreetmap.net",
362 "nominatim.openstreetmaps.org",
363 "nominatim.openmaps.org"]
364 notifies :reload, "service[apache2]"
367 apache_site "nominatim.openstreetmap.org" do
368 template "apache.erb"
369 directory build_directory
370 variables :pools => node[:nominatim][:fpm_pools]
373 apache_site "default" do
377 template "/etc/logrotate.d/apache2" do
378 source "logrotate.apache.erb"
384 include_recipe "fail2ban"
386 munin_plugin_conf "nominatim" do
388 variables :db => node[:nominatim][:dbname],
389 :querylog => "#{node[:nominatim][:logdir]}/query.log"
392 munin_plugin "nominatim_importlag" do
393 target "#{source_directory}/munin/nominatim_importlag"
396 munin_plugin "nominatim_query_speed" do
397 target "#{source_directory}/munin/nominatim_query_speed_querylog"
400 munin_plugin "nominatim_requests" do
401 target "#{source_directory}/munin/nominatim_requests_querylog"
404 munin_plugin "nominatim_throttled_ips" do
405 target "#{source_directory}/munin/nominatim_throttled_ips"
408 directory "#{basedir}/status" do