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"
63 libboost-date-time-dev
65 libboost-filesystem-dev
67 libboost-program-options-dev
71 libbytes-random-secure-perl
150 # Add uk_os_OSTN15_NTv2_OSGBtoETRS.tif used for reprojecting OS data
151 execute "uk_os_OSTN15_NTv2_OSGBtoETRS.tif" do
152 command "projsync --file uk_os_OSTN15_NTv2_OSGBtoETRS.tif --system-directory"
153 not_if { ::File.exist?("/usr/share/proj/uk_os_OSTN15_NTv2_OSGBtoETRS.tif") }
156 nodejs_package "svgo"
159 apache_module "expires"
160 apache_module "headers"
161 apache_module "proxy"
162 apache_module "proxy_fcgi"
163 apache_module "rewrite"
164 apache_module "suexec"
165 apache_module "userdir"
167 apache_module "wsgi" do
168 package "libapache2-mod-wsgi-py3"
171 package "apache2-suexec-pristine"
176 pm_min_spare_servers 2
177 pm_max_spare_servers 6
184 directory "/srv/dev.openstreetmap.org" do
190 template "/srv/dev.openstreetmap.org/index.html" do
191 source "dev.html.erb"
197 ssl_certificate "dev.openstreetmap.org" do
198 domains "dev.openstreetmap.org"
199 notifies :reload, "service[apache2]"
202 apache_site "dev.openstreetmap.org" do
203 template "apache.dev.erb"
208 template "/etc/phppgadmin/config.inc.php" do
209 source "phppgadmin.conf.erb"
215 file "/etc/apache2/conf.d/phppgadmin" do
219 ssl_certificate "phppgadmin.dev.openstreetmap.org" do
220 domains "phppgadmin.dev.openstreetmap.org"
221 notifies :reload, "service[apache2]"
224 apache_site "phppgadmin.dev.openstreetmap.org" do
225 template "apache.phppgadmin.erb"
228 search(:accounts, "*:*").each do |account|
230 details = node[:accounts][:users][name] || {}
232 next unless %w[user administrator].include?(details[:status])
234 user_home = details[:home] || account["home"] || "#{node[:accounts][:home]}/#{name}"
236 next unless File.directory?("#{user_home}/public_html")
243 pm_min_spare_servers 2
244 pm_max_spare_servers 6
245 pm_max_requests 10000
246 request_terminate_timeout 1800
247 environment "HOSTNAME" => "$HOSTNAME",
248 "PATH" => "/usr/local/bin:/usr/bin:/bin",
252 php_values "max_execution_time" => "300",
253 "memory_limit" => "128M",
254 "post_max_size" => "32M",
255 "upload_max_filesize" => "32M"
256 php_admin_values "sendmail_path" => "/usr/sbin/sendmail -t -i -f #{name}@dev.openstreetmap.org",
257 "open_basedir" => "/home/#{name}/:/tmp/:/usr/share/php/"
258 php_flags "display_errors" => "on"
261 ssl_certificate "#{name}.dev.openstreetmap.org" do
262 domains ["#{name}.dev.openstreetmap.org", "#{name}.dev.osm.org"]
263 notifies :reload, "service[apache2]"
266 apache_site "#{name}.dev.openstreetmap.org" do
267 template "apache.user.erb"
268 directory "#{user_home}/public_html"
269 variables :user => name
272 template "/etc/sudoers.d/#{name}" do
273 source "sudoers.user.erb"
277 variables :user => name
281 node[:postgresql][:versions].each do |version|
282 package "postgresql-#{version}-postgis-3"
285 if node[:postgresql][:clusters][:"15/main"]
286 postgresql_user "apis" do
290 template "/usr/local/bin/cleanup-rails-assets" do
292 source "cleanup-assets.erb"
298 systemd_service "rails-jobs@" do
299 description "Rails job queue runner"
301 environment_file "/etc/default/rails-%i"
303 working_directory "/srv/%i.apis.dev.openstreetmap.org/rails"
304 exec_start "#{node[:ruby][:bundle]} exec rails jobs:work"
307 sandbox :enable_network => true
308 restrict_address_families "AF_UNIX"
309 memory_deny_write_execute false
311 "/srv/%i.apis.dev.openstreetmap.org/logs",
312 "/srv/%i.apis.dev.openstreetmap.org/rails/storage"
316 systemd_service "cgimap@" do
317 description "OpenStreetMap API Server"
319 environment_file "/etc/default/cgimap-%i"
323 exec_start "/srv/%i.apis.dev.openstreetmap.org/cgimap/build/openstreetmap-cgimap --daemon --instances 5"
324 exec_reload "/bin/kill -HUP $MAINPID"
325 runtime_directory "cgimap-%i"
326 sandbox :enable_network => true
327 restrict_address_families "AF_UNIX"
328 read_write_paths ["/srv/%i.apis.dev.openstreetmap.org/logs", "/srv/%i.apis.dev.openstreetmap.org/rails/tmp"]
332 Dir.glob("/srv/*.apis.dev.openstreetmap.org").each do |dir|
333 node.default_unless[:dev][:rails][File.basename(dir).split(".").first] = {}
336 node[:dev][:rails].each do |name, details|
337 database_name = details[:database] || "apis_#{name}"
338 site_name = "#{name}.apis.dev.openstreetmap.org"
339 site_directory = "/srv/#{name}.apis.dev.openstreetmap.org"
340 log_directory = "#{site_directory}/logs"
341 rails_directory = "#{site_directory}/rails"
342 cgimap_directory = "#{site_directory}/cgimap"
343 gpx_directory = "#{site_directory}/gpx"
345 if details[:repository]
346 site_aliases = details[:aliases] || []
347 secret_key_base = persistent_token("dev", "rails", name, "secret_key_base")
349 postgresql_database database_name do
354 postgresql_extension "#{database_name}_btree_gist" do
356 database database_name
357 extension "btree_gist"
360 directory site_directory do
366 directory log_directory do
372 directory gpx_directory do
378 directory "#{gpx_directory}/traces" do
384 directory "#{gpx_directory}/images" do
390 openssl_rsa_private_key "#{site_directory}/doorkeeper.key" do
396 rails_port site_name do
397 directory rails_directory
400 repository details[:repository]
401 revision details[:revision]
402 database_port node[:postgresql][:clusters][:"15/main"][:port]
403 database_name database_name
404 database_username "apis"
405 email_from "OpenStreetMap <web@noreply.openstreetmap.org>"
406 gpx_dir gpx_directory
407 log_path "#{log_directory}/rails.log"
408 memcache_servers ["127.0.0.1"]
411 trace_use_job_queue true
412 doorkeeper_signing_key lazy { File.read("#{site_directory}/doorkeeper.key") }
415 template "#{rails_directory}/config/initializers/setup.rb" do
416 source "rails.setup.rb.erb"
420 variables :site => site_name
421 notifies :restart, "rails_port[#{site_name}]"
424 template "/etc/default/rails-#{name}" do
425 source "rails.environment.erb"
429 variables :secret_key_base => secret_key_base
432 service "rails-jobs@#{name}" do
433 action [:enable, :start]
434 supports :restart => true
435 subscribes :restart, "rails_port[#{site_name}]"
436 subscribes :restart, "systemd_service[rails-jobs@]"
437 only_if "fgrep -q delayed_job #{rails_directory}/Gemfile.lock"
440 if details[:cgimap_repository]
441 git cgimap_directory do
443 repository details[:cgimap_repository]
444 revision details[:cgimap_revision]
449 directory "#{cgimap_directory}/build" do
455 execute "#{cgimap_directory}/CMakeLists.txt" do
458 cwd "#{cgimap_directory}/build"
461 subscribes :run, "git[#{cgimap_directory}]", :immediately
464 execute "#{cgimap_directory}/build/Makefile" do
467 cwd "#{cgimap_directory}/build"
470 subscribes :run, "execute[#{cgimap_directory}/CMakeLists.txt]", :immediately
473 template "/etc/default/cgimap-#{name}" do
474 source "cgimap.environment.erb"
478 variables :cgimap_socket => "/run/cgimap-#{name}/socket",
479 :database_port => node[:postgresql][:clusters][:"15/main"][:port],
480 :database_name => database_name,
481 :log_directory => log_directory,
482 :options => details[:cgimap_options]
485 service "cgimap@#{name}" do
486 action [:start, :enable]
487 subscribes :restart, "execute[#{cgimap_directory}/build/Makefile]"
488 subscribes :restart, "template[/etc/default/cgimap-#{name}]"
489 subscribes :restart, "systemd_service[cgimap@]"
493 ssl_certificate site_name do
494 domains [site_name] + site_aliases
495 notifies :reload, "service[apache2]"
498 apache_site site_name do
499 template "apache.rails.erb"
500 variables :application_name => name,
501 :aliases => site_aliases,
502 :secret_key_base => secret_key_base,
503 :cgimap_enabled => details.key?(:cgimap_repository),
504 :cgimap_socket => "/run/cgimap-#{name}/socket"
507 template "/etc/logrotate.d/apis-#{name}" do
508 source "logrotate.apis.erb"
512 variables :name => name,
513 :log_directory => log_directory,
514 :rails_directory => rails_directory
517 file "/etc/logrotate.d/apis-#{name}" do
521 apache_site site_name do
525 service "cgimap@#{name}" do
526 action [:stop, :disable]
529 file "/etc/default/cgimap-#{name}" do
533 service "rails-jobs@#{name}" do
534 action [:stop, :disable]
537 directory site_directory do
542 file "/etc/cron.daily/rails-#{site_name.tr('.', '-')}" do
546 postgresql_database database_name do
553 directory "/srv/apis.dev.openstreetmap.org" do
559 template "/srv/apis.dev.openstreetmap.org/index.html" do
560 source "apis.html.erb"
566 ssl_certificate "apis.dev.openstreetmap.org" do
567 domains "apis.dev.openstreetmap.org"
568 notifies :reload, "service[apache2]"
571 apache_site "apis.dev.openstreetmap.org" do
572 template "apache.apis.erb"
576 directory "/srv/ooc.openstreetmap.org" do
582 remote_directory "/srv/ooc.openstreetmap.org/html" do
592 ssl_certificate "ooc.openstreetmap.org" do
593 domains ["ooc.openstreetmap.org",
594 "a.ooc.openstreetmap.org",
595 "b.ooc.openstreetmap.org",
596 "c.ooc.openstreetmap.org"]
597 notifies :reload, "service[apache2]"
600 apache_site "ooc.openstreetmap.org" do
601 template "apache.ooc.erb"
604 directory "/etc/systemd/system/user-.slice.d" do
610 template "/etc/systemd/system/user-.slice.d/99-chef.conf" do
611 source "user-slice.conf.erb"