-source_directory = "#{basedir}/src/nominatim"
-build_directory = "#{basedir}/src/build"
-project_directory = "#{basedir}/planet-project"
-bin_directory = "#{basedir}/bin"
-cfg_directory = "#{basedir}/etc"
-ui_directory = "#{basedir}/ui"
-qa_bin_directory = "#{basedir}/src/Nominatim-Data-Analyser"
-qa_data_directory = "#{basedir}/qa-data"
-
-[basedir, "#{basedir}/src", cfg_directory, bin_directory, build_directory, project_directory].each do |path|
- directory path do
+ ssl_certificate node[:fqdn] do
+ domains [node[:fqdn],
+ "nominatim.openstreetmap.org",
+ "nominatim.osm.org",
+ "nominatim.openstreetmap.com",
+ "nominatim.openstreetmap.net",
+ "nominatim.openstreetmaps.org",
+ "nominatim.openmaps.org",
+ "nominatim.qgis.org"]
+ notifies :reload, "service[nginx]"
+ end
+
+ nginx_site "default" do
+ action [:delete]
+ end
+
+ frontends = search(:node, "recipes:web\\:\\:frontend").sort_by(&:name)
+
+ nginx_site "nominatim" do
+ template "nginx.erb"
+ directory project_directory
+ variables :pools => node[:nominatim][:fpm_pools],
+ :frontends => frontends,
+ :confdir => "#{basedir}/etc",
+ :ui_directory => ui_directory
+ end
+
+ template "/etc/logrotate.d/nginx" do
+ source "logrotate.nginx.erb"
+ owner "root"
+ group "root"
+ mode "644"
+ end
+
+ ### Import, update and maintenance scripts
+
+ %w[nominatim-update
+ nominatim-update-data
+ nominatim-update-refresh-db
+ nominatim-daily-maintenance].each do |fname|
+ template "#{bin_directory}/#{fname}" do
+ source "#{fname}.erb"
+ owner "nominatim"
+ group "nominatim"
+ mode "554"
+ variables :bindir => bin_directory,
+ :projectdir => project_directory,
+ :venvprefix => "#{python_directory}/bin/",
+ :qadatadir => qa_data_directory
+ end
+ end
+
+ systemd_service "nominatim-update" do
+ description "Update the Nominatim database"
+ exec_start "#{bin_directory}/nominatim-update"
+ restart "on-success"
+ standard_output "journal"
+ standard_error "inherit"
+ working_directory project_directory
+ end
+
+ systemd_service "nominatim-update-maintenance-trigger" do
+ description "Trigger daily maintenance tasks for Nominatim DB"
+ exec_start "ln -sf #{bin_directory}/nominatim-daily-maintenance #{bin_directory}/maintenance/"
+ user "nominatim"
+ end
+
+ systemd_timer "nominatim-update-maintenance-trigger" do
+ action node[:nominatim][:state] != "off" ? :create : :delete
+ description "Schedule daily maintenance tasks for Nominatim DB"
+ on_calendar "*-*-* 02:03:00 UTC"
+ end
+
+ service "nominatim-update-maintenance-trigger" do
+ action node[:nominatim][:state] != "off" ? :enable : :disable
+ end
+
+ ## Nominatim UI
+
+ git ui_directory do
+ action :sync
+ repository node[:nominatim][:ui_repository]
+ revision node[:nominatim][:ui_revision]
+ user "nominatim"
+ group "nominatim"
+ end
+
+ template "#{ui_directory}/dist/theme/config.theme.js" do
+ source "ui-config.js.erb"