+ cluster database_cluster
+ database database_name
+end
+
+directory "/var/log/nominatim" do
+ owner "nominatim"
+ group "nominatim"
+ mode 0755
+end
+
+template "/etc/logrotate.d/nominatim" do
+ source "logrotate.nominatim.erb"
+ owner "root"
+ group "root"
+ mode 0644
+end
+
+package "osmosis"
+package "gcc"
+package "proj-bin"
+package "libgeos-c1"
+package "postgresql-#{database_version}-postgis-#{postgis_version}"
+package "postgresql-server-dev-#{database_version}"
+package "build-essential"
+package "libxml2-dev"
+package "libgeos-dev"
+package "libgeos++-dev"
+package "libpq-dev"
+package "libbz2-dev"
+package "libtool"
+package "automake"
+package "libproj-dev"
+package "libprotobuf-c0-dev"
+package "protobuf-c-compiler"
+package "python-psycopg2"
+package "libboost-dev"
+package "libboost-system-dev"
+package "libboost-filesystem-dev"
+package "libboost-thread-dev"
+
+execute "php-pear-db" do
+ command "pear install DB"
+ not_if { File.exist?("/usr/share/php/DB") }
+end
+
+execute "compile_nominatim" do
+ action :nothing
+ command "cd #{source_directory} && ./autogen.sh && ./configure && make"
+ user "nominatim"
+end
+
+git source_directory do
+ action :checkout
+ repository node[:nominatim][:repository]
+ enable_submodules true
+ user "nominatim"
+ group "nominatim"
+ notifies :run, "execute[compile_nominatim]"
+end
+
+directory "#{source_directory}/log" do
+ owner "nominatim"
+ group "nominatim"
+ mode 0755
+end
+
+template "#{source_directory}/.git/hooks/post-merge" do
+ source "update_source.erb"
+ owner "nominatim"
+ group "nominatim"
+ mode 0755
+ variables :source_directory => source_directory
+end
+
+template "#{source_directory}/settings/local.php" do
+ source "nominatim.erb"
+ owner "nominatim"
+ group "nominatim"
+ mode 0664
+ variables :postgres_version => database_version
+end
+
+template "#{source_directory}/settings/ip_blocks.conf" do
+ action :create_if_missing
+ source "ipblocks.erb"
+ owner "nominatim"
+ group "nominatim"
+ mode 0664
+end
+
+file "#{source_directory}/settings/apache_blocks.conf" do
+ action :create_if_missing
+ owner "nominatim"
+ group "nominatim"
+ mode 0664
+end
+
+file "#{source_directory}/settings/ip_blocks.map" do
+ action :create_if_missing
+ owner "nominatim"
+ group "nominatim"
+ mode 0664
+end
+
+if node[:nominatim][:enabled]
+ cron_action = :create
+else
+ cron_action = :delete
+end
+
+template "/etc/cron.d/nominatim" do
+ action cron_action
+ source "cron.erb"
+ owner "root"
+ group "root"
+ mode "0644"
+ variables :bin_directory => "#{source_directory}/utils", :mailto => email_errors
+end
+
+template "#{source_directory}/utils/nominatim-update" do
+ source "updater.erb"
+ user "nominatim"
+ group "nominatim"
+ mode 0755
+end
+
+template "/etc/init.d/nominatim-update" do
+ source "updater.init.erb"
+ user "nominatim"
+ group "nominatim"
+ mode 0755
+ variables :source_directory => source_directory
+end
+
+munin_plugin_conf "nominatim" do
+ template "munin.erb"
+end
+
+munin_plugin "nominatim_importlag" do
+ target "#{source_directory}/munin/nominatim_importlag"
+end
+
+munin_plugin "nominatim_query_speed" do
+ target "#{source_directory}/munin/nominatim_query_speed_querylog"
+end
+
+munin_plugin "nominatim_requests" do
+ target "#{source_directory}/munin/nominatim_requests_querylog"
+end
+
+munin_plugin "nominatim_throttled_ips" do
+ target "#{source_directory}/munin/nominatim_throttled_ips"
+end
+
+remote_file "#{source_directory}/data/wikipedia_article.sql.bin" do
+ action :create_if_missing
+ source "http://www.nominatim.org/data/wikipedia_article.sql.bin"
+ owner "nominatim"
+ group "nominatim"
+ mode 0644
+end
+
+remote_file "#{source_directory}/data/wikipedia_redirect.sql.bin" do
+ action :create_if_missing
+ source "http://www.nominatim.org/data/wikipedia_redirect.sql.bin"
+ owner "nominatim"
+ group "nominatim"
+ mode 0644
+end
+
+remote_file "#{source_directory}/data/gb_postcode_data.sql.gz" do
+ action :create_if_missing
+ source "http://www.nominatim.org/data/gb_postcode_data.sql.gz"
+ owner "nominatim"
+ group "nominatim"
+ mode 0644
+end
+
+template "/usr/local/bin/backup-nominatim" do
+ source "backup-nominatim.erb"
+ owner "root"
+ group "root"
+ mode 0755
+end
+
+directory File.dirname(node[:nominatim][:flatnode_file]) do
+ owner "nominatim"
+ group "nominatim"
+ mode 0755
+ recursive true