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
155 # Add uk_os_OSTN15_NTv2_OSGBtoETRS.tif used for reprojecting OS data
156 execute "uk_os_OSTN15_NTv2_OSGBtoETRS.tif" do
157 command "projsync --file uk_os_OSTN15_NTv2_OSGBtoETRS.tif --system-directory"
158 not_if { ::File.exist?("/usr/share/proj/uk_os_OSTN15_NTv2_OSGBtoETRS.tif") }
161 nodejs_package "svgo"
164 apache_module "expires"
165 apache_module "headers"
166 apache_module "proxy"
167 apache_module "proxy_fcgi"
168 apache_module "rewrite"
169 apache_module "suexec"
170 apache_module "userdir"
172 apache_module "wsgi" do
173 package "libapache2-mod-wsgi-py3"
176 package "apache2-suexec-pristine"
181 pm_min_spare_servers 2
182 pm_max_spare_servers 6
189 directory "/srv/dev.openstreetmap.org" do
195 template "/srv/dev.openstreetmap.org/index.html" do
196 source "dev.html.erb"
202 ssl_certificate "dev.openstreetmap.org" do
203 domains "dev.openstreetmap.org"
204 notifies :reload, "service[apache2]"
207 apache_site "dev.openstreetmap.org" do
208 template "apache.dev.erb"
213 template "/etc/phppgadmin/config.inc.php" do
214 source "phppgadmin.conf.erb"
220 file "/etc/apache2/conf.d/phppgadmin" do
224 ssl_certificate "phppgadmin.dev.openstreetmap.org" do
225 domains "phppgadmin.dev.openstreetmap.org"
226 notifies :reload, "service[apache2]"
229 apache_site "phppgadmin.dev.openstreetmap.org" do
230 template "apache.phppgadmin.erb"
233 search(:accounts, "*:*").each do |account|
235 details = node[:accounts][:users][name] || {}
237 next unless %w[user administrator].include?(details[:status])
239 user_home = details[:home] || account["home"] || "#{node[:accounts][:home]}/#{name}"
241 next unless File.directory?("#{user_home}/public_html")
248 pm_min_spare_servers 2
249 pm_max_spare_servers 6
250 pm_max_requests 10000
251 request_terminate_timeout 1800
252 environment "HOSTNAME" => "$HOSTNAME",
253 "PATH" => "/usr/local/bin:/usr/bin:/bin",
257 php_values "max_execution_time" => "300",
258 "memory_limit" => "128M",
259 "post_max_size" => "32M",
260 "upload_max_filesize" => "32M"
261 php_admin_values "sendmail_path" => "/usr/sbin/sendmail -t -i -f #{name}@dev.openstreetmap.org",
262 "open_basedir" => "/home/#{name}/:/tmp/:/usr/share/php/"
263 php_flags "display_errors" => "on"
266 ssl_certificate "#{name}.dev.openstreetmap.org" do
267 domains ["#{name}.dev.openstreetmap.org", "#{name}.dev.osm.org"]
268 notifies :reload, "service[apache2]"
271 apache_site "#{name}.dev.openstreetmap.org" do
272 template "apache.user.erb"
273 directory "#{user_home}/public_html"
274 variables :user => name
277 template "/etc/sudoers.d/#{name}" do
278 source "sudoers.user.erb"
282 variables :user => name
286 node[:postgresql][:versions].each do |version|
287 package "postgresql-#{version}-postgis-3"
290 if node[:postgresql][:clusters][:"15/main"]
291 postgresql_user "apis" do
295 template "/usr/local/bin/cleanup-rails-assets" do
297 source "cleanup-assets.erb"
303 systemd_service "rails-jobs@" do
304 description "Rails job queue runner"
306 environment_file "/etc/default/rails-%i"
308 working_directory "/srv/%i.apis.dev.openstreetmap.org/rails"
309 exec_start "#{node[:ruby][:bundle]} exec rails jobs:work"
312 sandbox :enable_network => true
313 restrict_address_families "AF_UNIX"
314 memory_deny_write_execute false
316 "/srv/%i.apis.dev.openstreetmap.org/logs",
317 "/srv/%i.apis.dev.openstreetmap.org/rails/storage"
321 systemd_service "cgimap@" do
322 description "OpenStreetMap API Server"
324 environment_file "/etc/default/cgimap-%i"
328 exec_start "/srv/%i.apis.dev.openstreetmap.org/cgimap/build/openstreetmap-cgimap --daemon --instances 5"
329 exec_reload "/bin/kill -HUP $MAINPID"
330 runtime_directory "cgimap-%i"
331 sandbox :enable_network => true
332 restrict_address_families "AF_UNIX"
333 read_write_paths ["/srv/%i.apis.dev.openstreetmap.org/logs", "/srv/%i.apis.dev.openstreetmap.org/rails/tmp"]
337 Dir.glob("/srv/*.apis.dev.openstreetmap.org").each do |dir|
338 node.default_unless[:dev][:rails][File.basename(dir).split(".").first] = {}
341 node[:dev][:rails].each do |name, details|
342 database_name = details[:database] || "apis_#{name}"
343 site_name = "#{name}.apis.dev.openstreetmap.org"
344 site_directory = "/srv/#{name}.apis.dev.openstreetmap.org"
345 log_directory = "#{site_directory}/logs"
346 rails_directory = "#{site_directory}/rails"
347 cgimap_directory = "#{site_directory}/cgimap"
348 gpx_directory = "#{site_directory}/gpx"
350 if details[:repository]
351 site_aliases = details[:aliases] || []
352 secret_key_base = persistent_token("dev", "rails", name, "secret_key_base")
354 postgresql_database database_name do
359 postgresql_extension "#{database_name}_btree_gist" do
361 database database_name
362 extension "btree_gist"
365 directory site_directory do
371 directory log_directory do
377 directory gpx_directory do
383 directory "#{gpx_directory}/traces" do
389 directory "#{gpx_directory}/images" do
395 openssl_rsa_private_key "#{site_directory}/doorkeeper.key" do
401 rails_port site_name do
402 directory rails_directory
405 repository details[:repository]
406 revision details[:revision]
407 database_port node[:postgresql][:clusters][:"15/main"][:port]
408 database_name database_name
409 database_username "apis"
410 email_from "OpenStreetMap <web@noreply.openstreetmap.org>"
411 gpx_dir gpx_directory
412 log_path "#{log_directory}/rails.log"
413 memcache_servers ["127.0.0.1"]
416 trace_use_job_queue true
417 doorkeeper_signing_key lazy { File.read("#{site_directory}/doorkeeper.key") }
420 template "#{rails_directory}/config/initializers/setup.rb" do
421 source "rails.setup.rb.erb"
425 variables :site => site_name
426 notifies :restart, "rails_port[#{site_name}]"
429 template "/etc/default/rails-#{name}" do
430 source "rails.environment.erb"
434 variables :secret_key_base => secret_key_base
437 service "rails-jobs@#{name}" do
438 action [:enable, :start]
439 supports :restart => true
440 subscribes :restart, "rails_port[#{site_name}]"
441 subscribes :restart, "systemd_service[rails-jobs@]"
442 only_if "fgrep -q delayed_job #{rails_directory}/Gemfile.lock"
445 if details[:cgimap_repository]
446 git cgimap_directory do
448 repository details[:cgimap_repository]
449 revision details[:cgimap_revision]
454 directory "#{cgimap_directory}/build" do
460 execute "#{cgimap_directory}/CMakeLists.txt" do
463 cwd "#{cgimap_directory}/build"
466 subscribes :run, "git[#{cgimap_directory}]", :immediately
469 execute "#{cgimap_directory}/build/Makefile" do
472 cwd "#{cgimap_directory}/build"
475 subscribes :run, "execute[#{cgimap_directory}/CMakeLists.txt]", :immediately
478 template "/etc/default/cgimap-#{name}" do
479 source "cgimap.environment.erb"
483 variables :cgimap_socket => "/run/cgimap-#{name}/socket",
484 :database_port => node[:postgresql][:clusters][:"15/main"][:port],
485 :database_name => database_name,
486 :log_directory => log_directory,
487 :options => details[:cgimap_options]
490 service "cgimap@#{name}" do
491 action [:start, :enable]
492 subscribes :restart, "execute[#{cgimap_directory}/build/Makefile]"
493 subscribes :restart, "template[/etc/default/cgimap-#{name}]"
494 subscribes :restart, "systemd_service[cgimap@]"
498 ssl_certificate site_name do
499 domains [site_name] + site_aliases
500 notifies :reload, "service[apache2]"
503 apache_site site_name do
504 template "apache.rails.erb"
505 variables :application_name => name,
506 :aliases => site_aliases,
507 :secret_key_base => secret_key_base,
508 :cgimap_enabled => details.key?(:cgimap_repository),
509 :cgimap_socket => "/run/cgimap-#{name}/socket"
512 template "/etc/logrotate.d/apis-#{name}" do
513 source "logrotate.apis.erb"
517 variables :name => name,
518 :log_directory => log_directory,
519 :rails_directory => rails_directory
522 file "/etc/logrotate.d/apis-#{name}" do
526 apache_site site_name do
530 service "cgimap@#{name}" do
531 action [:stop, :disable]
534 file "/etc/default/cgimap-#{name}" do
538 service "rails-jobs@#{name}" do
539 action [:stop, :disable]
542 directory site_directory do
547 file "/etc/cron.daily/rails-#{site_name.tr('.', '-')}" do
551 postgresql_database database_name do
558 directory "/srv/apis.dev.openstreetmap.org" do
564 template "/srv/apis.dev.openstreetmap.org/index.html" do
565 source "apis.html.erb"
571 ssl_certificate "apis.dev.openstreetmap.org" do
572 domains "apis.dev.openstreetmap.org"
573 notifies :reload, "service[apache2]"
576 apache_site "apis.dev.openstreetmap.org" do
577 template "apache.apis.erb"
581 directory "/srv/ooc.openstreetmap.org" do
587 remote_directory "/srv/ooc.openstreetmap.org/html" do
597 ssl_certificate "ooc.openstreetmap.org" do
598 domains ["ooc.openstreetmap.org",
599 "a.ooc.openstreetmap.org",
600 "b.ooc.openstreetmap.org",
601 "c.ooc.openstreetmap.org"]
602 notifies :reload, "service[apache2]"
605 apache_site "ooc.openstreetmap.org" do
606 template "apache.ooc.erb"
609 directory "/etc/systemd/system/user-.slice.d" do
615 template "/etc/systemd/system/user-.slice.d/99-chef.conf" do
616 source "user-slice.conf.erb"