]> git.openstreetmap.org Git - chef.git/blobdiff - cookbooks/nominatim/recipes/default.rb
Fix foodcritic warning
[chef.git] / cookbooks / nominatim / recipes / default.rb
index f6a57a8efc7d78047bed6e9ac42e404e9e485c1a..14b1852b5ff2535b3d6c859228e3546287049dd2 100644 (file)
@@ -17,7 +17,7 @@
 # limitations under the License.
 #
 
-include_recipe "apache"
+include_recipe "apache::ssl"
 include_recipe "postgresql"
 include_recipe "git"
 
@@ -29,62 +29,69 @@ package "php-pear"
 package "php-apc"
 
 apache_module "rewrite"
-apache_module "fastcgi-handler"
+apache_module "proxy"
+apache_module "proxy_fcgi"
 
+passwords = data_bag_item("nominatim", "passwords")
 home_directory = data_bag_item("accounts", "nominatim")["home"]
 source_directory = "#{home_directory}/nominatim"
 email_errors = data_bag_item("accounts", "lonvia")["email"]
 
+database_cluster = node[:nominatim][:database][:cluster]
+database_version = database_cluster.sub(%r{/.*}, "")
+database_name = node[:nominatim][:database][:dbname]
+
+postgis_version = node[:nominatim][:database][:postgis]
+
 service "php5-fpm" do
-  action [ :enable, :start ]
+  provider Chef::Provider::Service::Upstart
+  action [:enable, :start]
   supports :status => true, :restart => true, :reload => true
 end
 
 apache_site "nominatim.openstreetmap.org" do
   template "apache.erb"
-  directory "/home/lonvia/nominatim"
+  directory source_directory
   variables :pools => node[:nominatim][:fpm_pools]
 end
 
-node[:nominatim][:fpm_pools].each do |name,data|
+apache_site "default" do
+  action [:disable]
+end
 
+node[:nominatim][:fpm_pools].each do |name, data|
   template "/etc/php5/fpm/pool.d/#{name}.conf" do
     source "fpm.conf.erb"
     owner "root"
     group "root"
     mode 0644
-    variables data.merge(:name => name)
-    notifies :reload, resources(:service => "php5-fpm")
+    variables data.merge(:name => name, :port => data[:port])
+    notifies :reload, "service[php5-fpm]"
   end
 end
 
-postgresql_user "tomh" do
-  cluster "9.1/main"
-  superuser true
-end
+superusers = %w(tomh lonvia twain nominatim)
 
-postgresql_user "lonvia" do
-  cluster "9.1/main"
-  superuser true
-end
-
-postgresql_user "twain" do
-  cluster "9.1/main"
-  superuser true
+superusers.each do |user|
+  postgresql_user user do
+    cluster database_cluster
+    superuser true
+  end
 end
 
-postgresql_user "nominatim" do
-  cluster "9.1/main"
-  superuser true
+postgresql_user "www-data" do
+  cluster database_cluster
 end
 
-postgresql_user "www-data" do
-  cluster "9.1/main"
+postgresql_user "replication" do
+  cluster database_cluster
+  password passwords["replication"]
+  replication true
 end
 
 postgresql_munin "nominatim" do
-  cluster "9.1/main"
-  database "nominatim"
+  cluster database_cluster
+  database database_name
 end
 
 directory "/var/log/nominatim" do
@@ -93,12 +100,19 @@ directory "/var/log/nominatim" do
   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-9.1-postgis"
-package "postgresql-server-dev-9.1"
+package "postgresql-#{database_version}-postgis-#{postgis_version}"
+package "postgresql-server-dev-#{database_version}"
 package "build-essential"
 package "libxml2-dev"
 package "libgeos-dev"
@@ -110,10 +124,15 @@ 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.exists?("/usr/share/php/DB") }
+  not_if { File.exist?("/usr/share/php/DB") }
 end
 
 execute "compile_nominatim" do
@@ -137,12 +156,11 @@ directory "#{source_directory}/log" do
   mode 0755
 end
 
-
 template "#{source_directory}/.git/hooks/post-merge" do
   source "update_source.erb"
-  owner  "nominatim"
-  group  "nominatim"
-  mode   0755
+  owner "nominatim"
+  group "nominatim"
+  mode 0755
   variables :source_directory => source_directory
 end
 
@@ -151,6 +169,7 @@ template "#{source_directory}/settings/local.php" do
   owner "nominatim"
   group "nominatim"
   mode 0664
+  variables :postgres_version => database_version
 end
 
 template "#{source_directory}/settings/ip_blocks.conf" do
@@ -175,51 +194,93 @@ file "#{source_directory}/settings/ip_blocks.map" do
   mode 0664
 end
 
-cron "nominatim_logrotate" do
-  hour "5"
-  minute "30"
-  weekday "0"
-  command "#{source_directory}/utils/cron_logrotate.sh"
-  user "nominatim"
-  mailto email_errors
+if node[:nominatim][:enabled]
+  cron_action = :create
+else
+  cron_action = :delete
 end
 
-cron "nominatim_banip" do
-  command "#{source_directory}/utils/cron_banip.py"
+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"
-  mailto email_errors
+  group "nominatim"
+  mode 0755
 end
 
-cron "nominatim_vacuum" do
-  hour "2"
-  minute "00"
-  command "#{source_directory}/utils/cron_vacuum.sh"
+template "/etc/init.d/nominatim-update" do
+  source "updater.init.erb"
   user "nominatim"
-  mailto email_errors
+  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
 
-['search', 'reverse'].each do |filename|
-  ['phpj', 'phpx'].each do |ext|
-    link "#{source_directory}/website/#{filename}.#{ext}" do
-      to "#{source_directory}/website/#{filename}.php"
-      user "nominatim"
-      group "nominatim"
-    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
+
+external_data = [
+  "wikipedia_article.sql.bin",
+  "wikipedia_redirect.sql.bin",
+  "gb_postcode_data.sql.gz"
+]
+
+external_data.each do |fname|
+  remote_file "#{source_directory}/data/#{fname}" do
+    action :create_if_missing
+    source "http://www.nominatim.org/data/#{fname}"
+    owner "nominatim"
+    group "nominatim"
+    mode 0644
   end
 end
 
-template "#{source_directory}/utils/nominatim-update" do
-  source "updater.erb"
-  user   "nominatim"
-  group  "nominatim"
-  mode   0755
+additional_scripts = %w(backup-nominatim clean-db-nominatim)
+
+additional_scripts.each do |fname|
+  template "/usr/local/bin/#{fname}" do
+    source "#{fname}.erb"
+    owner "root"
+    group "root"
+    mode 0755
+  end
 end
 
-template "/etc/init.d/nominatim-update" do
-  source "updater.init.erb"
-  user   "nominatim"
-  group  "nominatim"
-  mode   0755
-  variables :source_directory => source_directory
+directory File.dirname(node[:nominatim][:flatnode_file]) do
+  owner "nominatim"
+  group "nominatim"
+  mode 0755
+  recursive true
 end
 
+directory "/data/postgresql-archive" do
+  owner "postgres"
+  group "postgres"
+  mode 0700
+  only_if { node[:postgresql][:settings][:defaults][:archive_mode] == "on" }
+end