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 if node[:lsb][:release].to_f >= 14.04
35 apache_module "proxy_fcgi"
37 apache_module "fastcgi-handler"
40 home_directory = data_bag_item("accounts", "nominatim")["home"]
41 source_directory = "#{home_directory}/nominatim"
42 email_errors = data_bag_item("accounts", "lonvia")["email"]
44 database_cluster = node[:nominatim][:database][:cluster]
45 database_version = database_cluster.sub(/\/.*/, "")
46 database_name = node[:nominatim][:database][:dbname]
48 postgis_version = node[:nominatim][:database][:postgis]
51 if node[:lsb][:release].to_f >= 14.04
52 provider Chef::Provider::Service::Upstart
54 action [ :enable, :start ]
55 supports :status => true, :restart => true, :reload => true
58 apache_site "nominatim.openstreetmap.org" do
60 directory source_directory
61 variables :pools => node[:nominatim][:fpm_pools]
64 apache_site "default" do
68 node[:nominatim][:fpm_pools].each do |name,data|
69 template "/etc/php5/fpm/pool.d/#{name}.conf" do
74 variables data.merge(:name => name, :port => data[:port])
75 notifies :reload, "service[php5-fpm]"
79 postgresql_user "tomh" do
80 cluster database_cluster
84 postgresql_user "lonvia" do
85 cluster database_cluster
89 postgresql_user "twain" do
90 cluster database_cluster
94 postgresql_user "nominatim" do
95 cluster database_cluster
99 postgresql_user "www-data" do
100 cluster database_cluster
103 postgresql_munin "nominatim" do
104 cluster database_cluster
105 database database_name
108 directory "/var/log/nominatim" do
114 template "/etc/logrotate.d/nominatim" do
115 source "logrotate.nominatim.erb"
126 package "postgresql-#{database_version}-postgis-#{postgis_version}"
127 package "postgresql-server-dev-#{database_version}"
128 package "build-essential"
129 package "libxml2-dev"
130 package "libgeos-dev"
131 package "libgeos++-dev"
136 package "libproj-dev"
137 package "libprotobuf-c0-dev"
138 package "protobuf-c-compiler"
139 package "python-psycopg2"
141 execute "php-pear-db" do
142 command "pear install DB"
143 not_if { File.exists?("/usr/share/php/DB") }
146 execute "compile_nominatim" do
148 command "cd #{source_directory} && ./autogen.sh && ./configure && make"
152 git source_directory do
154 repository node[:nominatim][:repository]
155 enable_submodules true
158 notifies :run, "execute[compile_nominatim]"
161 directory "#{source_directory}/log" do
168 template "#{source_directory}/.git/hooks/post-merge" do
169 source "update_source.erb"
173 variables :source_directory => source_directory
176 template "#{source_directory}/settings/local.php" do
177 source "nominatim.erb"
183 template "#{source_directory}/settings/ip_blocks.conf" do
184 action :create_if_missing
185 source "ipblocks.erb"
191 file "#{source_directory}/settings/apache_blocks.conf" do
192 action :create_if_missing
198 file "#{source_directory}/settings/ip_blocks.map" do
199 action :create_if_missing
205 if node[:nominatim][:enabled]
206 cron_action = :create
208 cron_action = :delete
211 cron "nominatim_logrotate" do
216 command "#{source_directory}/utils/cron_logrotate.sh"
221 cron "nominatim_banip" do
223 command "#{source_directory}/utils/cron_banip.py"
228 cron "nominatim_vacuum" do
232 command "#{source_directory}/utils/cron_vacuum.sh"
237 template "#{source_directory}/utils/nominatim-update" do
244 template "/etc/init.d/nominatim-update" do
245 source "updater.init.erb"
249 variables :source_directory => source_directory
252 munin_plugin_conf "nominatim" do
256 munin_plugin "nominatim_importlag" do
257 target "#{source_directory}/munin/nominatim_importlag"
260 munin_plugin "nominatim_query_speed" do
261 target "#{source_directory}/munin/nominatim_query_speed"
264 munin_plugin "nominatim_requests" do
265 target "#{source_directory}/munin/nominatim_requests"
268 munin_plugin "nominatim_throttled_ips" do
269 target "#{source_directory}/munin/nominatim_throttled_ips"
272 template "/usr/local/bin/backup-nominatim" do
273 source "backup-nominatim.erb"
279 cron "nominatim_backup" do
284 command "/usr/local/bin/backup-nominatim"