2 # Cookbook Name:: nominatim
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 # http://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
58 package "postgresql-#{postgresql_version}-postgis-2.3"
60 node[:nominatim][:dbadmins].each do |user|
61 postgresql_user user do
62 cluster node[:nominatim][:dbcluster]
64 only_if { node[:nominatim][:state] != "slave" }
68 postgresql_user "nominatim" do
69 cluster node[:nominatim][:dbcluster]
71 only_if { node[:nominatim][:state] != "slave" }
74 postgresql_user "www-data" do
75 cluster node[:nominatim][:dbcluster]
76 only_if { node[:nominatim][:state] != "slave" }
79 postgresql_munin "nominatim" do
80 cluster node[:nominatim][:dbcluster]
81 database node[:nominatim][:dbname]
84 directory "#{basedir}/tablespaces" do
90 # Note: tablespaces must be exactly in the same location on each
91 # Nominatim instance when replication is in use. Therefore
92 # use symlinks to canonical directory locations.
93 node[:nominatim][:tablespaces].each do |name, location|
101 link "#{basedir}/tablespaces/#{name}" do
105 postgresql_tablespace name do
106 cluster node[:nominatim][:dbcluster]
107 location "#{basedir}/tablespaces/#{name}"
111 if node[:nominatim][:state] == "master" # ~FC023
112 postgresql_user "replication" do
113 cluster node[:nominatim][:dbcluster]
114 password data_bag_item("nominatim", "passwords")["replication"]
118 directory node[:rsyncd][:modules][:archive][:path] do
124 template "/usr/local/bin/clean-db-nominatim" do
125 source "clean-db-nominatim.erb"
129 variables :archive_dir => node[:rsyncd][:modules][:archive][:path],
130 :update_stop_file => "#{basedir}/status/updates_disabled",
131 :streaming_clients => search(:node, "nominatim_state:slave").map { |slave| slave[:fqdn] }.join(" ")
138 include_recipe "python"
140 package "build-essential"
143 package "libboost-dev"
144 package "libboost-system-dev"
145 package "libboost-filesystem-dev"
146 package "libboost-python-dev"
147 package "libexpat1-dev"
149 package "libxml2-dev"
152 package "libgeos++-dev"
153 package "libproj-dev"
156 python_package "osmium"
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] # ~FC023
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 "http://www.nominatim.org/data/#{fname}"
241 remote_file "#{source_directory}/data/country_osm_grid.sql.gz" do
242 action :create_if_missing
243 source "http://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"
324 apache_module "rewrite"
325 apache_module "proxy"
326 apache_module "proxy_fcgi"
327 apache_module "proxy_http"
328 apache_module "headers"
330 service "php7.0-fpm" do
331 action [:enable, :start]
332 supports :status => true, :restart => true, :reload => true
335 node[:nominatim][:fpm_pools].each do |name, data|
336 template "/etc/php/7.0/fpm/pool.d/#{name}.conf" do
337 source "fpm.conf.erb"
341 variables data.merge(:name => name)
342 notifies :reload, "service[php7.0-fpm]"
346 ssl_certificate "nominatim.openstreetmap.org" do
347 domains ["nominatim.openstreetmap.org",
349 "nominatim.openstreetmap.com",
350 "nominatim.openstreetmap.net",
351 "nominatim.openstreetmaps.org",
352 "nominatim.openmaps.org"]
353 notifies :reload, "service[apache2]"
356 apache_site "nominatim.openstreetmap.org" do
357 template "apache.erb"
358 directory build_directory
359 variables :pools => node[:nominatim][:fpm_pools]
362 apache_site "default" do
366 template "/etc/logrotate.d/apache2" do
367 source "logrotate.apache.erb"
373 include_recipe "fail2ban"
375 fail2ban_filter "nominatim" do
376 failregex "Warning ignored: <HOST>"
379 fail2ban_jail "nominatim" do
381 logpath "#{node[:nominatim][:logdir]}/restricted_ips.log"
386 munin_plugin_conf "nominatim" do
388 variables :db => node[:nominatim][:dbname],
389 :querylog => "#{node[:nominatim][:logdir]}/query.log"
392 munin_plugin "nominatim_importlag" do
393 target "#{source_directory}/munin/nominatim_importlag"
396 munin_plugin "nominatim_query_speed" do
397 target "#{source_directory}/munin/nominatim_query_speed_querylog"
400 munin_plugin "nominatim_requests" do
401 target "#{source_directory}/munin/nominatim_requests_querylog"
404 munin_plugin "nominatim_throttled_ips" do
405 target "#{source_directory}/munin/nominatim_throttled_ips"
408 directory "#{basedir}/status" do