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 "postgresql"
33 include_recipe "python"
65 libboost-date-time-dev
67 libboost-filesystem-dev
69 libboost-program-options-dev
73 libbytes-random-secure-perl
152 # Add uk_os_OSTN15_NTv2_OSGBtoETRS.tif used for reprojecting OS data
153 execute "uk_os_OSTN15_NTv2_OSGBtoETRS.tif" do
154 command "projsync --file uk_os_OSTN15_NTv2_OSGBtoETRS.tif --system-directory"
155 not_if { ::File.exist?("/usr/share/proj/uk_os_OSTN15_NTv2_OSGBtoETRS.tif") }
158 nodejs_package "svgo"
161 apache_module "expires"
162 apache_module "headers"
163 apache_module "proxy"
164 apache_module "proxy_fcgi"
165 apache_module "rewrite"
166 apache_module "suexec"
167 apache_module "userdir"
169 apache_module "wsgi" do
170 package "libapache2-mod-wsgi-py3"
173 package "apache2-suexec-pristine"
178 pm_min_spare_servers 2
179 pm_max_spare_servers 6
186 directory "/srv/dev.openstreetmap.org" do
192 template "/srv/dev.openstreetmap.org/index.html" do
193 source "dev.html.erb"
199 ssl_certificate "dev.openstreetmap.org" do
200 domains "dev.openstreetmap.org"
201 notifies :reload, "service[apache2]"
204 apache_site "dev.openstreetmap.org" do
205 template "apache.dev.erb"
210 template "/etc/phppgadmin/config.inc.php" do
211 source "phppgadmin.conf.erb"
217 file "/etc/apache2/conf.d/phppgadmin" do
221 ssl_certificate "phppgadmin.dev.openstreetmap.org" do
222 domains "phppgadmin.dev.openstreetmap.org"
223 notifies :reload, "service[apache2]"
226 apache_site "phppgadmin.dev.openstreetmap.org" do
227 template "apache.phppgadmin.erb"
230 search(:accounts, "*:*").each do |account|
232 details = node[:accounts][:users][name] || {}
234 next unless %w[user administrator].include?(details[:status])
236 user_home = details[:home] || account["home"] || "#{node[:accounts][:home]}/#{name}"
238 next unless File.directory?("#{user_home}/public_html")
245 pm_min_spare_servers 2
246 pm_max_spare_servers 6
247 pm_max_requests 10000
248 request_terminate_timeout 1800
249 environment "HOSTNAME" => "$HOSTNAME",
250 "PATH" => "/usr/local/bin:/usr/bin:/bin",
254 php_values "max_execution_time" => "300",
255 "memory_limit" => "128M",
256 "post_max_size" => "32M",
257 "upload_max_filesize" => "32M"
258 php_admin_values "sendmail_path" => "/usr/sbin/sendmail -t -i -f #{name}@dev.openstreetmap.org",
259 "open_basedir" => "/home/#{name}/:/tmp/:/usr/share/php/"
260 php_flags "display_errors" => "on"
263 ssl_certificate "#{name}.dev.openstreetmap.org" do
264 domains ["#{name}.dev.openstreetmap.org", "#{name}.dev.osm.org"]
265 notifies :reload, "service[apache2]"
268 apache_site "#{name}.dev.openstreetmap.org" do
269 template "apache.user.erb"
270 directory "#{user_home}/public_html"
271 variables :user => name
274 template "/etc/sudoers.d/#{name}" do
275 source "sudoers.user.erb"
279 variables :user => name
283 node[:postgresql][:versions].each do |version|
284 package "postgresql-#{version}-postgis-3"
287 if node[:postgresql][:clusters][:"15/main"]
288 postgresql_user "apis" do
292 template "/usr/local/bin/cleanup-rails-assets" do
294 source "cleanup-assets.erb"
300 systemd_service "rails-jobs@" do
301 description "Rails job queue runner"
303 environment_file "/etc/default/rails-%i"
305 working_directory "/srv/%i.apis.dev.openstreetmap.org/rails"
306 exec_start "#{node[:ruby][:bundle]} exec rails jobs:work"
309 sandbox :enable_network => true
310 restrict_address_families "AF_UNIX"
311 memory_deny_write_execute false
313 "/srv/%i.apis.dev.openstreetmap.org/logs",
314 "/srv/%i.apis.dev.openstreetmap.org/rails/storage"
318 systemd_service "cgimap@" do
319 description "OpenStreetMap API Server"
321 environment_file "/etc/default/cgimap-%i"
325 exec_start "/srv/%i.apis.dev.openstreetmap.org/cgimap/build/openstreetmap-cgimap --daemon --instances 5"
326 exec_reload "/bin/kill -HUP $MAINPID"
327 runtime_directory "cgimap-%i"
328 sandbox :enable_network => true
329 restrict_address_families "AF_UNIX"
330 read_write_paths ["/srv/%i.apis.dev.openstreetmap.org/logs", "/srv/%i.apis.dev.openstreetmap.org/rails/tmp"]
334 Dir.glob("/srv/*.apis.dev.openstreetmap.org").each do |dir|
335 node.default_unless[:dev][:rails][File.basename(dir).split(".").first] = {}
338 node[:dev][:rails].each do |name, details|
339 database_name = details[:database] || "apis_#{name}"
340 site_name = "#{name}.apis.dev.openstreetmap.org"
341 site_directory = "/srv/#{name}.apis.dev.openstreetmap.org"
342 log_directory = "#{site_directory}/logs"
343 rails_directory = "#{site_directory}/rails"
344 cgimap_directory = "#{site_directory}/cgimap"
345 gpx_directory = "#{site_directory}/gpx"
347 if details[:repository]
348 site_aliases = details[:aliases] || []
349 secret_key_base = persistent_token("dev", "rails", name, "secret_key_base")
351 postgresql_database database_name do
356 postgresql_extension "#{database_name}_btree_gist" do
358 database database_name
359 extension "btree_gist"
362 directory site_directory do
368 directory log_directory do
374 directory gpx_directory do
380 directory "#{gpx_directory}/traces" do
386 directory "#{gpx_directory}/images" do
392 openssl_rsa_private_key "#{site_directory}/doorkeeper.key" do
398 rails_port site_name do
399 directory rails_directory
402 repository details[:repository]
403 revision details[:revision]
404 database_port node[:postgresql][:clusters][:"15/main"][:port]
405 database_name database_name
406 database_username "apis"
407 email_from "OpenStreetMap <web@noreply.openstreetmap.org>"
408 gpx_dir gpx_directory
409 log_path "#{log_directory}/rails.log"
410 memcache_servers ["127.0.0.1"]
413 trace_use_job_queue true
414 doorkeeper_signing_key lazy { File.read("#{site_directory}/doorkeeper.key") }
417 template "#{rails_directory}/config/initializers/setup.rb" do
418 source "rails.setup.rb.erb"
422 variables :site => site_name
423 notifies :restart, "rails_port[#{site_name}]"
426 template "/etc/default/rails-#{name}" do
427 source "rails.environment.erb"
431 variables :secret_key_base => secret_key_base
434 service "rails-jobs@#{name}" do
435 action [:enable, :start]
436 supports :restart => true
437 subscribes :restart, "rails_port[#{site_name}]"
438 subscribes :restart, "systemd_service[rails-jobs@]"
439 only_if "fgrep -q delayed_job #{rails_directory}/Gemfile.lock"
442 if details[:cgimap_repository]
443 git cgimap_directory do
445 repository details[:cgimap_repository]
446 revision details[:cgimap_revision]
451 directory "#{cgimap_directory}/build" do
457 execute "#{cgimap_directory}/CMakeLists.txt" do
460 cwd "#{cgimap_directory}/build"
463 subscribes :run, "git[#{cgimap_directory}]", :immediately
466 execute "#{cgimap_directory}/build/Makefile" do
469 cwd "#{cgimap_directory}/build"
472 subscribes :run, "execute[#{cgimap_directory}/CMakeLists.txt]", :immediately
475 template "/etc/default/cgimap-#{name}" do
476 source "cgimap.environment.erb"
480 variables :cgimap_socket => "/run/cgimap-#{name}/socket",
481 :database_port => node[:postgresql][:clusters][:"15/main"][:port],
482 :database_name => database_name,
483 :log_directory => log_directory,
484 :options => details[:cgimap_options]
487 service "cgimap@#{name}" do
488 action [:start, :enable]
489 subscribes :restart, "execute[#{cgimap_directory}/build/Makefile]"
490 subscribes :restart, "template[/etc/default/cgimap-#{name}]"
491 subscribes :restart, "systemd_service[cgimap@]"
495 ssl_certificate site_name do
496 domains [site_name] + site_aliases
497 notifies :reload, "service[apache2]"
500 apache_site site_name do
501 template "apache.rails.erb"
502 variables :application_name => name,
503 :aliases => site_aliases,
504 :secret_key_base => secret_key_base,
505 :cgimap_enabled => details.key?(:cgimap_repository),
506 :cgimap_socket => "/run/cgimap-#{name}/socket"
509 template "/etc/logrotate.d/apis-#{name}" do
510 source "logrotate.apis.erb"
514 variables :name => name,
515 :log_directory => log_directory,
516 :rails_directory => rails_directory
519 file "/etc/logrotate.d/apis-#{name}" do
523 apache_site site_name do
527 service "cgimap@#{name}" do
528 action [:stop, :disable]
531 file "/etc/default/cgimap-#{name}" do
535 service "rails-jobs@#{name}" do
536 action [:stop, :disable]
539 directory site_directory do
544 file "/etc/cron.daily/rails-#{site_name.tr('.', '-')}" do
548 postgresql_database database_name do
555 directory "/srv/apis.dev.openstreetmap.org" do
561 template "/srv/apis.dev.openstreetmap.org/index.html" do
562 source "apis.html.erb"
568 ssl_certificate "apis.dev.openstreetmap.org" do
569 domains "apis.dev.openstreetmap.org"
570 notifies :reload, "service[apache2]"
573 apache_site "apis.dev.openstreetmap.org" do
574 template "apache.apis.erb"
578 directory "/srv/ooc.openstreetmap.org" do
584 remote_directory "/srv/ooc.openstreetmap.org/html" do
594 ssl_certificate "ooc.openstreetmap.org" do
595 domains ["ooc.openstreetmap.org",
596 "a.ooc.openstreetmap.org",
597 "b.ooc.openstreetmap.org",
598 "c.ooc.openstreetmap.org"]
599 notifies :reload, "service[apache2]"
602 apache_site "ooc.openstreetmap.org" do
603 template "apache.ooc.erb"
606 directory "/etc/systemd/system/user-.slice.d" do
612 template "/etc/systemd/system/user-.slice.d/99-chef.conf" do
613 source "user-slice.conf.erb"