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"
57 node[:nominatim][:dbadmins].each do |user|
58 postgresql_user user do
59 cluster node[:nominatim][:dbcluster]
61 only_if { node[:nominatim][:state] != "slave" }
65 postgresql_user "nominatim" do
66 cluster node[:nominatim][:dbcluster]
68 only_if { node[:nominatim][:state] != "slave" }
71 postgresql_user "www-data" do
72 cluster node[:nominatim][:dbcluster]
73 only_if { node[:nominatim][:state] != "slave" }
76 postgresql_munin "nominatim" do
77 cluster node[:nominatim][:dbcluster]
78 database node[:nominatim][:dbname]
81 directory "#{basedir}/tablespaces" do
87 # Note: tablespaces must be exactly in the same location on each
88 # Nominatim instance when replication is in use. Therefore
89 # use symlinks to canonical directory locations.
90 node[:nominatim][:tablespaces].each do |name, location|
98 link "#{basedir}/tablespaces/#{name}" do
102 postgresql_tablespace name do
103 cluster node[:nominatim][:dbcluster]
104 location "#{basedir}/tablespaces/#{name}"
108 if node[:nominatim][:state] == "master" # ~FC023
109 postgresql_user "replication" do
110 cluster node[:nominatim][:dbcluster]
111 password data_bag_item("nominatim", "passwords")["replication"]
115 directory node[:rsyncd][:modules][:archive][:path] do
121 template "/usr/local/bin/clean-db-nominatim" do
122 source "clean-db-nominatim.erb"
126 variables :archive_dir => node[:rsyncd][:modules][:archive][:path],
127 :update_stop_file => "#{basedir}/status/updates_disabled",
128 :streaming_clients => search(:node, "nominatim_state:slave").map { |slave| slave[:fqdn] }.join(" ")
135 include_recipe "python"
137 package "build-essential"
140 package "libboost-dev"
141 package "libboost-system-dev"
142 package "libboost-filesystem-dev"
143 package "libexpat1-dev"
145 package "libxml2-dev"
148 package "libgeos++-dev"
149 package "libproj-dev"
152 python_package "osmium"
154 source_directory = "#{basedir}/nominatim"
155 build_directory = "#{basedir}/bin"
157 directory build_directory do
164 # Normally syncing via chef is a bad idea because syncing might involve
165 # an update of database functions which should not be done while an update
166 # is ongoing. Therefore we sync in between update cycles. There is an
167 # exception for slaves: they get DB function updates from the master, so
168 # only the source code needs to be updated, which chef may do.
169 git source_directory do
170 action node[:nominatim][:state] == "slave" ? :sync : :checkout
171 repository node[:nominatim][:repository]
172 revision node[:nominatim][:revision]
173 enable_submodules true
176 notifies :run, "execute[compile_nominatim]", :immediately
179 execute "compile_nominatim" do
183 command "cmake #{source_directory} && make"
186 template "#{source_directory}/.git/hooks/post-merge" do
187 source "git-post-merge-hook.erb"
191 variables :srcdir => source_directory,
192 :builddir => build_directory,
193 :dbname => node[:nominatim][:dbname]
196 template "#{build_directory}/settings/local.php" do
197 source "settings.erb"
201 variables :base_url => node[:nominatim][:state] == "off" ? node[:fqdn] : "nominatim.openstreetmap.org",
202 :dbname => node[:nominatim][:dbname],
203 :flatnode_file => node[:nominatim][:flatnode_file],
204 :log_file => "#{node[:nominatim][:logdir]}/query.log"
207 if node[:nominatim][:flatnode_file] # ~FC023
208 directory File.dirname(node[:nominatim][:flatnode_file]) do
213 template "/etc/logrotate.d/nominatim" do
214 source "logrotate.nominatim.erb"
221 "wikipedia_article.sql.bin",
222 "wikipedia_redirect.sql.bin",
223 "gb_postcode_data.sql.gz"
226 external_data.each do |fname|
227 remote_file "#{source_directory}/data/#{fname}" do
228 action :create_if_missing
229 source "http://www.nominatim.org/data/#{fname}"
236 template "/etc/cron.d/nominatim" do
237 action node[:nominatim][:state] == :off ? :delete : :create
238 source "nominatim.cron.erb"
242 variables :bin_directory => "#{source_directory}/utils", :mailto => email_errors
245 template "#{source_directory}/utils/nominatim-update" do
250 variables :bindir => build_directory,
251 :srcdir => source_directory,
252 :logfile => "#{node[:nominatim][:logdir]}/update.log",
253 :branch => node[:nominatim][:revision],
254 :update_stop_file => "#{basedir}/status/updates_disabled"
257 template "/etc/init.d/nominatim-update" do
258 source "updater.init.erb"
262 variables :source_directory => source_directory
265 %w(backup-nominatim vacuum-db-nominatim).each do |fname|
266 template "/usr/local/bin/#{fname}" do
267 source "#{fname}.erb"
271 variables :db => node[:nominatim][:dbname]
275 ## webserver frontend
277 template "#{build_directory}/settings/ip_blocks.conf" do
278 action :create_if_missing
279 source "ipblocks.erb"
285 file "#{build_directory}/settings/apache_blocks.conf" do
286 action :create_if_missing
292 file "#{build_directory}/settings/ip_blocks.map" do
293 action :create_if_missing
299 include_recipe "apache"
307 apache_module "rewrite"
308 apache_module "proxy"
309 apache_module "proxy_fcgi"
310 apache_module "proxy_http"
311 apache_module "headers"
312 apache_module "reqtimeout"
314 service "php7.0-fpm" do
315 action [:enable, :start]
316 supports :status => true, :restart => true, :reload => true
319 node[:nominatim][:fpm_pools].each do |name, data|
320 template "/etc/php/7.0/fpm/pool.d/#{name}.conf" do
321 source "fpm.conf.erb"
325 variables data.merge(:name => name)
326 notifies :reload, "service[php7.0-fpm]"
330 ssl_certificate "nominatim.openstreetmap.org" do
331 domains ["nominatim.openstreetmap.org",
333 "nominatim.openstreetmap.com",
334 "nominatim.openstreetmap.net",
335 "nominatim.openstreetmaps.org",
336 "nominatim.openmaps.org"]
337 notifies :reload, "service[apache2]"
340 apache_site "nominatim.openstreetmap.org" do
341 template "apache.erb"
342 directory build_directory
343 variables :pools => node[:nominatim][:fpm_pools]
346 apache_site "default" do
350 template "/etc/logrotate.d/apache2" do
351 source "logrotate.apache.erb"
357 include_recipe "fail2ban"
359 web_servers = search(:node, "recipes:web\\:\\:frontend").collect do |n| # ~FC010
360 n.ipaddresses(:role => :external)
363 fail2ban_filter "nominatim" do
364 failregex '^<HOST> - - \[\] "[^"]+" (408|429) '
367 fail2ban_jail "nominatim" do
369 logpath "/var/log/apache2/nominatim.openstreetmap.org-access.log"
372 ignoreips web_servers
375 munin_plugin_conf "nominatim" do
377 variables :db => node[:nominatim][:dbname],
378 :querylog => "#{node[:nominatim][:logdir]}/query.log"
381 munin_plugin "nominatim_importlag" do
382 target "#{source_directory}/munin/nominatim_importlag"
385 munin_plugin "nominatim_query_speed" do
386 target "#{source_directory}/munin/nominatim_query_speed_querylog"
389 munin_plugin "nominatim_requests" do
390 target "#{source_directory}/munin/nominatim_requests_querylog"
393 munin_plugin "nominatim_throttled_ips" do
394 target "#{source_directory}/munin/nominatim_throttled_ips"
397 directory "#{basedir}/status" do