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]
58 package "postgresql-#{postgresql_version}-postgis-#{postgis_version}"
60 node[:nominatim][:dbadmins].each do |user|
61 postgresql_user user do
62 cluster node[:nominatim][:dbcluster]
64 only_if { node[:nominatim][:state] != "slave" }
68 postgresql_user "nominatim" do
69 cluster node[:nominatim][:dbcluster]
71 only_if { node[:nominatim][:state] != "slave" }
74 postgresql_user "www-data" do
75 cluster node[:nominatim][:dbcluster]
76 only_if { node[:nominatim][:state] != "slave" }
79 postgresql_munin "nominatim" do
80 cluster node[:nominatim][:dbcluster]
81 database node[:nominatim][:dbname]
84 directory "#{basedir}/tablespaces" do
90 # Note: tablespaces must be exactly in the same location on each
91 # Nominatim instance when replication is in use. Therefore
92 # use symlinks to canonical directory locations.
93 node[:nominatim][:tablespaces].each do |name, location|
101 link "#{basedir}/tablespaces/#{name}" do
105 postgresql_tablespace name do
106 cluster node[:nominatim][:dbcluster]
107 location "#{basedir}/tablespaces/#{name}"
111 if node[:nominatim][:state] == "master"
112 postgresql_user "replication" do
113 cluster node[:nominatim][:dbcluster]
114 password data_bag_item("nominatim", "passwords")["replication"]
118 directory node[:rsyncd][:modules][:archive][:path] do
124 template "/usr/local/bin/clean-db-nominatim" do
125 source "clean-db-nominatim.erb"
129 variables :archive_dir => node[:rsyncd][:modules][:archive][:path],
130 :update_stop_file => "#{basedir}/status/updates_disabled",
131 :streaming_clients => search(:node, "nominatim_state:slave").map { |slave| slave[:fqdn] }.join(" ")
145 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]
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"
321 apache_module "rewrite"
322 apache_module "proxy"
323 apache_module "proxy_fcgi"
324 apache_module "proxy_http"
325 apache_module "headers"
327 service "php7.2-fpm" do
328 action [:enable, :start]
329 supports :status => true, :restart => true, :reload => true
332 node[:nominatim][:fpm_pools].each do |name, data|
333 template "/etc/php/7.2/fpm/pool.d/#{name}.conf" do
334 source "fpm.conf.erb"
338 variables data.merge(:name => name)
339 notifies :reload, "service[php7.2-fpm]"
343 systemd_service "apache-nominatim" do
347 notifies :restart, "service[apache2]"
350 ssl_certificate "nominatim.openstreetmap.org" do
351 domains ["nominatim.openstreetmap.org",
353 "nominatim.openstreetmap.com",
354 "nominatim.openstreetmap.net",
355 "nominatim.openstreetmaps.org",
356 "nominatim.openmaps.org"]
357 notifies :reload, "service[apache2]"
360 apache_site "nominatim.openstreetmap.org" do
361 template "apache.erb"
362 directory build_directory
363 variables :pools => node[:nominatim][:fpm_pools]
364 only_if { node[:nominatim][:state] != "off" }
367 apache_site "default" do
371 template "/etc/logrotate.d/apache2" do
372 source "logrotate.apache.erb"
378 include_recipe "fail2ban"
380 munin_plugin_conf "nominatim" do
382 variables :db => node[:nominatim][:dbname],
383 :querylog => "#{node[:nominatim][:logdir]}/query.log"
386 munin_plugin "nominatim_importlag" do
387 target "#{source_directory}/munin/nominatim_importlag"
390 munin_plugin "nominatim_query_speed" do
391 target "#{source_directory}/munin/nominatim_query_speed_querylog"
394 munin_plugin "nominatim_requests" do
395 target "#{source_directory}/munin/nominatim_requests_querylog"
398 munin_plugin "nominatim_throttled_ips" do
399 target "#{source_directory}/munin/nominatim_throttled_ips"
402 directory "#{basedir}/status" do