5 # Copyright:: 2011, 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 # https://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.
21 require "securerandom"
23 include_recipe "accounts"
24 include_recipe "apache"
25 include_recipe "passenger"
26 include_recipe "geoipupdate"
28 include_recipe "memcached"
29 include_recipe "mysql"
30 include_recipe "nodejs"
31 include_recipe "php::fpm"
32 include_recipe "podman"
33 include_recipe "postgresql"
34 include_recipe "python"
67 libboost-date-time-dev
69 libboost-filesystem-dev
71 libboost-program-options-dev
75 libbytes-random-secure-perl
156 # Add uk_os_OSTN15_NTv2_OSGBtoETRS.tif used for reprojecting OS data
157 execute "uk_os_OSTN15_NTv2_OSGBtoETRS.tif" do
158 command "projsync --file uk_os_OSTN15_NTv2_OSGBtoETRS.tif --system-directory"
159 not_if { ::File.exist?("/usr/share/proj/uk_os_OSTN15_NTv2_OSGBtoETRS.tif") }
162 nodejs_package "svgo"
165 apache_module "expires"
166 apache_module "headers"
167 apache_module "proxy"
168 apache_module "proxy_fcgi"
169 apache_module "rewrite"
170 apache_module "suexec"
171 apache_module "userdir"
173 apache_module "wsgi" do
174 package "libapache2-mod-wsgi-py3"
177 package "apache2-suexec-pristine"
182 pm_min_spare_servers 2
183 pm_max_spare_servers 6
190 directory "/srv/dev.openstreetmap.org" do
196 template "/srv/dev.openstreetmap.org/index.html" do
197 source "dev.html.erb"
203 ssl_certificate "dev.openstreetmap.org" do
204 domains "dev.openstreetmap.org"
205 notifies :reload, "service[apache2]"
208 apache_site "dev.openstreetmap.org" do
209 template "apache.dev.erb"
214 template "/etc/phppgadmin/config.inc.php" do
215 source "phppgadmin.conf.erb"
221 file "/etc/apache2/conf.d/phppgadmin" do
225 ssl_certificate "phppgadmin.dev.openstreetmap.org" do
226 domains "phppgadmin.dev.openstreetmap.org"
227 notifies :reload, "service[apache2]"
230 apache_site "phppgadmin.dev.openstreetmap.org" do
231 template "apache.phppgadmin.erb"
234 search(:accounts, "*:*").each do |account|
236 details = node[:accounts][:users][name] || {}
238 next unless %w[user administrator].include?(details[:status])
240 user_home = details[:home] || account["home"] || "#{node[:accounts][:home]}/#{name}"
242 next unless File.directory?("#{user_home}/public_html")
249 pm_min_spare_servers 2
250 pm_max_spare_servers 6
251 pm_max_requests 10000
252 request_terminate_timeout 1800
253 environment "HOSTNAME" => "$HOSTNAME",
254 "PATH" => "/usr/local/bin:/usr/bin:/bin",
258 php_values "max_execution_time" => "300",
259 "memory_limit" => "128M",
260 "post_max_size" => "32M",
261 "upload_max_filesize" => "32M"
262 php_admin_values "sendmail_path" => "/usr/sbin/sendmail -t -i -f #{name}@dev.openstreetmap.org",
263 "open_basedir" => "/home/#{name}/:/tmp/:/usr/share/php/"
264 php_flags "display_errors" => "on"
267 ssl_certificate "#{name}.dev.openstreetmap.org" do
268 domains ["#{name}.dev.openstreetmap.org", "#{name}.dev.osm.org"]
269 notifies :reload, "service[apache2]"
272 apache_site "#{name}.dev.openstreetmap.org" do
273 template "apache.user.erb"
274 directory "#{user_home}/public_html"
275 variables :user => name
278 template "/etc/sudoers.d/#{name}" do
279 source "sudoers.user.erb"
283 variables :user => name
287 node[:postgresql][:versions].each do |version|
288 package "postgresql-#{version}-postgis-3"
291 if node[:postgresql][:clusters][:"15/main"]
292 postgresql_user "apis" do
296 template "/usr/local/bin/cleanup-rails-assets" do
298 source "cleanup-assets.erb"
304 systemd_service "rails-jobs@" do
305 description "Rails job queue runner"
307 environment_file "/etc/default/rails-%i"
309 working_directory "/srv/%i.apis.dev.openstreetmap.org/rails"
310 exec_start "#{node[:ruby][:bundle]} exec rails jobs:work"
313 sandbox :enable_network => true
314 restrict_address_families "AF_UNIX"
315 memory_deny_write_execute false
317 "/srv/%i.apis.dev.openstreetmap.org/logs",
318 "/srv/%i.apis.dev.openstreetmap.org/rails/storage"
322 systemd_service "cgimap@" do
323 description "OpenStreetMap API Server"
325 environment_file "/etc/default/cgimap-%i"
329 exec_start "/srv/%i.apis.dev.openstreetmap.org/cgimap/build/openstreetmap-cgimap --daemon --instances 5"
330 exec_reload "/bin/kill -HUP $MAINPID"
331 runtime_directory "cgimap-%i"
332 sandbox :enable_network => true
333 restrict_address_families "AF_UNIX"
334 read_write_paths ["/srv/%i.apis.dev.openstreetmap.org/logs", "/srv/%i.apis.dev.openstreetmap.org/rails/tmp"]
338 Dir.glob("/srv/*.apis.dev.openstreetmap.org").each do |dir|
339 node.default_unless[:dev][:rails][File.basename(dir).split(".").first] = {}
342 node[:dev][:rails].each do |name, details|
343 database_name = details[:database] || "apis_#{name}"
344 site_name = "#{name}.apis.dev.openstreetmap.org"
345 site_directory = "/srv/#{name}.apis.dev.openstreetmap.org"
346 log_directory = "#{site_directory}/logs"
347 rails_directory = "#{site_directory}/rails"
348 cgimap_directory = "#{site_directory}/cgimap"
349 gpx_directory = "#{site_directory}/gpx"
351 if details[:repository]
352 site_aliases = details[:aliases] || []
353 secret_key_base = persistent_token("dev", "rails", name, "secret_key_base")
355 postgresql_database database_name do
360 postgresql_extension "#{database_name}_btree_gist" do
362 database database_name
363 extension "btree_gist"
366 directory site_directory do
372 directory log_directory do
378 directory gpx_directory do
384 directory "#{gpx_directory}/traces" do
390 directory "#{gpx_directory}/images" do
396 openssl_rsa_private_key "#{site_directory}/doorkeeper.key" do
402 rails_port site_name do
403 directory rails_directory
406 repository details[:repository]
407 revision details[:revision]
408 database_port node[:postgresql][:clusters][:"15/main"][:port]
409 database_name database_name
410 database_username "apis"
411 email_from "OpenStreetMap <web@noreply.openstreetmap.org>"
412 gpx_dir gpx_directory
413 log_path "#{log_directory}/rails.log"
414 memcache_servers ["127.0.0.1"]
417 trace_use_job_queue true
418 doorkeeper_signing_key lazy { File.read("#{site_directory}/doorkeeper.key") }
421 template "#{rails_directory}/config/initializers/setup.rb" do
422 source "rails.setup.rb.erb"
426 variables :site => site_name
427 notifies :restart, "rails_port[#{site_name}]"
430 template "/etc/default/rails-#{name}" do
431 source "rails.environment.erb"
435 variables :secret_key_base => secret_key_base
438 service "rails-jobs@#{name}" do
439 action [:enable, :start]
440 supports :restart => true
441 subscribes :restart, "rails_port[#{site_name}]"
442 subscribes :restart, "systemd_service[rails-jobs@]"
443 only_if "fgrep -q delayed_job #{rails_directory}/Gemfile.lock"
446 if details[:cgimap_repository]
447 git cgimap_directory do
449 repository details[:cgimap_repository]
450 revision details[:cgimap_revision]
455 directory "#{cgimap_directory}/build" do
461 execute "#{cgimap_directory}/CMakeLists.txt" do
464 cwd "#{cgimap_directory}/build"
467 subscribes :run, "git[#{cgimap_directory}]", :immediately
470 execute "#{cgimap_directory}/build/Makefile" do
473 cwd "#{cgimap_directory}/build"
476 subscribes :run, "execute[#{cgimap_directory}/CMakeLists.txt]", :immediately
479 template "/etc/default/cgimap-#{name}" do
480 source "cgimap.environment.erb"
484 variables :cgimap_socket => "/run/cgimap-#{name}/socket",
485 :database_port => node[:postgresql][:clusters][:"15/main"][:port],
486 :database_name => database_name,
487 :log_directory => log_directory,
488 :options => details[:cgimap_options]
491 service "cgimap@#{name}" do
492 action [:start, :enable]
493 subscribes :restart, "execute[#{cgimap_directory}/build/Makefile]"
494 subscribes :restart, "template[/etc/default/cgimap-#{name}]"
495 subscribes :restart, "systemd_service[cgimap@]"
499 ssl_certificate site_name do
500 domains [site_name] + site_aliases
501 notifies :reload, "service[apache2]"
504 apache_site site_name do
505 template "apache.rails.erb"
506 variables :application_name => name,
507 :aliases => site_aliases,
508 :secret_key_base => secret_key_base,
509 :cgimap_enabled => details.key?(:cgimap_repository),
510 :cgimap_socket => "/run/cgimap-#{name}/socket"
513 template "/etc/logrotate.d/apis-#{name}" do
514 source "logrotate.apis.erb"
518 variables :name => name,
519 :log_directory => log_directory,
520 :rails_directory => rails_directory
523 file "/etc/logrotate.d/apis-#{name}" do
527 apache_site site_name do
531 service "cgimap@#{name}" do
532 action [:stop, :disable]
535 file "/etc/default/cgimap-#{name}" do
539 service "rails-jobs@#{name}" do
540 action [:stop, :disable]
543 directory site_directory do
548 file "/etc/cron.daily/rails-#{site_name.tr('.', '-')}" do
552 postgresql_database database_name do
559 directory "/srv/apis.dev.openstreetmap.org" do
565 template "/srv/apis.dev.openstreetmap.org/index.html" do
566 source "apis.html.erb"
572 ssl_certificate "apis.dev.openstreetmap.org" do
573 domains "apis.dev.openstreetmap.org"
574 notifies :reload, "service[apache2]"
577 apache_site "apis.dev.openstreetmap.org" do
578 template "apache.apis.erb"
582 directory "/srv/ooc.openstreetmap.org" do
588 remote_directory "/srv/ooc.openstreetmap.org/html" do
598 ssl_certificate "ooc.openstreetmap.org" do
599 domains ["ooc.openstreetmap.org",
600 "a.ooc.openstreetmap.org",
601 "b.ooc.openstreetmap.org",
602 "c.ooc.openstreetmap.org"]
603 notifies :reload, "service[apache2]"
606 apache_site "ooc.openstreetmap.org" do
607 template "apache.ooc.erb"
610 directory "/etc/systemd/system/user-.slice.d" do
616 template "/etc/systemd/system/user-.slice.d/99-chef.conf" do
617 source "user-slice.conf.erb"