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(" ")
146 libboost-filesystem-dev
157 source_directory = "#{basedir}/nominatim"
158 build_directory = "#{basedir}/bin"
160 directory build_directory do
167 # Normally syncing via chef is a bad idea because syncing might involve
168 # an update of database functions which should not be done while an update
169 # is ongoing. Therefore we sync in between update cycles. There is an
170 # exception for slaves: they get DB function updates from the master, so
171 # only the source code needs to be updated, which chef may do.
172 git source_directory do
173 action node[:nominatim][:state] == "slave" ? :sync : :checkout
174 repository node[:nominatim][:repository]
175 revision node[:nominatim][:revision]
176 enable_submodules true
179 not_if { node[:nominatim][:state] != "slave" && File.exist?("#{source_directory}/README.md") }
180 notifies :run, "execute[compile_nominatim]", :immediately
183 execute "compile_nominatim" do
187 command "cmake #{source_directory} && make"
190 template "#{source_directory}/.git/hooks/post-merge" do
191 source "git-post-merge-hook.erb"
195 variables :srcdir => source_directory,
196 :builddir => build_directory,
197 :dbname => node[:nominatim][:dbname]
200 template "#{build_directory}/settings/local.php" do
201 source "settings.erb"
205 variables :base_url => node[:nominatim][:state] == "off" ? node[:fqdn] : "nominatim.openstreetmap.org",
206 :dbname => node[:nominatim][:dbname],
207 :flatnode_file => node[:nominatim][:flatnode_file],
208 :log_file => "#{node[:nominatim][:logdir]}/query.log"
211 if node[:nominatim][:flatnode_file] # ~FC023
212 directory File.dirname(node[:nominatim][:flatnode_file]) do
217 template "/etc/logrotate.d/nominatim" do
218 source "logrotate.nominatim.erb"
225 "wikipedia_article.sql.bin",
226 "wikipedia_redirect.sql.bin",
227 "gb_postcode_data.sql.gz"
230 external_data.each do |fname|
231 remote_file "#{source_directory}/data/#{fname}" do
232 action :create_if_missing
233 source "https://www.nominatim.org/data/#{fname}"
240 remote_file "#{source_directory}/data/country_osm_grid.sql.gz" do
241 action :create_if_missing
242 source "https://www.nominatim.org/data/country_grid.sql.gz"
248 template "/etc/cron.d/nominatim" do
249 action node[:nominatim][:state] == "off" ? :delete : :create
250 source "nominatim.cron.erb"
254 variables :bin_directory => "#{source_directory}/utils",
255 :mailto => email_errors,
256 :update_maintenance_trigger => "#{basedir}/status/update_maintenance"
259 template "#{source_directory}/utils/nominatim-update" do
264 variables :bindir => build_directory,
265 :srcdir => source_directory,
266 :logfile => "#{node[:nominatim][:logdir]}/update.log",
267 :branch => node[:nominatim][:revision],
268 :update_stop_file => "#{basedir}/status/updates_disabled",
269 :update_maintenance_trigger => "#{basedir}/status/update_maintenance"
272 template "/etc/init.d/nominatim-update" do
273 source "updater.init.erb"
277 variables :source_directory => source_directory
280 %w[backup-nominatim vacuum-db-nominatim].each do |fname|
281 template "/usr/local/bin/#{fname}" do
282 source "#{fname}.erb"
286 variables :db => node[:nominatim][:dbname]
290 ## webserver frontend
292 template "#{build_directory}/settings/ip_blocks.conf" do
293 action :create_if_missing
294 source "ipblocks.erb"
300 file "#{build_directory}/settings/apache_blocks.conf" do
301 action :create_if_missing
307 file "#{build_directory}/settings/ip_blocks.map" do
308 action :create_if_missing
314 include_recipe "apache"
323 apache_module "rewrite"
324 apache_module "proxy"
325 apache_module "proxy_fcgi"
326 apache_module "proxy_http"
327 apache_module "headers"
329 service "php7.2-fpm" do
330 action [:enable, :start]
331 supports :status => true, :restart => true, :reload => true
334 node[:nominatim][:fpm_pools].each do |name, data|
335 template "/etc/php/7.2/fpm/pool.d/#{name}.conf" do
336 source "fpm.conf.erb"
340 variables data.merge(:name => name)
341 notifies :reload, "service[php7.2-fpm]"
345 ssl_certificate "nominatim.openstreetmap.org" do
346 domains ["nominatim.openstreetmap.org",
348 "nominatim.openstreetmap.com",
349 "nominatim.openstreetmap.net",
350 "nominatim.openstreetmaps.org",
351 "nominatim.openmaps.org"]
352 notifies :reload, "service[apache2]"
355 apache_site "nominatim.openstreetmap.org" do
356 template "apache.erb"
357 directory build_directory
358 variables :pools => node[:nominatim][:fpm_pools]
359 only_if { node[:nominatim][:state] != "off" }
362 apache_site "default" do
366 template "/etc/logrotate.d/apache2" do
367 source "logrotate.apache.erb"
373 include_recipe "fail2ban"
375 munin_plugin_conf "nominatim" do
377 variables :db => node[:nominatim][:dbname],
378 :querylog => "#{node[:nominatim][:logdir]}/query.log"
381 munin_plugin "nominatim_importlag" do
382 target "#{source_directory}/munin/nominatim_importlag"
385 munin_plugin "nominatim_query_speed" do
386 target "#{source_directory}/munin/nominatim_query_speed_querylog"
389 munin_plugin "nominatim_requests" do
390 target "#{source_directory}/munin/nominatim_requests_querylog"
393 munin_plugin "nominatim_throttled_ips" do
394 target "#{source_directory}/munin/nominatim_throttled_ips"
397 directory "#{basedir}/status" do