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 "accounts"
21 include_recipe "munin"
22 include_recipe "php::fpm"
24 basedir = data_bag_item("accounts", "nominatim")["home"]
25 email_errors = data_bag_item("accounts", "lonvia")["email"]
34 directory node[:nominatim][:logdir] do
41 file "#{node[:nominatim][:logdir]}/query.log" do
42 action :create_if_missing
48 file "#{node[:nominatim][:logdir]}/update.log" do
49 action :create_if_missing
55 # exception granted for a limited time so that they can set up their own server
56 firewall_rule "increase-limits-gnome-proxy" do
59 source "net:8.43.85.23"
63 rate_limit "s:10/sec:30"
68 include_recipe "postgresql"
70 postgresql_version = node[:nominatim][:dbcluster].split("/").first
71 postgis_version = node[:nominatim][:postgis]
73 package "postgresql-#{postgresql_version}-postgis-#{postgis_version}"
75 node[:nominatim][:dbadmins].each do |user|
76 postgresql_user user do
77 cluster node[:nominatim][:dbcluster]
79 only_if { node[:nominatim][:state] != "slave" }
83 postgresql_user "nominatim" do
84 cluster node[:nominatim][:dbcluster]
86 only_if { node[:nominatim][:state] != "slave" }
89 postgresql_user "www-data" do
90 cluster node[:nominatim][:dbcluster]
91 only_if { node[:nominatim][:state] != "slave" }
94 postgresql_munin "nominatim" do
95 cluster node[:nominatim][:dbcluster]
96 database node[:nominatim][:dbname]
99 directory "#{basedir}/tablespaces" do
105 # NOTE: tablespaces must be exactly in the same location on each
106 # Nominatim instance when replication is in use. Therefore
107 # use symlinks to canonical directory locations.
108 node[:nominatim][:tablespaces].each do |name, location|
109 directory location do
116 link "#{basedir}/tablespaces/#{name}" do
120 postgresql_tablespace name do
121 cluster node[:nominatim][:dbcluster]
122 location "#{basedir}/tablespaces/#{name}"
126 if node[:nominatim][:state] == "master"
127 postgresql_user "replication" do
128 cluster node[:nominatim][:dbcluster]
129 password data_bag_item("nominatim", "passwords")["replication"]
133 directory node[:rsyncd][:modules][:archive][:path] do
139 template "/usr/local/bin/clean-db-nominatim" do
140 source "clean-db-nominatim.erb"
144 variables :archive_dir => node[:rsyncd][:modules][:archive][:path],
145 :update_stop_file => "#{basedir}/status/updates_disabled",
146 :streaming_clients => search(:node, "nominatim_state:slave").map { |slave| slave[:fqdn] }.join(" ")
160 libboost-filesystem-dev
180 source_directory = "#{basedir}/nominatim"
181 build_directory = "#{basedir}/bin"
182 ui_directory = "#{basedir}/ui"
183 qa_bin_directory = "#{basedir}/Nominatim-Data-Analyser"
184 qa_data_directory = "#{basedir}/qa-data"
186 directory build_directory do
193 # Normally syncing via chef is a bad idea because syncing might involve
194 # an update of database functions which should not be done while an update
195 # is ongoing. Therefore we sync in between update cycles. There is an
196 # exception for slaves: they get DB function updates from the master, so
197 # only the source code needs to be updated, which chef may do.
198 git source_directory do
199 action node[:nominatim][:state] == "slave" ? :sync : :checkout
200 repository node[:nominatim][:repository]
201 revision node[:nominatim][:revision]
202 enable_submodules true
205 not_if { node[:nominatim][:state] != "slave" && File.exist?("#{source_directory}/README.md") }
206 notifies :run, "execute[compile_nominatim]"
209 remote_file "#{source_directory}/data/country_osm_grid.sql.gz" do
210 action :create_if_missing
211 source "https://www.nominatim.org/data/country_grid.sql.gz"
217 execute "compile_nominatim" do
221 command "cmake #{source_directory} && make"
224 template "#{source_directory}/.git/hooks/post-merge" do
225 source "git-post-merge-hook.erb"
229 variables :srcdir => source_directory,
230 :builddir => build_directory,
231 :dbname => node[:nominatim][:dbname]
234 template "#{build_directory}/.env" do
235 source "nominatim.env.erb"
239 variables :base_url => node[:nominatim][:state] == "off" ? node[:fqdn] : "nominatim.openstreetmap.org",
240 :dbname => node[:nominatim][:dbname],
241 :flatnode_file => node[:nominatim][:flatnode_file],
242 :log_file => "#{node[:nominatim][:logdir]}/query.log",
243 :tokenizer => node[:nominatim][:config][:tokenizer]
248 repository node[:nominatim][:ui_repository]
249 revision node[:nominatim][:ui_revision]
254 template "#{ui_directory}/dist/theme/config.theme.js" do
255 source "ui-config.js.erb"
261 if node[:nominatim][:flatnode_file]
262 directory File.dirname(node[:nominatim][:flatnode_file]) do
267 template "/etc/logrotate.d/nominatim" do
268 source "logrotate.nominatim.erb"
275 "wikimedia-importance.sql.gz",
276 "gb_postcodes.csv.gz",
277 "us_postcodes.csv.gz"
280 external_data.each do |fname|
281 remote_file "#{build_directory}/#{fname}" do
282 action :create_if_missing
283 source "https://www.nominatim.org/data/#{fname}"
290 if node[:nominatim][:state] == "off"
291 cron_d "nominatim-backup" do
295 cron_d "nominatim-vacuum-db" do
299 cron_d "nominatim-clean-db" do
303 cron_d "nominatim-update-maintenance-trigger" do
307 cron_d "nominatim-backup" do
308 action node[:nominatim][:enable_backup] ? :create : :delete
313 command "/usr/local/bin/backup-nominatim"
317 cron_d "nominatim-vacuum-db" do
321 command "/usr/local/bin/vacuum-db-nominatim"
325 cron_d "nominatim-clean-db" do
326 action node[:nominatim][:state] == "master" ? :create : :delete
330 command "/usr/local/bin/clean-db-nominatim"
334 cron_d "nominatim-update-maintenance-trigger" do
338 command "touch #{basedir}/status/update_maintenance"
343 template "#{source_directory}/utils/nominatim-update" do
348 variables :bindir => build_directory,
349 :srcdir => source_directory,
350 :logfile => "#{node[:nominatim][:logdir]}/update.log",
351 :branch => node[:nominatim][:revision],
352 :update_stop_file => "#{basedir}/status/updates_disabled",
353 :update_maintenance_trigger => "#{basedir}/status/update_maintenance",
354 :qabindir => qa_bin_directory,
355 :qadatadir => qa_data_directory
358 template "/etc/init.d/nominatim-update" do
359 source "updater.init.erb"
363 variables :source_directory => source_directory
366 %w[backup-nominatim vacuum-db-nominatim].each do |fname|
367 template "/usr/local/bin/#{fname}" do
368 source "#{fname}.erb"
372 variables :db => node[:nominatim][:dbname]
376 ## webserver frontend
378 directory "#{basedir}/etc" do
384 %w[user_agent referrer email generic].each do |name|
385 file "#{basedir}/etc/nginx_blocked_#{name}.conf" do
386 action :create_if_missing
393 node[:nominatim][:fpm_pools].each do |name, data|
397 pm_max_children data[:max_children]
399 pm_min_spare_servers 10
400 pm_max_spare_servers 20
401 pm_max_requests 10000
402 prometheus_port data[:prometheus_port]
406 ssl_certificate node[:fqdn] do
407 domains [node[:fqdn],
408 "nominatim.openstreetmap.org",
410 "nominatim.openstreetmap.com",
411 "nominatim.openstreetmap.net",
412 "nominatim.openstreetmaps.org",
413 "nominatim.openmaps.org",
414 "nominatim.qgis.org"]
415 notifies :reload, "service[nginx]"
422 include_recipe "nginx"
424 nginx_site "default" do
428 frontends = search(:node, "recipes:web\\:\\:frontend").sort_by(&:name)
430 nginx_site "nominatim" do
432 directory build_directory
433 variables :pools => node[:nominatim][:fpm_pools],
434 :frontends => frontends,
435 :confdir => "#{basedir}/etc",
436 :ui_directory => ui_directory
439 template "/etc/logrotate.d/nginx" do
440 source "logrotate.nginx.erb"
446 munin_plugin_conf "nominatim" do
448 variables :db => node[:nominatim][:dbname],
449 :querylog => "#{node[:nominatim][:logdir]}/query.log"
452 munin_plugin "nominatim_importlag" do
453 target "#{source_directory}/munin/nominatim_importlag"
456 munin_plugin "nominatim_query_speed" do
457 target "#{source_directory}/munin/nominatim_query_speed_querylog"
460 munin_plugin "nominatim_requests" do
461 target "#{source_directory}/munin/nominatim_requests_querylog"
464 directory "#{basedir}/status" do
470 include_recipe "fail2ban"
472 frontend_addresses = frontends.collect { |f| f.ipaddresses(:role => :external) }
474 fail2ban_jail "nominatim_limit_req" do
475 filter "nginx-limit-req"
476 logpath "#{node[:nominatim][:logdir]}/nominatim.openstreetmap.org-error.log"
479 ignoreips frontend_addresses.flatten.sort
482 ### QA tile generation
484 if node[:nominatim][:enable_qa_tiles]
485 git qa_bin_directory do
486 repository node[:nominatim][:qa_repository]
487 revision node[:nominatim][:qa_revision]
488 enable_submodules true
491 notifies :run, "execute[compile_qa]"
494 execute "compile_qa" do
497 cwd "#{qa_bin_directory}/clustering-vt"
501 directory qa_data_directory do
508 template "#{qa_bin_directory}/analyser/config/config.yaml" do
509 source "qa_config.erb"
513 variables :outputdir => "#{qa_data_directory}/new"
516 link "#{build_directory}/website/qa-data" do
517 to "#{qa_data_directory}/current"