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 "wikimedia-importance.sql.gz",
226 "gb_postcode_data.sql.gz"
229 external_data.each do |fname|
230 remote_file "#{source_directory}/data/#{fname}" do
231 action :create_if_missing
232 source "https://www.nominatim.org/data/#{fname}"
239 remote_file "#{source_directory}/data/country_osm_grid.sql.gz" do
240 action :create_if_missing
241 source "https://www.nominatim.org/data/country_grid.sql.gz"
247 template "/etc/cron.d/nominatim" do
248 action node[:nominatim][:state] == "off" ? :delete : :create
249 source "nominatim.cron.erb"
253 variables :bin_directory => "#{source_directory}/utils",
254 :mailto => email_errors,
255 :update_maintenance_trigger => "#{basedir}/status/update_maintenance"
258 template "#{source_directory}/utils/nominatim-update" do
263 variables :bindir => build_directory,
264 :srcdir => source_directory,
265 :logfile => "#{node[:nominatim][:logdir]}/update.log",
266 :branch => node[:nominatim][:revision],
267 :update_stop_file => "#{basedir}/status/updates_disabled",
268 :update_maintenance_trigger => "#{basedir}/status/update_maintenance"
271 template "/etc/init.d/nominatim-update" do
272 source "updater.init.erb"
276 variables :source_directory => source_directory
279 %w[backup-nominatim vacuum-db-nominatim].each do |fname|
280 template "/usr/local/bin/#{fname}" do
281 source "#{fname}.erb"
285 variables :db => node[:nominatim][:dbname]
289 ## webserver frontend
291 template "#{build_directory}/settings/ip_blocks.conf" do
292 action :create_if_missing
293 source "ipblocks.erb"
299 file "#{build_directory}/settings/apache_blocks.conf" do
300 action :create_if_missing
306 file "#{build_directory}/settings/ip_blocks.map" do
307 action :create_if_missing
313 include_recipe "apache"
320 apache_module "rewrite"
321 apache_module "proxy"
322 apache_module "proxy_fcgi"
323 apache_module "proxy_http"
324 apache_module "headers"
326 service "php7.2-fpm" do
327 action [:enable, :start]
328 supports :status => true, :restart => true, :reload => true
331 node[:nominatim][:fpm_pools].each do |name, data|
332 template "/etc/php/7.2/fpm/pool.d/#{name}.conf" do
333 source "fpm.conf.erb"
337 variables data.merge(:name => name)
338 notifies :reload, "service[php7.2-fpm]"
342 systemd_service "apache-nominatim" do
346 notifies :restart, "service[apache2]"
349 ssl_certificate "nominatim.openstreetmap.org" do
350 domains ["nominatim.openstreetmap.org",
352 "nominatim.openstreetmap.com",
353 "nominatim.openstreetmap.net",
354 "nominatim.openstreetmaps.org",
355 "nominatim.openmaps.org"]
356 notifies :reload, "service[apache2]"
359 apache_site "nominatim.openstreetmap.org" do
360 template "apache.erb"
361 directory build_directory
362 variables :pools => node[:nominatim][:fpm_pools]
363 only_if { node[:nominatim][:state] != "off" }
366 apache_site "default" do
370 template "/etc/logrotate.d/apache2" do
371 source "logrotate.apache.erb"
377 include_recipe "fail2ban"
379 munin_plugin_conf "nominatim" do
381 variables :db => node[:nominatim][:dbname],
382 :querylog => "#{node[:nominatim][:logdir]}/query.log"
385 munin_plugin "nominatim_importlag" do
386 target "#{source_directory}/munin/nominatim_importlag"
389 munin_plugin "nominatim_query_speed" do
390 target "#{source_directory}/munin/nominatim_query_speed_querylog"
393 munin_plugin "nominatim_requests" do
394 target "#{source_directory}/munin/nominatim_requests_querylog"
397 munin_plugin "nominatim_throttled_ips" do
398 target "#{source_directory}/munin/nominatim_throttled_ips"
401 directory "#{basedir}/status" do