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"
68 libboost-date-time-dev
70 libboost-filesystem-dev
72 libboost-program-options-dev
76 libbytes-random-secure-perl
158 # Add uk_os_OSTN15_NTv2_OSGBtoETRS.tif used for reprojecting OS data
159 execute "uk_os_OSTN15_NTv2_OSGBtoETRS.tif" do
160 command "projsync --file uk_os_OSTN15_NTv2_OSGBtoETRS.tif --system-directory"
161 not_if { ::File.exist?("/usr/share/proj/uk_os_OSTN15_NTv2_OSGBtoETRS.tif") }
164 nodejs_package "svgo"
167 apache_module "expires"
168 apache_module "headers"
169 apache_module "proxy"
170 apache_module "proxy_fcgi"
171 apache_module "rewrite"
172 apache_module "suexec"
173 apache_module "userdir"
175 apache_module "wsgi" do
176 package "libapache2-mod-wsgi-py3"
179 package "apache2-suexec-pristine"
184 pm_min_spare_servers 2
185 pm_max_spare_servers 6
192 directory "/srv/dev.openstreetmap.org" do
198 template "/srv/dev.openstreetmap.org/index.html" do
199 source "dev.html.erb"
205 ssl_certificate "dev.openstreetmap.org" do
206 domains "dev.openstreetmap.org"
207 notifies :reload, "service[apache2]"
210 apache_site "dev.openstreetmap.org" do
211 template "apache.dev.erb"
216 template "/etc/phppgadmin/config.inc.php" do
217 source "phppgadmin.conf.erb"
223 file "/etc/apache2/conf.d/phppgadmin" do
227 ssl_certificate "phppgadmin.dev.openstreetmap.org" do
228 domains "phppgadmin.dev.openstreetmap.org"
229 notifies :reload, "service[apache2]"
232 apache_site "phppgadmin.dev.openstreetmap.org" do
233 template "apache.phppgadmin.erb"
236 search(:accounts, "*:*").each do |account|
238 details = node[:accounts][:users][name] || {}
240 next unless %w[user administrator].include?(details[:status])
242 user_home = details[:home] || account["home"] || "#{node[:accounts][:home]}/#{name}"
244 next unless File.directory?("#{user_home}/public_html")
251 pm_min_spare_servers 2
252 pm_max_spare_servers 6
253 pm_max_requests 10000
254 request_terminate_timeout 1800
255 environment "HOSTNAME" => "$HOSTNAME",
256 "PATH" => "/usr/local/bin:/usr/bin:/bin",
260 php_values "max_execution_time" => "300",
261 "memory_limit" => "128M",
262 "post_max_size" => "32M",
263 "upload_max_filesize" => "32M"
264 php_admin_values "sendmail_path" => "/usr/sbin/sendmail -t -i -f #{name}@dev.openstreetmap.org",
265 "open_basedir" => "/home/#{name}/:/tmp/:/usr/share/php/"
266 php_flags "display_errors" => "on"
269 ssl_certificate "#{name}.dev.openstreetmap.org" do
270 domains ["#{name}.dev.openstreetmap.org", "#{name}.dev.osm.org"]
271 notifies :reload, "service[apache2]"
274 apache_site "#{name}.dev.openstreetmap.org" do
275 template "apache.user.erb"
276 directory "#{user_home}/public_html"
277 variables :user => name
280 template "/etc/sudoers.d/#{name}" do
281 source "sudoers.user.erb"
285 variables :user => name
289 node[:postgresql][:versions].each do |version|
290 package "postgresql-#{version}-postgis-3"
293 if node[:postgresql][:clusters][:"15/main"]
294 postgresql_user "apis" do
298 template "/usr/local/bin/cleanup-rails-assets" do
300 source "cleanup-assets.erb"
306 systemd_service "rails-jobs@" do
307 description "Rails job queue runner"
309 environment_file "/etc/default/rails-%i"
311 working_directory "/srv/%i.apis.dev.openstreetmap.org/rails"
312 exec_start "#{node[:ruby][:bundle]} exec rails jobs:work"
315 sandbox :enable_network => true
316 restrict_address_families "AF_UNIX"
317 memory_deny_write_execute false
319 "/srv/%i.apis.dev.openstreetmap.org/logs",
320 "/srv/%i.apis.dev.openstreetmap.org/rails/storage"
324 systemd_service "cgimap@" do
325 description "OpenStreetMap API Server"
327 environment_file "/etc/default/cgimap-%i"
331 exec_start "/srv/%i.apis.dev.openstreetmap.org/cgimap/build/openstreetmap-cgimap --daemon --instances 5"
332 exec_reload "/bin/kill -HUP $MAINPID"
333 runtime_directory "cgimap-%i"
334 sandbox :enable_network => true
335 restrict_address_families "AF_UNIX"
336 read_write_paths ["/srv/%i.apis.dev.openstreetmap.org/logs", "/srv/%i.apis.dev.openstreetmap.org/rails/tmp"]
340 Dir.glob("/srv/*.apis.dev.openstreetmap.org").each do |dir|
341 node.default_unless[:dev][:rails][File.basename(dir).split(".").first] = {}
344 node[:dev][:rails].each do |name, details|
345 database_name = details[:database] || "apis_#{name}"
346 site_name = "#{name}.apis.dev.openstreetmap.org"
347 site_directory = "/srv/#{name}.apis.dev.openstreetmap.org"
348 log_directory = "#{site_directory}/logs"
349 rails_directory = "#{site_directory}/rails"
350 cgimap_directory = "#{site_directory}/cgimap"
351 gpx_directory = "#{site_directory}/gpx"
353 if details[:repository]
354 site_aliases = details[:aliases] || []
355 secret_key_base = persistent_token("dev", "rails", name, "secret_key_base")
357 postgresql_database database_name do
362 postgresql_extension "#{database_name}_btree_gist" do
364 database database_name
365 extension "btree_gist"
368 directory site_directory do
374 directory log_directory do
380 directory gpx_directory do
386 directory "#{gpx_directory}/traces" do
392 directory "#{gpx_directory}/images" do
398 openssl_rsa_private_key "#{site_directory}/doorkeeper.key" do
404 rails_port site_name do
405 directory rails_directory
408 repository details[:repository]
409 revision details[:revision]
410 database_port node[:postgresql][:clusters][:"15/main"][:port]
411 database_name database_name
412 database_username "apis"
413 email_from "OpenStreetMap <web@noreply.openstreetmap.org>"
414 gpx_dir gpx_directory
415 log_path "#{log_directory}/rails.log"
416 memcache_servers ["127.0.0.1"]
419 trace_use_job_queue true
420 doorkeeper_signing_key lazy { File.read("#{site_directory}/doorkeeper.key") }
423 template "#{rails_directory}/config/initializers/setup.rb" do
424 source "rails.setup.rb.erb"
428 variables :site => site_name
429 notifies :restart, "rails_port[#{site_name}]"
432 template "/etc/default/rails-#{name}" do
433 source "rails.environment.erb"
437 variables :secret_key_base => secret_key_base
440 service "rails-jobs@#{name}" do
441 action [:enable, :start]
442 supports :restart => true
443 subscribes :restart, "rails_port[#{site_name}]"
444 subscribes :restart, "systemd_service[rails-jobs@]"
445 only_if "fgrep -q delayed_job #{rails_directory}/Gemfile.lock"
448 if details[:cgimap_repository]
449 git cgimap_directory do
451 repository details[:cgimap_repository]
452 revision details[:cgimap_revision]
457 directory "#{cgimap_directory}/build" do
463 execute "#{cgimap_directory}/CMakeLists.txt" do
466 cwd "#{cgimap_directory}/build"
469 subscribes :run, "git[#{cgimap_directory}]", :immediately
472 execute "#{cgimap_directory}/build/Makefile" do
475 cwd "#{cgimap_directory}/build"
478 subscribes :run, "execute[#{cgimap_directory}/CMakeLists.txt]", :immediately
481 template "/etc/default/cgimap-#{name}" do
482 source "cgimap.environment.erb"
486 variables :cgimap_socket => "/run/cgimap-#{name}/socket",
487 :database_port => node[:postgresql][:clusters][:"15/main"][:port],
488 :database_name => database_name,
489 :log_directory => log_directory,
490 :options => details[:cgimap_options]
493 service "cgimap@#{name}" do
494 action [:start, :enable]
495 subscribes :restart, "execute[#{cgimap_directory}/build/Makefile]"
496 subscribes :restart, "template[/etc/default/cgimap-#{name}]"
497 subscribes :restart, "systemd_service[cgimap@]"
501 ssl_certificate site_name do
502 domains [site_name] + site_aliases
503 notifies :reload, "service[apache2]"
506 apache_site site_name do
507 template "apache.rails.erb"
508 variables :application_name => name,
509 :aliases => site_aliases,
510 :secret_key_base => secret_key_base,
511 :cgimap_enabled => details.key?(:cgimap_repository),
512 :cgimap_socket => "/run/cgimap-#{name}/socket"
515 template "/etc/logrotate.d/apis-#{name}" do
516 source "logrotate.apis.erb"
520 variables :name => name,
521 :log_directory => log_directory,
522 :rails_directory => rails_directory
525 file "/etc/logrotate.d/apis-#{name}" do
529 apache_site site_name do
533 service "cgimap@#{name}" do
534 action [:stop, :disable]
537 file "/etc/default/cgimap-#{name}" do
541 service "rails-jobs@#{name}" do
542 action [:stop, :disable]
545 directory site_directory do
550 file "/etc/cron.daily/rails-#{site_name.tr('.', '-')}" do
554 postgresql_database database_name do
561 directory "/srv/apis.dev.openstreetmap.org" do
567 template "/srv/apis.dev.openstreetmap.org/index.html" do
568 source "apis.html.erb"
574 ssl_certificate "apis.dev.openstreetmap.org" do
575 domains "apis.dev.openstreetmap.org"
576 notifies :reload, "service[apache2]"
579 apache_site "apis.dev.openstreetmap.org" do
580 template "apache.apis.erb"
584 directory "/srv/ooc.openstreetmap.org" do
590 remote_directory "/srv/ooc.openstreetmap.org/html" do
600 ssl_certificate "ooc.openstreetmap.org" do
601 domains ["ooc.openstreetmap.org",
602 "a.ooc.openstreetmap.org",
603 "b.ooc.openstreetmap.org",
604 "c.ooc.openstreetmap.org"]
605 notifies :reload, "service[apache2]"
608 apache_site "ooc.openstreetmap.org" do
609 template "apache.ooc.erb"
612 directory "/etc/systemd/system/user-.slice.d" do
618 template "/etc/systemd/system/user-.slice.d/99-chef.conf" do
619 source "user-slice.conf.erb"