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
153 # Unavailable on debian 12
156 >>>>>>> d9d12032 (Install wine on dev server to run windows-only utils)
162 # Add uk_os_OSTN15_NTv2_OSGBtoETRS.tif used for reprojecting OS data
163 execute "uk_os_OSTN15_NTv2_OSGBtoETRS.tif" do
164 command "projsync --file uk_os_OSTN15_NTv2_OSGBtoETRS.tif --system-directory"
165 not_if { ::File.exist?("/usr/share/proj/uk_os_OSTN15_NTv2_OSGBtoETRS.tif") }
168 nodejs_package "svgo"
171 apache_module "expires"
172 apache_module "headers"
173 apache_module "proxy"
174 apache_module "proxy_fcgi"
175 apache_module "rewrite"
176 apache_module "suexec"
177 apache_module "userdir"
179 apache_module "wsgi" do
180 package "libapache2-mod-wsgi-py3"
183 package "apache2-suexec-pristine"
188 pm_min_spare_servers 2
189 pm_max_spare_servers 6
196 directory "/srv/dev.openstreetmap.org" do
202 template "/srv/dev.openstreetmap.org/index.html" do
203 source "dev.html.erb"
209 ssl_certificate "dev.openstreetmap.org" do
210 domains "dev.openstreetmap.org"
211 notifies :reload, "service[apache2]"
214 apache_site "dev.openstreetmap.org" do
215 template "apache.dev.erb"
220 template "/etc/phppgadmin/config.inc.php" do
221 source "phppgadmin.conf.erb"
227 file "/etc/apache2/conf.d/phppgadmin" do
231 ssl_certificate "phppgadmin.dev.openstreetmap.org" do
232 domains "phppgadmin.dev.openstreetmap.org"
233 notifies :reload, "service[apache2]"
236 apache_site "phppgadmin.dev.openstreetmap.org" do
237 template "apache.phppgadmin.erb"
240 search(:accounts, "*:*").each do |account|
242 details = node[:accounts][:users][name] || {}
244 next unless %w[user administrator].include?(details[:status])
246 user_home = details[:home] || account["home"] || "#{node[:accounts][:home]}/#{name}"
248 next unless File.directory?("#{user_home}/public_html")
255 pm_min_spare_servers 2
256 pm_max_spare_servers 6
257 pm_max_requests 10000
258 request_terminate_timeout 1800
259 environment "HOSTNAME" => "$HOSTNAME",
260 "PATH" => "/usr/local/bin:/usr/bin:/bin",
264 php_values "max_execution_time" => "300",
265 "memory_limit" => "128M",
266 "post_max_size" => "32M",
267 "upload_max_filesize" => "32M"
268 php_admin_values "sendmail_path" => "/usr/sbin/sendmail -t -i -f #{name}@dev.openstreetmap.org",
269 "open_basedir" => "/home/#{name}/:/tmp/:/usr/share/php/"
270 php_flags "display_errors" => "on"
273 ssl_certificate "#{name}.dev.openstreetmap.org" do
274 domains ["#{name}.dev.openstreetmap.org", "#{name}.dev.osm.org"]
275 notifies :reload, "service[apache2]"
278 apache_site "#{name}.dev.openstreetmap.org" do
279 template "apache.user.erb"
280 directory "#{user_home}/public_html"
281 variables :user => name
284 template "/etc/sudoers.d/#{name}" do
285 source "sudoers.user.erb"
289 variables :user => name
293 node[:postgresql][:versions].each do |version|
294 package "postgresql-#{version}-postgis-3"
297 if node[:postgresql][:clusters][:"15/main"]
298 postgresql_user "apis" do
302 template "/usr/local/bin/cleanup-rails-assets" do
304 source "cleanup-assets.erb"
310 systemd_service "rails-jobs@" do
311 description "Rails job queue runner"
313 environment_file "/etc/default/rails-%i"
315 working_directory "/srv/%i.apis.dev.openstreetmap.org/rails"
316 exec_start "#{node[:ruby][:bundle]} exec rails jobs:work"
319 sandbox :enable_network => true
320 restrict_address_families "AF_UNIX"
321 memory_deny_write_execute false
323 "/srv/%i.apis.dev.openstreetmap.org/logs",
324 "/srv/%i.apis.dev.openstreetmap.org/rails/storage"
328 systemd_service "cgimap@" do
329 description "OpenStreetMap API Server"
331 environment_file "/etc/default/cgimap-%i"
335 exec_start "/srv/%i.apis.dev.openstreetmap.org/cgimap/build/openstreetmap-cgimap --daemon --instances 5"
336 exec_reload "/bin/kill -HUP $MAINPID"
337 runtime_directory "cgimap-%i"
338 sandbox :enable_network => true
339 restrict_address_families "AF_UNIX"
340 read_write_paths ["/srv/%i.apis.dev.openstreetmap.org/logs", "/srv/%i.apis.dev.openstreetmap.org/rails/tmp"]
344 Dir.glob("/srv/*.apis.dev.openstreetmap.org").each do |dir|
345 node.default_unless[:dev][:rails][File.basename(dir).split(".").first] = {}
348 node[:dev][:rails].each do |name, details|
349 database_name = details[:database] || "apis_#{name}"
350 site_name = "#{name}.apis.dev.openstreetmap.org"
351 site_directory = "/srv/#{name}.apis.dev.openstreetmap.org"
352 log_directory = "#{site_directory}/logs"
353 rails_directory = "#{site_directory}/rails"
354 cgimap_directory = "#{site_directory}/cgimap"
355 gpx_directory = "#{site_directory}/gpx"
357 if details[:repository]
358 site_aliases = details[:aliases] || []
359 secret_key_base = persistent_token("dev", "rails", name, "secret_key_base")
361 postgresql_database database_name do
366 postgresql_extension "#{database_name}_btree_gist" do
368 database database_name
369 extension "btree_gist"
372 directory site_directory do
378 directory log_directory do
384 directory gpx_directory do
390 directory "#{gpx_directory}/traces" do
396 directory "#{gpx_directory}/images" do
402 openssl_rsa_private_key "#{site_directory}/doorkeeper.key" do
408 rails_port site_name do
409 directory rails_directory
412 repository details[:repository]
413 revision details[:revision]
414 database_port node[:postgresql][:clusters][:"15/main"][:port]
415 database_name database_name
416 database_username "apis"
417 email_from "OpenStreetMap <web@noreply.openstreetmap.org>"
418 gpx_dir gpx_directory
419 log_path "#{log_directory}/rails.log"
420 memcache_servers ["127.0.0.1"]
423 trace_use_job_queue true
424 doorkeeper_signing_key lazy { File.read("#{site_directory}/doorkeeper.key") }
427 template "#{rails_directory}/config/initializers/setup.rb" do
428 source "rails.setup.rb.erb"
432 variables :site => site_name
433 notifies :restart, "rails_port[#{site_name}]"
436 template "/etc/default/rails-#{name}" do
437 source "rails.environment.erb"
441 variables :secret_key_base => secret_key_base
444 service "rails-jobs@#{name}" do
445 action [:enable, :start]
446 supports :restart => true
447 subscribes :restart, "rails_port[#{site_name}]"
448 subscribes :restart, "systemd_service[rails-jobs@]"
449 only_if "fgrep -q delayed_job #{rails_directory}/Gemfile.lock"
452 if details[:cgimap_repository]
453 git cgimap_directory do
455 repository details[:cgimap_repository]
456 revision details[:cgimap_revision]
461 directory "#{cgimap_directory}/build" do
467 execute "#{cgimap_directory}/CMakeLists.txt" do
470 cwd "#{cgimap_directory}/build"
473 subscribes :run, "git[#{cgimap_directory}]", :immediately
476 execute "#{cgimap_directory}/build/Makefile" do
479 cwd "#{cgimap_directory}/build"
482 subscribes :run, "execute[#{cgimap_directory}/CMakeLists.txt]", :immediately
485 template "/etc/default/cgimap-#{name}" do
486 source "cgimap.environment.erb"
490 variables :cgimap_socket => "/run/cgimap-#{name}/socket",
491 :database_port => node[:postgresql][:clusters][:"15/main"][:port],
492 :database_name => database_name,
493 :log_directory => log_directory,
494 :options => details[:cgimap_options]
497 service "cgimap@#{name}" do
498 action [:start, :enable]
499 subscribes :restart, "execute[#{cgimap_directory}/build/Makefile]"
500 subscribes :restart, "template[/etc/default/cgimap-#{name}]"
501 subscribes :restart, "systemd_service[cgimap@]"
505 ssl_certificate site_name do
506 domains [site_name] + site_aliases
507 notifies :reload, "service[apache2]"
510 apache_site site_name do
511 template "apache.rails.erb"
512 variables :application_name => name,
513 :aliases => site_aliases,
514 :secret_key_base => secret_key_base,
515 :cgimap_enabled => details.key?(:cgimap_repository),
516 :cgimap_socket => "/run/cgimap-#{name}/socket"
519 template "/etc/logrotate.d/apis-#{name}" do
520 source "logrotate.apis.erb"
524 variables :name => name,
525 :log_directory => log_directory,
526 :rails_directory => rails_directory
529 file "/etc/logrotate.d/apis-#{name}" do
533 apache_site site_name do
537 service "cgimap@#{name}" do
538 action [:stop, :disable]
541 file "/etc/default/cgimap-#{name}" do
545 service "rails-jobs@#{name}" do
546 action [:stop, :disable]
549 directory site_directory do
554 file "/etc/cron.daily/rails-#{site_name.tr('.', '-')}" do
558 postgresql_database database_name do
565 directory "/srv/apis.dev.openstreetmap.org" do
571 template "/srv/apis.dev.openstreetmap.org/index.html" do
572 source "apis.html.erb"
578 ssl_certificate "apis.dev.openstreetmap.org" do
579 domains "apis.dev.openstreetmap.org"
580 notifies :reload, "service[apache2]"
583 apache_site "apis.dev.openstreetmap.org" do
584 template "apache.apis.erb"
588 directory "/srv/ooc.openstreetmap.org" do
594 remote_directory "/srv/ooc.openstreetmap.org/html" do
604 ssl_certificate "ooc.openstreetmap.org" do
605 domains ["ooc.openstreetmap.org",
606 "a.ooc.openstreetmap.org",
607 "b.ooc.openstreetmap.org",
608 "c.ooc.openstreetmap.org"]
609 notifies :reload, "service[apache2]"
612 apache_site "ooc.openstreetmap.org" do
613 template "apache.ooc.erb"
616 directory "/etc/systemd/system/user-.slice.d" do
622 template "/etc/systemd/system/user-.slice.d/99-chef.conf" do
623 source "user-slice.conf.erb"