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 include_recipe "munin"
22 basedir = data_bag_item("accounts", "nominatim")["home"]
23 email_errors = data_bag_item("accounts", "lonvia")["email"]
32 directory node[:nominatim][:logdir] do
39 file "#{node[:nominatim][:logdir]}/query.log" do
40 action :create_if_missing
46 file "#{node[:nominatim][:logdir]}/update.log" do
47 action :create_if_missing
53 # exception granted for a limited time so that they can set up their own server
54 firewall_rule "increase-limits-gnome-proxy" do
56 source "net:8.43.85.23"
60 rate_limit "s:10/sec:30"
65 include_recipe "postgresql"
67 postgresql_version = node[:nominatim][:dbcluster].split("/").first
68 postgis_version = node[:nominatim][:postgis]
70 package "postgresql-#{postgresql_version}-postgis-#{postgis_version}"
72 node[:nominatim][:dbadmins].each do |user|
73 postgresql_user user do
74 cluster node[:nominatim][:dbcluster]
76 only_if { node[:nominatim][:state] != "slave" }
80 postgresql_user "nominatim" do
81 cluster node[:nominatim][:dbcluster]
83 only_if { node[:nominatim][:state] != "slave" }
86 postgresql_user "www-data" do
87 cluster node[:nominatim][:dbcluster]
88 only_if { node[:nominatim][:state] != "slave" }
91 postgresql_munin "nominatim" do
92 cluster node[:nominatim][:dbcluster]
93 database node[:nominatim][:dbname]
96 directory "#{basedir}/tablespaces" do
102 # Note: tablespaces must be exactly in the same location on each
103 # Nominatim instance when replication is in use. Therefore
104 # use symlinks to canonical directory locations.
105 node[:nominatim][:tablespaces].each do |name, location|
106 directory location do
113 link "#{basedir}/tablespaces/#{name}" do
117 postgresql_tablespace name do
118 cluster node[:nominatim][:dbcluster]
119 location "#{basedir}/tablespaces/#{name}"
123 if node[:nominatim][:state] == "master"
124 postgresql_user "replication" do
125 cluster node[:nominatim][:dbcluster]
126 password data_bag_item("nominatim", "passwords")["replication"]
130 directory node[:rsyncd][:modules][:archive][:path] do
136 template "/usr/local/bin/clean-db-nominatim" do
137 source "clean-db-nominatim.erb"
141 variables :archive_dir => node[:rsyncd][:modules][:archive][:path],
142 :update_stop_file => "#{basedir}/status/updates_disabled",
143 :streaming_clients => search(:node, "nominatim_state:slave").map { |slave| slave[:fqdn] }.join(" ")
157 libboost-filesystem-dev
170 source_directory = "#{basedir}/nominatim"
171 build_directory = "#{basedir}/bin"
173 directory build_directory do
180 # Normally syncing via chef is a bad idea because syncing might involve
181 # an update of database functions which should not be done while an update
182 # is ongoing. Therefore we sync in between update cycles. There is an
183 # exception for slaves: they get DB function updates from the master, so
184 # only the source code needs to be updated, which chef may do.
185 git source_directory do
186 action node[:nominatim][:state] == "slave" ? :sync : :checkout
187 repository node[:nominatim][:repository]
188 revision node[:nominatim][:revision]
189 enable_submodules true
192 not_if { node[:nominatim][:state] != "slave" && File.exist?("#{source_directory}/README.md") }
193 notifies :run, "execute[compile_nominatim]", :immediately
196 execute "compile_nominatim" do
200 command "cmake #{source_directory} && make"
203 template "#{source_directory}/.git/hooks/post-merge" do
204 source "git-post-merge-hook.erb"
208 variables :srcdir => source_directory,
209 :builddir => build_directory,
210 :dbname => node[:nominatim][:dbname]
213 template "#{build_directory}/settings/local.php" do
214 source "settings.erb"
218 variables :base_url => node[:nominatim][:state] == "off" ? node[:fqdn] : "nominatim.openstreetmap.org",
219 :dbname => node[:nominatim][:dbname],
220 :flatnode_file => node[:nominatim][:flatnode_file],
221 :log_file => "#{node[:nominatim][:logdir]}/query.log"
224 if node[:nominatim][:flatnode_file]
225 directory File.dirname(node[:nominatim][:flatnode_file]) do
230 template "/etc/logrotate.d/nominatim" do
231 source "logrotate.nominatim.erb"
238 "wikimedia-importance.sql.gz",
239 "gb_postcode_data.sql.gz"
242 external_data.each do |fname|
243 remote_file "#{source_directory}/data/#{fname}" do
244 action :create_if_missing
245 source "https://www.nominatim.org/data/#{fname}"
252 remote_file "#{source_directory}/data/country_osm_grid.sql.gz" do
253 action :create_if_missing
254 source "https://www.nominatim.org/data/country_grid.sql.gz"
260 template "/etc/cron.d/nominatim" do
261 action node[:nominatim][:state] == "off" ? :delete : :create
262 source "nominatim.cron.erb"
266 variables :bin_directory => "#{source_directory}/utils",
267 :mailto => email_errors,
268 :update_maintenance_trigger => "#{basedir}/status/update_maintenance"
271 template "#{source_directory}/utils/nominatim-update" do
276 variables :bindir => build_directory,
277 :srcdir => source_directory,
278 :logfile => "#{node[:nominatim][:logdir]}/update.log",
279 :branch => node[:nominatim][:revision],
280 :update_stop_file => "#{basedir}/status/updates_disabled",
281 :update_maintenance_trigger => "#{basedir}/status/update_maintenance"
284 template "/etc/init.d/nominatim-update" do
285 source "updater.init.erb"
289 variables :source_directory => source_directory
292 %w[backup-nominatim vacuum-db-nominatim].each do |fname|
293 template "/usr/local/bin/#{fname}" do
294 source "#{fname}.erb"
298 variables :db => node[:nominatim][:dbname]
302 ## webserver frontend
304 template "#{build_directory}/settings/ip_blocks.conf" do
305 action :create_if_missing
306 source "ipblocks.erb"
312 file "#{build_directory}/settings/apache_blocks.conf" do
313 action :create_if_missing
319 file "#{build_directory}/settings/ip_blocks.map" do
320 action :create_if_missing
326 include_recipe "apache"
333 apache_module "rewrite"
334 apache_module "proxy"
335 apache_module "proxy_fcgi"
336 apache_module "proxy_http"
337 apache_module "headers"
339 service "php7.2-fpm" do
340 action [:enable, :start]
341 supports :status => true, :restart => true, :reload => true
344 node[:nominatim][:fpm_pools].each do |name, data|
345 template "/etc/php/7.2/fpm/pool.d/#{name}.conf" do
346 source "fpm.conf.erb"
350 variables data.merge(:name => name)
351 notifies :reload, "service[php7.2-fpm]"
355 systemd_service "apache-nominatim" do
359 notifies :restart, "service[apache2]"
362 ssl_certificate "nominatim.openstreetmap.org" do
363 domains ["nominatim.openstreetmap.org",
365 "nominatim.openstreetmap.com",
366 "nominatim.openstreetmap.net",
367 "nominatim.openstreetmaps.org",
368 "nominatim.openmaps.org"]
369 notifies :reload, "service[apache2]"
372 apache_site "nominatim.openstreetmap.org" do
373 template "apache.erb"
374 directory build_directory
375 variables :pools => node[:nominatim][:fpm_pools]
376 only_if { node[:nominatim][:state] != "off" }
379 apache_site "default" do
383 template "/etc/logrotate.d/apache2" do
384 source "logrotate.apache.erb"
390 include_recipe "fail2ban"
392 munin_plugin_conf "nominatim" do
394 variables :db => node[:nominatim][:dbname],
395 :querylog => "#{node[:nominatim][:logdir]}/query.log"
398 munin_plugin "nominatim_importlag" do
399 target "#{source_directory}/munin/nominatim_importlag"
402 munin_plugin "nominatim_query_speed" do
403 target "#{source_directory}/munin/nominatim_query_speed_querylog"
406 munin_plugin "nominatim_requests" do
407 target "#{source_directory}/munin/nominatim_requests_querylog"
410 munin_plugin "nominatim_throttled_ips" do
411 target "#{source_directory}/munin/nominatim_throttled_ips"
414 directory "#{basedir}/status" do