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 "apache"
24 include_recipe "passenger"
25 include_recipe "geoipupdate"
27 include_recipe "memcached"
28 include_recipe "munin"
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
70 libbytes-random-secure-perl
146 # Add uk_os_OSTN15_NTv2_OSGBtoETRS.tif used for reprojecting OS data
147 execute "uk_os_OSTN15_NTv2_OSGBtoETRS.tif" do
148 command "projsync --file uk_os_OSTN15_NTv2_OSGBtoETRS.tif --system-directory"
149 not_if { ::File.exist?("/usr/share/proj/uk_os_OSTN15_NTv2_OSGBtoETRS.tif") }
152 nodejs_package "svgo"
154 python_package "geojson" do
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/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 execute "#{cgimap_directory}/autogen.sh" do
451 command "./autogen.sh"
455 subscribes :run, "git[#{cgimap_directory}]", :immediately
458 execute "#{cgimap_directory}/configure" do
460 command "./configure --with-fcgi=/usr --with-boost-libdir=/usr/lib/x86_64-linux-gnu --enable-yajl"
464 subscribes :run, "execute[#{cgimap_directory}/autogen.sh]", :immediately
467 execute "#{cgimap_directory}/Makefile" do
473 subscribes :run, "execute[#{cgimap_directory}/configure]", :immediately
476 template "/etc/default/cgimap-#{name}" do
477 source "cgimap.environment.erb"
481 variables :cgimap_socket => "/run/cgimap-#{name}/socket",
482 :database_port => node[:postgresql][:clusters][:"15/main"][:port],
483 :database_name => database_name,
484 :log_directory => log_directory,
485 :options => details[:cgimap_options]
488 service "cgimap@#{name}" do
489 action [:start, :enable]
490 subscribes :restart, "execute[#{cgimap_directory}/Makefile]"
491 subscribes :restart, "template[/etc/default/cgimap-#{name}]"
492 subscribes :restart, "systemd_service[cgimap@]"
496 ssl_certificate site_name do
497 domains [site_name] + site_aliases
498 notifies :reload, "service[apache2]"
501 apache_site site_name do
502 template "apache.rails.erb"
503 variables :application_name => name,
504 :aliases => site_aliases,
505 :secret_key_base => secret_key_base,
506 :cgimap_enabled => details.key?(:cgimap_repository),
507 :cgimap_socket => "/run/cgimap-#{name}/socket"
510 template "/etc/logrotate.d/apis-#{name}" do
511 source "logrotate.apis.erb"
515 variables :name => name,
516 :log_directory => log_directory,
517 :rails_directory => rails_directory
520 file "/etc/logrotate.d/apis-#{name}" do
524 apache_site site_name do
528 service "cgimap@#{name}" do
529 action [:stop, :disable]
532 file "/etc/default/cgimap-#{name}" do
536 service "rails-jobs@#{name}" do
537 action [:stop, :disable]
540 directory site_directory do
545 file "/etc/cron.daily/rails-#{site_name.tr('.', '-')}" do
549 postgresql_database database_name do
556 directory "/srv/apis.dev.openstreetmap.org" do
562 template "/srv/apis.dev.openstreetmap.org/index.html" do
563 source "apis.html.erb"
569 ssl_certificate "apis.dev.openstreetmap.org" do
570 domains "apis.dev.openstreetmap.org"
571 notifies :reload, "service[apache2]"
574 apache_site "apis.dev.openstreetmap.org" do
575 template "apache.apis.erb"
578 node[:postgresql][:clusters].each_key do |name|
579 postgresql_munin name do
586 directory "/srv/ooc.openstreetmap.org" do
592 remote_directory "/srv/ooc.openstreetmap.org/html" do
602 ssl_certificate "ooc.openstreetmap.org" do
603 domains ["ooc.openstreetmap.org",
604 "a.ooc.openstreetmap.org",
605 "b.ooc.openstreetmap.org",
606 "c.ooc.openstreetmap.org"]
607 notifies :reload, "service[apache2]"
610 apache_site "ooc.openstreetmap.org" do
611 template "apache.ooc.erb"
614 directory "/etc/systemd/system/user-.slice.d" do
620 template "/etc/systemd/system/user-.slice.d/99-chef.conf" do
621 source "user-slice.conf.erb"