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"
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
158 source_directory = "#{basedir}/nominatim"
159 build_directory = "#{basedir}/bin"
161 directory build_directory do
168 # Normally syncing via chef is a bad idea because syncing might involve
169 # an update of database functions which should not be done while an update
170 # is ongoing. Therefore we sync in between update cycles. There is an
171 # exception for slaves: they get DB function updates from the master, so
172 # only the source code needs to be updated, which chef may do.
173 git source_directory do
174 action node[:nominatim][:state] == "slave" ? :sync : :checkout
175 repository node[:nominatim][:repository]
176 revision node[:nominatim][:revision]
177 enable_submodules true
180 not_if { node[:nominatim][:state] != "slave" && File.exist?("#{source_directory}/README.md") }
181 notifies :run, "execute[compile_nominatim]", :immediately
184 execute "compile_nominatim" do
188 command "cmake #{source_directory} && make"
191 template "#{source_directory}/.git/hooks/post-merge" do
192 source "git-post-merge-hook.erb"
196 variables :srcdir => source_directory,
197 :builddir => build_directory,
198 :dbname => node[:nominatim][:dbname]
201 template "#{build_directory}/settings/local.php" do
202 source "settings.erb"
206 variables :base_url => node[:nominatim][:state] == "off" ? node[:fqdn] : "nominatim.openstreetmap.org",
207 :dbname => node[:nominatim][:dbname],
208 :flatnode_file => node[:nominatim][:flatnode_file],
209 :log_file => "#{node[:nominatim][:logdir]}/query.log"
212 if node[:nominatim][:flatnode_file]
213 directory File.dirname(node[:nominatim][:flatnode_file]) do
218 template "/etc/logrotate.d/nominatim" do
219 source "logrotate.nominatim.erb"
226 "wikipedia_article.sql.bin",
227 "wikipedia_redirect.sql.bin",
228 "gb_postcode_data.sql.gz"
231 external_data.each do |fname|
232 remote_file "#{source_directory}/data/#{fname}" do
233 action :create_if_missing
234 source "https://www.nominatim.org/data/#{fname}"
241 remote_file "#{source_directory}/data/country_osm_grid.sql.gz" do
242 action :create_if_missing
243 source "https://www.nominatim.org/data/country_grid.sql.gz"
249 template "/etc/cron.d/nominatim" do
250 action node[:nominatim][:state] == "off" ? :delete : :create
251 source "nominatim.cron.erb"
255 variables :bin_directory => "#{source_directory}/utils",
256 :mailto => email_errors,
257 :update_maintenance_trigger => "#{basedir}/status/update_maintenance"
260 template "#{source_directory}/utils/nominatim-update" do
265 variables :bindir => build_directory,
266 :srcdir => source_directory,
267 :logfile => "#{node[:nominatim][:logdir]}/update.log",
268 :branch => node[:nominatim][:revision],
269 :update_stop_file => "#{basedir}/status/updates_disabled",
270 :update_maintenance_trigger => "#{basedir}/status/update_maintenance"
273 template "/etc/init.d/nominatim-update" do
274 source "updater.init.erb"
278 variables :source_directory => source_directory
281 %w[backup-nominatim vacuum-db-nominatim].each do |fname|
282 template "/usr/local/bin/#{fname}" do
283 source "#{fname}.erb"
287 variables :db => node[:nominatim][:dbname]
291 ## webserver frontend
293 template "#{build_directory}/settings/ip_blocks.conf" do
294 action :create_if_missing
295 source "ipblocks.erb"
301 file "#{build_directory}/settings/apache_blocks.conf" do
302 action :create_if_missing
308 file "#{build_directory}/settings/ip_blocks.map" do
309 action :create_if_missing
315 include_recipe "apache"
322 apache_module "rewrite"
323 apache_module "proxy"
324 apache_module "proxy_fcgi"
325 apache_module "proxy_http"
326 apache_module "headers"
328 service "php7.2-fpm" do
329 action [:enable, :start]
330 supports :status => true, :restart => true, :reload => true
333 node[:nominatim][:fpm_pools].each do |name, data|
334 template "/etc/php/7.2/fpm/pool.d/#{name}.conf" do
335 source "fpm.conf.erb"
339 variables data.merge(:name => name)
340 notifies :reload, "service[php7.2-fpm]"
344 ssl_certificate "nominatim.openstreetmap.org" do
345 domains ["nominatim.openstreetmap.org",
347 "nominatim.openstreetmap.com",
348 "nominatim.openstreetmap.net",
349 "nominatim.openstreetmaps.org",
350 "nominatim.openmaps.org"]
351 notifies :reload, "service[apache2]"
354 apache_site "nominatim.openstreetmap.org" do
355 template "apache.erb"
356 directory build_directory
357 variables :pools => node[:nominatim][:fpm_pools]
358 only_if { node[:nominatim][:state] != "off" }
361 apache_site "default" do
365 template "/etc/logrotate.d/apache2" do
366 source "logrotate.apache.erb"
372 include_recipe "fail2ban"
374 munin_plugin_conf "nominatim" do
376 variables :db => node[:nominatim][:dbname],
377 :querylog => "#{node[:nominatim][:logdir]}/query.log"
380 munin_plugin "nominatim_importlag" do
381 target "#{source_directory}/munin/nominatim_importlag"
384 munin_plugin "nominatim_query_speed" do
385 target "#{source_directory}/munin/nominatim_query_speed_querylog"
388 munin_plugin "nominatim_requests" do
389 target "#{source_directory}/munin/nominatim_requests_querylog"
392 munin_plugin "nominatim_throttled_ips" do
393 target "#{source_directory}/munin/nominatim_throttled_ips"
396 directory "#{basedir}/status" do