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 node[:nominatim][:fpm_pools].each do |name,data|
65 template "/etc/php5/fpm/pool.d/#{name}.conf" do
70 variables data.merge(:name => name, :port => data[:port])
71 notifies :reload, "service[php5-fpm]"
75 postgresql_user "tomh" do
76 cluster database_cluster
80 postgresql_user "lonvia" do
81 cluster database_cluster
85 postgresql_user "twain" do
86 cluster database_cluster
90 postgresql_user "nominatim" do
91 cluster database_cluster
95 postgresql_user "www-data" do
96 cluster database_cluster
99 postgresql_munin "nominatim" do
100 cluster database_cluster
101 database database_name
104 directory "/var/log/nominatim" do
110 template "/etc/logrotate.d/nominatim" do
111 source "logrotate.nominatim.erb"
122 package "postgresql-#{database_version}-postgis-#{postgis_version}"
123 package "postgresql-server-dev-#{database_version}"
124 package "build-essential"
125 package "libxml2-dev"
126 package "libgeos-dev"
127 package "libgeos++-dev"
132 package "libproj-dev"
133 package "libprotobuf-c0-dev"
134 package "protobuf-c-compiler"
135 package "python-psycopg2"
137 execute "php-pear-db" do
138 command "pear install DB"
139 not_if { File.exists?("/usr/share/php/DB") }
142 execute "compile_nominatim" do
144 command "cd #{source_directory} && ./autogen.sh && ./configure && make"
148 git source_directory do
150 repository node[:nominatim][:repository]
151 enable_submodules true
154 notifies :run, "execute[compile_nominatim]"
157 directory "#{source_directory}/log" do
164 template "#{source_directory}/.git/hooks/post-merge" do
165 source "update_source.erb"
169 variables :source_directory => source_directory
172 template "#{source_directory}/settings/local.php" do
173 source "nominatim.erb"
179 template "#{source_directory}/settings/ip_blocks.conf" do
180 action :create_if_missing
181 source "ipblocks.erb"
187 file "#{source_directory}/settings/apache_blocks.conf" do
188 action :create_if_missing
194 file "#{source_directory}/settings/ip_blocks.map" do
195 action :create_if_missing
201 if node[:nominatim][:enabled]
202 cron_action = :create
204 cron_action = :delete
207 cron "nominatim_logrotate" do
212 command "#{source_directory}/utils/cron_logrotate.sh"
217 cron "nominatim_banip" do
219 command "#{source_directory}/utils/cron_banip.py"
224 cron "nominatim_vacuum" do
228 command "#{source_directory}/utils/cron_vacuum.sh"
233 ['search', 'reverse'].each do |filename|
234 ['phpj', 'phpx'].each do |ext|
235 link "#{source_directory}/website/#{filename}.#{ext}" do
236 to "#{source_directory}/website/#{filename}.php"
243 template "#{source_directory}/utils/nominatim-update" do
250 template "/etc/init.d/nominatim-update" do
251 source "updater.init.erb"
255 variables :source_directory => source_directory
258 munin_plugin_conf "nominatim" do
262 munin_plugin "nominatim_importlag" do
263 target "#{source_directory}/munin/nominatim_importlag"
266 munin_plugin "nominatim_query_speed" do
267 target "#{source_directory}/munin/nominatim_query_speed"
270 munin_plugin "nominatim_requests" do
271 target "#{source_directory}/munin/nominatim_requests"
274 munin_plugin "nominatim_throttled_ips" do
275 target "#{source_directory}/munin/nominatim_throttled_ips"
278 template "/usr/local/bin/backup-nominatim" do
279 source "backup-nominatim.erb"
285 cron "nominatim_backup" do
290 command "/usr/local/bin/backup-nominatim"