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
57 source "net:8.43.85.23"
61 rate_limit "s:10/sec:30"
66 include_recipe "postgresql"
68 postgresql_version = node[:nominatim][:dbcluster].split("/").first
69 postgis_version = node[:nominatim][:postgis]
71 package "postgresql-#{postgresql_version}-postgis-#{postgis_version}"
73 node[:nominatim][:dbadmins].each do |user|
74 postgresql_user user do
75 cluster node[:nominatim][:dbcluster]
77 only_if { node[:nominatim][:state] != "slave" }
81 postgresql_user "nominatim" do
82 cluster node[:nominatim][:dbcluster]
84 only_if { node[:nominatim][:state] != "slave" }
87 postgresql_user "www-data" do
88 cluster node[:nominatim][:dbcluster]
89 only_if { node[:nominatim][:state] != "slave" }
92 postgresql_munin "nominatim" do
93 cluster node[:nominatim][:dbcluster]
94 database node[:nominatim][:dbname]
97 directory "#{basedir}/tablespaces" do
103 # Note: tablespaces must be exactly in the same location on each
104 # Nominatim instance when replication is in use. Therefore
105 # use symlinks to canonical directory locations.
106 node[:nominatim][:tablespaces].each do |name, location|
107 directory location do
114 link "#{basedir}/tablespaces/#{name}" do
118 postgresql_tablespace name do
119 cluster node[:nominatim][:dbcluster]
120 location "#{basedir}/tablespaces/#{name}"
124 if node[:nominatim][:state] == "master"
125 postgresql_user "replication" do
126 cluster node[:nominatim][:dbcluster]
127 password data_bag_item("nominatim", "passwords")["replication"]
131 directory node[:rsyncd][:modules][:archive][:path] do
137 template "/usr/local/bin/clean-db-nominatim" do
138 source "clean-db-nominatim.erb"
142 variables :archive_dir => node[:rsyncd][:modules][:archive][:path],
143 :update_stop_file => "#{basedir}/status/updates_disabled",
144 :streaming_clients => search(:node, "nominatim_state:slave").map { |slave| slave[:fqdn] }.join(" ")
158 libboost-filesystem-dev
175 source_directory = "#{basedir}/nominatim"
176 build_directory = "#{basedir}/bin"
178 directory build_directory do
185 # Normally syncing via chef is a bad idea because syncing might involve
186 # an update of database functions which should not be done while an update
187 # is ongoing. Therefore we sync in between update cycles. There is an
188 # exception for slaves: they get DB function updates from the master, so
189 # only the source code needs to be updated, which chef may do.
190 git source_directory do
191 action node[:nominatim][:state] == "slave" ? :sync : :checkout
192 repository node[:nominatim][:repository]
193 revision node[:nominatim][:revision]
194 enable_submodules true
197 not_if { node[:nominatim][:state] != "slave" && File.exist?("#{source_directory}/README.md") }
198 notifies :run, "execute[compile_nominatim]", :immediately
201 execute "compile_nominatim" do
205 command "cmake #{source_directory} && make"
208 template "#{source_directory}/.git/hooks/post-merge" do
209 source "git-post-merge-hook.erb"
213 variables :srcdir => source_directory,
214 :builddir => build_directory,
215 :dbname => node[:nominatim][:dbname]
218 template "#{build_directory}/settings/local.php" do
219 source "settings.erb"
223 variables :base_url => node[:nominatim][:state] == "off" ? node[:fqdn] : "nominatim.openstreetmap.org",
224 :dbname => node[:nominatim][:dbname],
225 :flatnode_file => node[:nominatim][:flatnode_file],
226 :log_file => "#{node[:nominatim][:logdir]}/query.log"
229 if node[:nominatim][:flatnode_file]
230 directory File.dirname(node[:nominatim][:flatnode_file]) do
235 template "/etc/logrotate.d/nominatim" do
236 source "logrotate.nominatim.erb"
243 "wikimedia-importance.sql.gz",
244 "gb_postcode_data.sql.gz"
247 external_data.each do |fname|
248 remote_file "#{source_directory}/data/#{fname}" do
249 action :create_if_missing
250 source "https://www.nominatim.org/data/#{fname}"
257 remote_file "#{source_directory}/data/country_osm_grid.sql.gz" do
258 action :create_if_missing
259 source "https://www.nominatim.org/data/country_grid.sql.gz"
265 template "/etc/cron.d/nominatim" do
266 action node[:nominatim][:state] == "off" ? :delete : :create
267 source "nominatim.cron.erb"
271 variables :bin_directory => "#{source_directory}/utils",
272 :mailto => email_errors,
273 :update_maintenance_trigger => "#{basedir}/status/update_maintenance"
276 template "#{source_directory}/utils/nominatim-update" do
281 variables :bindir => build_directory,
282 :srcdir => source_directory,
283 :logfile => "#{node[:nominatim][:logdir]}/update.log",
284 :branch => node[:nominatim][:revision],
285 :update_stop_file => "#{basedir}/status/updates_disabled",
286 :update_maintenance_trigger => "#{basedir}/status/update_maintenance"
289 template "/etc/init.d/nominatim-update" do
290 source "updater.init.erb"
294 variables :source_directory => source_directory
297 %w[backup-nominatim vacuum-db-nominatim].each do |fname|
298 template "/usr/local/bin/#{fname}" do
299 source "#{fname}.erb"
303 variables :db => node[:nominatim][:dbname]
307 ## webserver frontend
309 directory "#{basedir}/etc" do
315 file "#{basedir}/etc/nginx_blocked_user_agent.conf" do
316 action :create_if_missing
322 file "#{basedir}/etc/nginx_blocked_referrer.conf" do
323 action :create_if_missing
329 service "php7.2-fpm" do
330 action [:enable, :start]
331 supports :status => true, :restart => true, :reload => true
334 node[:nominatim][:fpm_pools].each do |name, data|
335 template "/etc/php/7.2/fpm/pool.d/#{name}.conf" do
336 source "fpm.conf.erb"
340 variables data.merge(:name => name)
341 notifies :reload, "service[php7.2-fpm]"
345 ssl_certificate node[:fqdn] do
346 domains [node[:fqdn],
347 "nominatim.openstreetmap.org",
349 "nominatim.openstreetmap.com",
350 "nominatim.openstreetmap.net",
351 "nominatim.openstreetmaps.org",
352 "nominatim.openmaps.org"]
353 notifies :reload, "service[nginx]"
360 include_recipe "nginx"
362 nginx_site "default" do
366 nginx_site "nominatim" do
368 directory build_directory
369 variables :pools => node[:nominatim][:fpm_pools],
370 :frontends => search(:node, "recipes:web\\:\\:frontend"),
371 :confdir => "#{basedir}/etc"
374 template "/etc/logrotate.d/nginx" do
375 source "logrotate.nginx.erb"
381 munin_plugin_conf "nominatim" do
383 variables :db => node[:nominatim][:dbname],
384 :querylog => "#{node[:nominatim][:logdir]}/query.log"
387 munin_plugin "nominatim_importlag" do
388 target "#{source_directory}/munin/nominatim_importlag"
391 munin_plugin "nominatim_query_speed" do
392 target "#{source_directory}/munin/nominatim_query_speed_querylog"
395 munin_plugin "nominatim_requests" do
396 target "#{source_directory}/munin/nominatim_requests_querylog"
399 directory "#{basedir}/status" do
405 include_recipe "fail2ban"
407 fail2ban_jail "nominatim_limit_req" do
408 filter "nginx-limit-req"
409 logpath "#{node[:nominatim][:logdir]}/nominatim.openstreetmap.org-error.log"