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
157 # Add uk_os_OSTN15_NTv2_OSGBtoETRS.tif used for reprojecting OS data
158 execute "uk_os_OSTN15_NTv2_OSGBtoETRS.tif" do
159 command "projsync --file uk_os_OSTN15_NTv2_OSGBtoETRS.tif --system-directory"
160 not_if { ::File.exist?("/usr/share/proj/uk_os_OSTN15_NTv2_OSGBtoETRS.tif") }
163 nodejs_package "svgo"
166 apache_module "expires"
167 apache_module "headers"
168 apache_module "proxy"
169 apache_module "proxy_fcgi"
170 apache_module "rewrite"
171 apache_module "suexec"
172 apache_module "userdir"
174 apache_module "wsgi" do
175 package "libapache2-mod-wsgi-py3"
178 package "apache2-suexec-pristine"
183 pm_min_spare_servers 2
184 pm_max_spare_servers 6
191 directory "/srv/dev.openstreetmap.org" do
197 template "/srv/dev.openstreetmap.org/index.html" do
198 source "dev.html.erb"
204 ssl_certificate "dev.openstreetmap.org" do
205 domains "dev.openstreetmap.org"
206 notifies :reload, "service[apache2]"
209 apache_site "dev.openstreetmap.org" do
210 template "apache.dev.erb"
215 template "/etc/phppgadmin/config.inc.php" do
216 source "phppgadmin.conf.erb"
222 file "/etc/apache2/conf.d/phppgadmin" do
226 ssl_certificate "phppgadmin.dev.openstreetmap.org" do
227 domains "phppgadmin.dev.openstreetmap.org"
228 notifies :reload, "service[apache2]"
231 apache_site "phppgadmin.dev.openstreetmap.org" do
232 template "apache.phppgadmin.erb"
235 search(:accounts, "*:*").each do |account|
237 details = node[:accounts][:users][name] || {}
239 next unless %w[user administrator].include?(details[:status])
241 user_home = details[:home] || account["home"] || "#{node[:accounts][:home]}/#{name}"
243 next unless File.directory?("#{user_home}/public_html")
250 pm_min_spare_servers 2
251 pm_max_spare_servers 6
252 pm_max_requests 10000
253 request_terminate_timeout 1800
254 environment "HOSTNAME" => "$HOSTNAME",
255 "PATH" => "/usr/local/bin:/usr/bin:/bin",
259 php_values "max_execution_time" => "300",
260 "memory_limit" => "128M",
261 "post_max_size" => "32M",
262 "upload_max_filesize" => "32M"
263 php_admin_values "sendmail_path" => "/usr/sbin/sendmail -t -i -f #{name}@dev.openstreetmap.org",
264 "open_basedir" => "/home/#{name}/:/tmp/:/usr/share/php/"
265 php_flags "display_errors" => "on"
268 ssl_certificate "#{name}.dev.openstreetmap.org" do
269 domains ["#{name}.dev.openstreetmap.org", "#{name}.dev.osm.org"]
270 notifies :reload, "service[apache2]"
273 apache_site "#{name}.dev.openstreetmap.org" do
274 template "apache.user.erb"
275 directory "#{user_home}/public_html"
276 variables :user => name
279 template "/etc/sudoers.d/#{name}" do
280 source "sudoers.user.erb"
284 variables :user => name
288 node[:postgresql][:versions].each do |version|
289 package "postgresql-#{version}-postgis-3"
292 if node[:postgresql][:clusters][:"15/main"]
293 postgresql_user "apis" do
297 template "/usr/local/bin/cleanup-rails-assets" do
299 source "cleanup-assets.erb"
305 systemd_service "rails-jobs@" do
306 description "Rails job queue runner"
308 environment_file "/etc/default/rails-%i"
310 working_directory "/srv/%i.apis.dev.openstreetmap.org/rails"
311 exec_start "#{node[:ruby][:bundle]} exec rails jobs:work"
314 sandbox :enable_network => true
315 restrict_address_families "AF_UNIX"
316 memory_deny_write_execute false
318 "/srv/%i.apis.dev.openstreetmap.org/logs",
319 "/srv/%i.apis.dev.openstreetmap.org/rails/storage"
323 systemd_service "cgimap@" do
324 description "OpenStreetMap API Server"
326 environment_file "/etc/default/cgimap-%i"
330 exec_start "/srv/%i.apis.dev.openstreetmap.org/cgimap/build/openstreetmap-cgimap --daemon --instances 5"
331 exec_reload "/bin/kill -HUP $MAINPID"
332 runtime_directory "cgimap-%i"
333 sandbox :enable_network => true
334 restrict_address_families "AF_UNIX"
335 read_write_paths ["/srv/%i.apis.dev.openstreetmap.org/logs", "/srv/%i.apis.dev.openstreetmap.org/rails/tmp"]
339 Dir.glob("/srv/*.apis.dev.openstreetmap.org").each do |dir|
340 node.default_unless[:dev][:rails][File.basename(dir).split(".").first] = {}
343 node[:dev][:rails].each do |name, details|
344 database_name = details[:database] || "apis_#{name}"
345 site_name = "#{name}.apis.dev.openstreetmap.org"
346 site_directory = "/srv/#{name}.apis.dev.openstreetmap.org"
347 log_directory = "#{site_directory}/logs"
348 rails_directory = "#{site_directory}/rails"
349 cgimap_directory = "#{site_directory}/cgimap"
350 gpx_directory = "#{site_directory}/gpx"
352 if details[:repository]
353 site_aliases = details[:aliases] || []
354 secret_key_base = persistent_token("dev", "rails", name, "secret_key_base")
356 postgresql_database database_name do
361 postgresql_extension "#{database_name}_btree_gist" do
363 database database_name
364 extension "btree_gist"
367 directory site_directory do
373 directory log_directory do
379 directory gpx_directory do
385 directory "#{gpx_directory}/traces" do
391 directory "#{gpx_directory}/images" do
397 openssl_rsa_private_key "#{site_directory}/doorkeeper.key" do
403 rails_port site_name do
404 directory rails_directory
407 repository details[:repository]
408 revision details[:revision]
409 database_port node[:postgresql][:clusters][:"15/main"][:port]
410 database_name database_name
411 database_username "apis"
412 email_from "OpenStreetMap <web@noreply.openstreetmap.org>"
413 gpx_dir gpx_directory
414 log_path "#{log_directory}/rails.log"
415 memcache_servers ["127.0.0.1"]
418 trace_use_job_queue true
419 doorkeeper_signing_key lazy { File.read("#{site_directory}/doorkeeper.key") }
422 template "#{rails_directory}/config/initializers/setup.rb" do
423 source "rails.setup.rb.erb"
427 variables :site => site_name
428 notifies :restart, "rails_port[#{site_name}]"
431 template "/etc/default/rails-#{name}" do
432 source "rails.environment.erb"
436 variables :secret_key_base => secret_key_base
439 service "rails-jobs@#{name}" do
440 action [:enable, :start]
441 supports :restart => true
442 subscribes :restart, "rails_port[#{site_name}]"
443 subscribes :restart, "systemd_service[rails-jobs@]"
444 only_if "fgrep -q delayed_job #{rails_directory}/Gemfile.lock"
447 if details[:cgimap_repository]
448 git cgimap_directory do
450 repository details[:cgimap_repository]
451 revision details[:cgimap_revision]
456 directory "#{cgimap_directory}/build" do
462 execute "#{cgimap_directory}/CMakeLists.txt" do
465 cwd "#{cgimap_directory}/build"
468 subscribes :run, "git[#{cgimap_directory}]", :immediately
471 execute "#{cgimap_directory}/build/Makefile" do
474 cwd "#{cgimap_directory}/build"
477 subscribes :run, "execute[#{cgimap_directory}/CMakeLists.txt]", :immediately
480 template "/etc/default/cgimap-#{name}" do
481 source "cgimap.environment.erb"
485 variables :cgimap_socket => "/run/cgimap-#{name}/socket",
486 :database_port => node[:postgresql][:clusters][:"15/main"][:port],
487 :database_name => database_name,
488 :log_directory => log_directory,
489 :options => details[:cgimap_options]
492 service "cgimap@#{name}" do
493 action [:start, :enable]
494 subscribes :restart, "execute[#{cgimap_directory}/build/Makefile]"
495 subscribes :restart, "template[/etc/default/cgimap-#{name}]"
496 subscribes :restart, "systemd_service[cgimap@]"
500 ssl_certificate site_name do
501 domains [site_name] + site_aliases
502 notifies :reload, "service[apache2]"
505 apache_site site_name do
506 template "apache.rails.erb"
507 variables :application_name => name,
508 :aliases => site_aliases,
509 :secret_key_base => secret_key_base,
510 :cgimap_enabled => details.key?(:cgimap_repository),
511 :cgimap_socket => "/run/cgimap-#{name}/socket"
514 template "/etc/logrotate.d/apis-#{name}" do
515 source "logrotate.apis.erb"
519 variables :name => name,
520 :log_directory => log_directory,
521 :rails_directory => rails_directory
524 file "/etc/logrotate.d/apis-#{name}" do
528 apache_site site_name do
532 service "cgimap@#{name}" do
533 action [:stop, :disable]
536 file "/etc/default/cgimap-#{name}" do
540 service "rails-jobs@#{name}" do
541 action [:stop, :disable]
544 directory site_directory do
549 file "/etc/cron.daily/rails-#{site_name.tr('.', '-')}" do
553 postgresql_database database_name do
560 directory "/srv/apis.dev.openstreetmap.org" do
566 template "/srv/apis.dev.openstreetmap.org/index.html" do
567 source "apis.html.erb"
573 ssl_certificate "apis.dev.openstreetmap.org" do
574 domains "apis.dev.openstreetmap.org"
575 notifies :reload, "service[apache2]"
578 apache_site "apis.dev.openstreetmap.org" do
579 template "apache.apis.erb"
583 directory "/srv/ooc.openstreetmap.org" do
589 remote_directory "/srv/ooc.openstreetmap.org/html" do
599 ssl_certificate "ooc.openstreetmap.org" do
600 domains ["ooc.openstreetmap.org",
601 "a.ooc.openstreetmap.org",
602 "b.ooc.openstreetmap.org",
603 "c.ooc.openstreetmap.org"]
604 notifies :reload, "service[apache2]"
607 apache_site "ooc.openstreetmap.org" do
608 template "apache.ooc.erb"
611 directory "/etc/systemd/system/user-.slice.d" do
617 template "/etc/systemd/system/user-.slice.d/99-chef.conf" do
618 source "user-slice.conf.erb"