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
154 # Add uk_os_OSTN15_NTv2_OSGBtoETRS.tif used for reprojecting OS data
155 execute "uk_os_OSTN15_NTv2_OSGBtoETRS.tif" do
156 command "projsync --file uk_os_OSTN15_NTv2_OSGBtoETRS.tif --system-directory"
157 not_if { ::File.exist?("/usr/share/proj/uk_os_OSTN15_NTv2_OSGBtoETRS.tif") }
160 nodejs_package "svgo"
163 apache_module "expires"
164 apache_module "headers"
165 apache_module "proxy"
166 apache_module "proxy_fcgi"
167 apache_module "rewrite"
168 apache_module "suexec"
169 apache_module "userdir"
171 apache_module "wsgi" do
172 package "libapache2-mod-wsgi-py3"
175 package "apache2-suexec-pristine"
180 pm_min_spare_servers 2
181 pm_max_spare_servers 6
188 directory "/srv/dev.openstreetmap.org" do
194 template "/srv/dev.openstreetmap.org/index.html" do
195 source "dev.html.erb"
201 ssl_certificate "dev.openstreetmap.org" do
202 domains "dev.openstreetmap.org"
203 notifies :reload, "service[apache2]"
206 apache_site "dev.openstreetmap.org" do
207 template "apache.dev.erb"
212 template "/etc/phppgadmin/config.inc.php" do
213 source "phppgadmin.conf.erb"
219 file "/etc/apache2/conf.d/phppgadmin" do
223 ssl_certificate "phppgadmin.dev.openstreetmap.org" do
224 domains "phppgadmin.dev.openstreetmap.org"
225 notifies :reload, "service[apache2]"
228 apache_site "phppgadmin.dev.openstreetmap.org" do
229 template "apache.phppgadmin.erb"
232 search(:accounts, "*:*").each do |account|
234 details = node[:accounts][:users][name] || {}
236 next unless %w[user administrator].include?(details[:status])
238 user_home = details[:home] || account["home"] || "#{node[:accounts][:home]}/#{name}"
240 next unless File.directory?("#{user_home}/public_html")
247 pm_min_spare_servers 2
248 pm_max_spare_servers 6
249 pm_max_requests 10000
250 request_terminate_timeout 1800
251 environment "HOSTNAME" => "$HOSTNAME",
252 "PATH" => "/usr/local/bin:/usr/bin:/bin",
256 php_values "max_execution_time" => "300",
257 "memory_limit" => "128M",
258 "post_max_size" => "32M",
259 "upload_max_filesize" => "32M"
260 php_admin_values "sendmail_path" => "/usr/sbin/sendmail -t -i -f #{name}@dev.openstreetmap.org",
261 "open_basedir" => "/home/#{name}/:/tmp/:/usr/share/php/"
262 php_flags "display_errors" => "on"
265 ssl_certificate "#{name}.dev.openstreetmap.org" do
266 domains ["#{name}.dev.openstreetmap.org", "#{name}.dev.osm.org"]
267 notifies :reload, "service[apache2]"
270 apache_site "#{name}.dev.openstreetmap.org" do
271 template "apache.user.erb"
272 directory "#{user_home}/public_html"
273 variables :user => name
276 template "/etc/sudoers.d/#{name}" do
277 source "sudoers.user.erb"
281 variables :user => name
285 node[:postgresql][:versions].each do |version|
286 package "postgresql-#{version}-postgis-3"
289 if node[:postgresql][:clusters][:"15/main"]
290 postgresql_user "apis" do
294 template "/usr/local/bin/cleanup-rails-assets" do
296 source "cleanup-assets.erb"
302 systemd_service "rails-jobs@" do
303 description "Rails job queue runner"
305 environment_file "/etc/default/rails-%i"
307 working_directory "/srv/%i.apis.dev.openstreetmap.org/rails"
308 exec_start "#{node[:ruby][:bundle]} exec rails jobs:work"
311 sandbox :enable_network => true
312 restrict_address_families "AF_UNIX"
313 memory_deny_write_execute false
315 "/srv/%i.apis.dev.openstreetmap.org/logs",
316 "/srv/%i.apis.dev.openstreetmap.org/rails/storage"
320 systemd_service "cgimap@" do
321 description "OpenStreetMap API Server"
323 environment_file "/etc/default/cgimap-%i"
327 exec_start "/srv/%i.apis.dev.openstreetmap.org/cgimap/build/openstreetmap-cgimap --daemon --instances 5"
328 exec_reload "/bin/kill -HUP $MAINPID"
329 runtime_directory "cgimap-%i"
330 sandbox :enable_network => true
331 restrict_address_families "AF_UNIX"
332 read_write_paths ["/srv/%i.apis.dev.openstreetmap.org/logs", "/srv/%i.apis.dev.openstreetmap.org/rails/tmp"]
336 Dir.glob("/srv/*.apis.dev.openstreetmap.org").each do |dir|
337 node.default_unless[:dev][:rails][File.basename(dir).split(".").first] = {}
340 node[:dev][:rails].each do |name, details|
341 database_name = details[:database] || "apis_#{name}"
342 site_name = "#{name}.apis.dev.openstreetmap.org"
343 site_directory = "/srv/#{name}.apis.dev.openstreetmap.org"
344 log_directory = "#{site_directory}/logs"
345 rails_directory = "#{site_directory}/rails"
346 cgimap_directory = "#{site_directory}/cgimap"
347 gpx_directory = "#{site_directory}/gpx"
349 if details[:repository]
350 site_aliases = details[:aliases] || []
351 secret_key_base = persistent_token("dev", "rails", name, "secret_key_base")
353 postgresql_database database_name do
358 postgresql_extension "#{database_name}_btree_gist" do
360 database database_name
361 extension "btree_gist"
364 directory site_directory do
370 directory log_directory do
376 directory gpx_directory do
382 directory "#{gpx_directory}/traces" do
388 directory "#{gpx_directory}/images" do
394 openssl_rsa_private_key "#{site_directory}/doorkeeper.key" do
400 rails_port site_name do
401 directory rails_directory
404 repository details[:repository]
405 revision details[:revision]
406 database_port node[:postgresql][:clusters][:"15/main"][:port]
407 database_name database_name
408 database_username "apis"
409 email_from "OpenStreetMap <web@noreply.openstreetmap.org>"
410 gpx_dir gpx_directory
411 log_path "#{log_directory}/rails.log"
412 memcache_servers ["127.0.0.1"]
415 trace_use_job_queue true
416 doorkeeper_signing_key lazy { File.read("#{site_directory}/doorkeeper.key") }
419 template "#{rails_directory}/config/initializers/setup.rb" do
420 source "rails.setup.rb.erb"
424 variables :site => site_name
425 notifies :restart, "rails_port[#{site_name}]"
428 template "/etc/default/rails-#{name}" do
429 source "rails.environment.erb"
433 variables :secret_key_base => secret_key_base
436 service "rails-jobs@#{name}" do
437 action [:enable, :start]
438 supports :restart => true
439 subscribes :restart, "rails_port[#{site_name}]"
440 subscribes :restart, "systemd_service[rails-jobs@]"
441 only_if "fgrep -q delayed_job #{rails_directory}/Gemfile.lock"
444 if details[:cgimap_repository]
445 git cgimap_directory do
447 repository details[:cgimap_repository]
448 revision details[:cgimap_revision]
453 directory "#{cgimap_directory}/build" do
459 execute "#{cgimap_directory}/CMakeLists.txt" do
462 cwd "#{cgimap_directory}/build"
465 subscribes :run, "git[#{cgimap_directory}]", :immediately
468 execute "#{cgimap_directory}/build/Makefile" do
471 cwd "#{cgimap_directory}/build"
474 subscribes :run, "execute[#{cgimap_directory}/CMakeLists.txt]", :immediately
477 template "/etc/default/cgimap-#{name}" do
478 source "cgimap.environment.erb"
482 variables :cgimap_socket => "/run/cgimap-#{name}/socket",
483 :database_port => node[:postgresql][:clusters][:"15/main"][:port],
484 :database_name => database_name,
485 :log_directory => log_directory,
486 :options => details[:cgimap_options]
489 service "cgimap@#{name}" do
490 action [:start, :enable]
491 subscribes :restart, "execute[#{cgimap_directory}/build/Makefile]"
492 subscribes :restart, "template[/etc/default/cgimap-#{name}]"
493 subscribes :restart, "systemd_service[cgimap@]"
497 ssl_certificate site_name do
498 domains [site_name] + site_aliases
499 notifies :reload, "service[apache2]"
502 apache_site site_name do
503 template "apache.rails.erb"
504 variables :application_name => name,
505 :aliases => site_aliases,
506 :secret_key_base => secret_key_base,
507 :cgimap_enabled => details.key?(:cgimap_repository),
508 :cgimap_socket => "/run/cgimap-#{name}/socket"
511 template "/etc/logrotate.d/apis-#{name}" do
512 source "logrotate.apis.erb"
516 variables :name => name,
517 :log_directory => log_directory,
518 :rails_directory => rails_directory
521 file "/etc/logrotate.d/apis-#{name}" do
525 apache_site site_name do
529 service "cgimap@#{name}" do
530 action [:stop, :disable]
533 file "/etc/default/cgimap-#{name}" do
537 service "rails-jobs@#{name}" do
538 action [:stop, :disable]
541 directory site_directory do
546 file "/etc/cron.daily/rails-#{site_name.tr('.', '-')}" do
550 postgresql_database database_name do
557 directory "/srv/apis.dev.openstreetmap.org" do
563 template "/srv/apis.dev.openstreetmap.org/index.html" do
564 source "apis.html.erb"
570 ssl_certificate "apis.dev.openstreetmap.org" do
571 domains "apis.dev.openstreetmap.org"
572 notifies :reload, "service[apache2]"
575 apache_site "apis.dev.openstreetmap.org" do
576 template "apache.apis.erb"
580 directory "/srv/ooc.openstreetmap.org" do
586 remote_directory "/srv/ooc.openstreetmap.org/html" do
596 ssl_certificate "ooc.openstreetmap.org" do
597 domains ["ooc.openstreetmap.org",
598 "a.ooc.openstreetmap.org",
599 "b.ooc.openstreetmap.org",
600 "c.ooc.openstreetmap.org"]
601 notifies :reload, "service[apache2]"
604 apache_site "ooc.openstreetmap.org" do
605 template "apache.ooc.erb"
608 directory "/etc/systemd/system/user-.slice.d" do
614 template "/etc/systemd/system/user-.slice.d/99-chef.conf" do
615 source "user-slice.conf.erb"