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" # ~FC023
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
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] # ~FC023
212 directory File.dirname(node[:nominatim][:flatnode_file]) do
217 template "/etc/logrotate.d/nominatim" do
218 source "logrotate.nominatim.erb"
225 "wikipedia_article.sql.bin",
226 "wikipedia_redirect.sql.bin",
227 "gb_postcode_data.sql.gz"
230 external_data.each do |fname|
231 remote_file "#{source_directory}/data/#{fname}" do
232 action :create_if_missing
233 source "https://www.nominatim.org/data/#{fname}"
240 remote_file "#{source_directory}/data/country_osm_grid.sql.gz" do
241 action :create_if_missing
242 source "https://www.nominatim.org/data/country_grid.sql.gz"
248 template "/etc/cron.d/nominatim" do
249 action node[:nominatim][:state] == "off" ? :delete : :create
250 source "nominatim.cron.erb"
254 variables :bin_directory => "#{source_directory}/utils",
255 :mailto => email_errors,
256 :update_maintenance_trigger => "#{basedir}/status/update_maintenance"
259 template "#{source_directory}/utils/nominatim-update" do
264 variables :bindir => build_directory,
265 :srcdir => source_directory,
266 :logfile => "#{node[:nominatim][:logdir]}/update.log",
267 :branch => node[:nominatim][:revision],
268 :update_stop_file => "#{basedir}/status/updates_disabled",
269 :update_maintenance_trigger => "#{basedir}/status/update_maintenance"
272 template "/etc/init.d/nominatim-update" do
273 source "updater.init.erb"
277 variables :source_directory => source_directory
280 %w[backup-nominatim vacuum-db-nominatim].each do |fname|
281 template "/usr/local/bin/#{fname}" do
282 source "#{fname}.erb"
286 variables :db => node[:nominatim][:dbname]
290 ## webserver frontend
292 template "#{build_directory}/settings/ip_blocks.conf" do
293 action :create_if_missing
294 source "ipblocks.erb"
300 file "#{build_directory}/settings/apache_blocks.conf" do
301 action :create_if_missing
307 file "#{build_directory}/settings/ip_blocks.map" do
308 action :create_if_missing
314 include_recipe "apache"
321 apache_module "rewrite"
322 apache_module "proxy"
323 apache_module "proxy_fcgi"
324 apache_module "proxy_http"
325 apache_module "headers"
327 service "php7.2-fpm" do
328 action [:enable, :start]
329 supports :status => true, :restart => true, :reload => true
332 node[:nominatim][:fpm_pools].each do |name, data|
333 template "/etc/php/7.2/fpm/pool.d/#{name}.conf" do
334 source "fpm.conf.erb"
338 variables data.merge(:name => name)
339 notifies :reload, "service[php7.2-fpm]"
343 ssl_certificate "nominatim.openstreetmap.org" do
344 domains ["nominatim.openstreetmap.org",
346 "nominatim.openstreetmap.com",
347 "nominatim.openstreetmap.net",
348 "nominatim.openstreetmaps.org",
349 "nominatim.openmaps.org"]
350 notifies :reload, "service[apache2]"
353 apache_site "nominatim.openstreetmap.org" do
354 template "apache.erb"
355 directory build_directory
356 variables :pools => node[:nominatim][:fpm_pools]
357 only_if { node[:nominatim][:state] != "off" }
360 apache_site "default" do
364 template "/etc/logrotate.d/apache2" do
365 source "logrotate.apache.erb"
371 include_recipe "fail2ban"
373 munin_plugin_conf "nominatim" do
375 variables :db => node[:nominatim][:dbname],
376 :querylog => "#{node[:nominatim][:logdir]}/query.log"
379 munin_plugin "nominatim_importlag" do
380 target "#{source_directory}/munin/nominatim_importlag"
383 munin_plugin "nominatim_query_speed" do
384 target "#{source_directory}/munin/nominatim_query_speed_querylog"
387 munin_plugin "nominatim_requests" do
388 target "#{source_directory}/munin/nominatim_requests_querylog"
391 munin_plugin "nominatim_throttled_ips" do
392 target "#{source_directory}/munin/nominatim_throttled_ips"
395 directory "#{basedir}/status" do