2 # Cookbook Name:: nominatim
5 # Copyright 2012, 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 include_recipe "apache::ssl"
21 include_recipe "postgresql"
31 apache_module "rewrite"
33 apache_module "proxy_fcgi"
35 passwords = data_bag_item("nominatim", "passwords")
36 home_directory = data_bag_item("accounts", "nominatim")["home"]
37 source_directory = "#{home_directory}/nominatim"
38 email_errors = data_bag_item("accounts", "lonvia")["email"]
40 database_cluster = node[:nominatim][:database][:cluster]
41 database_version = database_cluster.sub(%r{/.*}, "")
42 database_name = node[:nominatim][:database][:dbname]
44 postgis_version = node[:nominatim][:database][:postgis]
47 provider Chef::Provider::Service::Upstart
48 action [:enable, :start]
49 supports :status => true, :restart => true, :reload => true
52 apache_site "nominatim.openstreetmap.org" do
54 directory source_directory
55 variables :pools => node[:nominatim][:fpm_pools]
58 apache_site "default" do
62 node[:nominatim][:fpm_pools].each do |name, data|
63 template "/etc/php5/fpm/pool.d/#{name}.conf" do
68 variables data.merge(:name => name, :port => data[:port])
69 notifies :reload, "service[php5-fpm]"
73 superusers = %w(tomh lonvia twain nominatim)
75 superusers.each do |user|
76 postgresql_user user do
77 cluster database_cluster
82 postgresql_user "www-data" do
83 cluster database_cluster
86 postgresql_user "replication" do
87 cluster database_cluster
88 password passwords["replication"]
92 postgresql_munin "nominatim" do
93 cluster database_cluster
94 database database_name
97 directory "/var/log/nominatim" do
103 template "/etc/logrotate.d/nominatim" do
104 source "logrotate.nominatim.erb"
114 package "postgresql-#{database_version}-postgis-#{postgis_version}"
115 package "postgresql-server-dev-#{database_version}"
116 package "build-essential"
117 package "libxml2-dev"
118 package "libgeos-dev"
119 package "libgeos++-dev"
124 package "libproj-dev"
125 package "libprotobuf-c0-dev"
126 package "protobuf-c-compiler"
127 package "python-psycopg2"
128 package "libboost-dev"
129 package "libboost-system-dev"
130 package "libboost-filesystem-dev"
131 package "libboost-thread-dev"
133 execute "php-pear-db" do
134 command "pear install DB"
135 not_if { File.exist?("/usr/share/php/DB") }
138 execute "compile_nominatim" do
140 command "cd #{source_directory} && ./autogen.sh && ./configure && make"
144 git source_directory do
146 repository node[:nominatim][:repository]
147 enable_submodules true
150 notifies :run, "execute[compile_nominatim]"
153 directory "#{source_directory}/log" do
159 template "#{source_directory}/.git/hooks/post-merge" do
160 source "update_source.erb"
164 variables :source_directory => source_directory
167 template "#{source_directory}/settings/local.php" do
168 source "nominatim.erb"
172 variables :postgres_version => database_version
175 template "#{source_directory}/settings/ip_blocks.conf" do
176 action :create_if_missing
177 source "ipblocks.erb"
183 file "#{source_directory}/settings/apache_blocks.conf" do
184 action :create_if_missing
190 file "#{source_directory}/settings/ip_blocks.map" do
191 action :create_if_missing
197 if node[:nominatim][:enabled]
198 cron_action = :create
200 cron_action = :delete
203 template "/etc/cron.d/nominatim" do
209 variables :bin_directory => "#{source_directory}/utils", :mailto => email_errors
212 template "#{source_directory}/utils/nominatim-update" do
219 template "/etc/init.d/nominatim-update" do
220 source "updater.init.erb"
224 variables :source_directory => source_directory
227 munin_plugin_conf "nominatim" do
231 munin_plugin "nominatim_importlag" do
232 target "#{source_directory}/munin/nominatim_importlag"
235 munin_plugin "nominatim_query_speed" do
236 target "#{source_directory}/munin/nominatim_query_speed_querylog"
239 munin_plugin "nominatim_requests" do
240 target "#{source_directory}/munin/nominatim_requests_querylog"
243 munin_plugin "nominatim_throttled_ips" do
244 target "#{source_directory}/munin/nominatim_throttled_ips"
248 "wikipedia_article.sql.bin",
249 "wikipedia_redirect.sql.bin",
250 "gb_postcode_data.sql.gz"
253 external_data.each do |fname|
254 remote_file "#{source_directory}/data/#{fname}" do
255 action :create_if_missing
256 source "http://www.nominatim.org/data/#{fname}"
263 additional_scripts = %w(backup-nominatim clean-db-nominatim)
265 additional_scripts.each do |fname|
266 template "/usr/local/bin/#{fname}" do
267 source "#{fname}.erb"
274 directory File.dirname(node[:nominatim][:flatnode_file]) do
281 directory "/data/postgresql-archive" do
285 only_if { node[:postgresql][:settings][:defaults][:archive_mode] == "on" }
288 fail2ban_filter "nominatim" do
289 failregex '^<HOST> - - \[[^]]+\] "[^"]+" (403|429) '
292 fail2ban_jail "nominatim" do
294 logpath "/var/log/apache2/nominatim.openstreetmap.org-access.log"