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"]
23 directory node[:nominatim][:logdir] do
30 file "#{node[:nominatim][:logdir]}/query.log" do
31 action :create_if_missing
37 file "#{node[:nominatim][:logdir]}/update.log" do
38 action :create_if_missing
44 directory "#{basedir}/status" do
52 include_recipe "postgresql"
56 node[:nominatim][:dbadmins].each do |user|
57 postgresql_user user do
58 cluster node[:nominatim][:dbcluster]
60 only_if { node[:nominatim][:state] != "slave" }
64 postgresql_user "nominatim" do
65 cluster node[:nominatim][:dbcluster]
67 only_if { node[:nominatim][:state] != "slave" }
70 postgresql_user "www-data" do
71 cluster node[:nominatim][:dbcluster]
72 only_if { node[:nominatim][:state] != "slave" }
75 postgresql_munin "nominatim" do
76 cluster node[:nominatim][:dbcluster]
77 database node[:nominatim][:dbname]
80 directory "#{basedir}/tablespaces" do
86 # Note: tablespaces must be exactly in the same location on each
87 # Nominatim instance when replication is in use. Therefore
88 # use symlinks to canonical directory locations.
89 node[:nominatim][:tablespaces].each do |name, location|
97 link "#{basedir}/tablespaces/#{name}" do
101 postgresql_tablespace name do
102 cluster node[:nominatim][:dbcluster]
103 location "#{basedir}/tablespaces/#{name}"
107 if node[:nominatim][:state] == "master" # ~FC023
108 postgresql_user "replication" do
109 cluster node[:nominatim][:dbcluster]
110 password data_bag_item("nominatim", "passwords")["replication"]
114 directory node[:rsyncd][:modules][:archive][:path] do
120 template "/usr/local/bin/clean-db-nominatim" do
121 source "clean-db-nominatim.erb"
125 variables :archive_dir => node[:rsyncd][:modules][:archive][:path],
126 :update_stop_file => "#{basedir}/status/updates_disabled",
127 :streaming_clients => search(:node, "nominatim_state:slave").map { |slave| slave[:fqdn] }.join(" ")
135 package "build-essential"
138 package "libboost-dev"
139 package "libboost-system-dev"
140 package "libboost-filesystem-dev"
141 package "libexpat1-dev"
143 package "libxml2-dev"
146 package "libgeos++-dev"
147 package "libproj-dev"
150 source_directory = "#{basedir}/nominatim"
151 build_directory = "#{basedir}/bin"
153 directory build_directory do
160 # Normally syncing via chef is a bad idea because syncing might involve
161 # an update of database functions which should not be done while an update
162 # is ongoing. Therefore we sync in between update cycles. There is an
163 # exception for slaves: they get DB function updates from the master, so
164 # only the source code needs to be updated, which chef may do.
165 git source_directory do
166 action node[:nominatim][:state] == "slave" ? :sync : :checkout
167 repository node[:nominatim][:repository]
168 revision node[:nominatim][:revision]
169 enable_submodules true
172 notifies :run, "execute[compile_nominatim]", :immediately
175 execute "compile_nominatim" do
179 command "cmake #{source_directory} && make"
182 template "#{source_directory}/.git/hooks/post-merge" do
183 source "git-post-merge-hook.erb"
187 variables :srcdir => source_directory,
188 :builddir => build_directory,
189 :dbname => node[:nominatim][:dbname]
192 template "#{build_directory}/settings/local.php" do
193 source "settings.erb"
197 variables :base_url => node[:nominatim][:state] == "off" ? node[:fqdn] : "nominatim.openstreetmap.org",
198 :dbname => node[:nominatim][:dbname],
199 :flatnode_file => node[:nominatim][:flatnode_file],
200 :log_file => "#{node[:nominatim][:logdir]}/query.log"
203 if node[:nominatim][:flatnode_file] # ~FC023
204 directory File.dirname(node[:nominatim][:flatnode_file]) do
209 template "/etc/logrotate.d/nominatim" do
210 source "logrotate.nominatim.erb"
217 "wikipedia_article.sql.bin",
218 "wikipedia_redirect.sql.bin",
219 "gb_postcode_data.sql.gz"
222 external_data.each do |fname|
223 remote_file "#{source_directory}/data/#{fname}" do
224 action :create_if_missing
225 source "http://www.nominatim.org/data/#{fname}"
232 template "/etc/cron.d/nominatim" do
233 action node[:nominatim][:state] == :off ? :delete : :create
234 source "nominatim.cron.erb"
238 variables :bin_directory => "#{source_directory}/utils", :mailto => email_errors
241 template "#{source_directory}/utils/nominatim-update" do
246 variables :bindir => build_directory,
247 :logfile => "#{node[:nominatim][:logdir]}/update.log",
248 :branch => node[:nominatim][:revision],
249 :update_stop_file => "#{basedir}/status/updates_disabled"
252 template "/etc/init.d/nominatim-update" do
253 source "updater.init.erb"
257 variables :source_directory => source_directory
260 %w(backup-nominatim vacuum-db-nominatim).each do |fname|
261 template "/usr/local/bin/#{fname}" do
262 source "#{fname}.erb"
266 variables :db => node[:nominatim][:dbname]
270 ## webserver frontend
272 template "#{build_directory}/settings/ip_blocks.conf" do
273 action :create_if_missing
274 source "ipblocks.erb"
280 file "#{build_directory}/settings/apache_blocks.conf" do
281 action :create_if_missing
287 file "#{build_directory}/settings/ip_blocks.map" do
288 action :create_if_missing
294 include_recipe "apache::ssl"
302 apache_module "rewrite"
303 apache_module "proxy"
304 apache_module "proxy_fcgi"
305 apache_module "proxy_http"
306 apache_module "headers"
308 service "php5-fpm" do
309 if node[:lsb][:release].to_f >= 15.10
310 provider Chef::Provider::Service::Systemd
311 service_name "php7.0-fpm"
312 elsif node[:lsb][:release].to_f >= 14.04
313 provider Chef::Provider::Service::Upstart
315 action [:enable, :start]
316 supports :status => true, :restart => true, :reload => true
319 php_confdir = node[:lsb][:release].to_f >= 15.10 ? "/etc/php/7.0" : "/etc/php5"
321 node[:nominatim][:fpm_pools].each do |name, data|
322 template "#{php_confdir}/fpm/pool.d/#{name}.conf" do
323 source "fpm.conf.erb"
327 variables data.merge(:name => name)
328 notifies :reload, "service[php5-fpm]"
332 apache_site "nominatim.openstreetmap.org" do
333 template "apache.erb"
334 directory build_directory
335 variables :pools => node[:nominatim][:fpm_pools]
338 apache_site "default" do
342 template "/etc/logrotate.d/apache2" do
343 source "logrotate.apache.erb"
349 include_recipe "fail2ban"
351 fail2ban_filter "nominatim" do
352 failregex '^<HOST> - - \[[^]]+\] "[^"]+" 429 '
355 fail2ban_jail "nominatim" do
357 logpath "/var/log/apache2/nominatim.openstreetmap.org-access.log"
362 munin_plugin_conf "nominatim" do
364 variables :db => node[:nominatim][:dbname],
365 :querylog => "#{node[:nominatim][:logdir]}/query.log"
368 munin_plugin "nominatim_importlag" do
369 target "#{source_directory}/munin/nominatim_importlag"
372 munin_plugin "nominatim_query_speed" do
373 target "#{source_directory}/munin/nominatim_query_speed_querylog"
376 munin_plugin "nominatim_requests" do
377 target "#{source_directory}/munin/nominatim_requests_querylog"
380 munin_plugin "nominatim_throttled_ips" do
381 target "#{source_directory}/munin/nominatim_throttled_ips"