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 "mysql"
29 include_recipe "nodejs"
30 include_recipe "php::fpm"
31 include_recipe "postgresql"
32 include_recipe "python"
62 libboost-date-time-dev
64 libboost-filesystem-dev
66 libboost-program-options-dev
69 libbytes-random-secure-perl
145 # Add uk_os_OSTN15_NTv2_OSGBtoETRS.tif used for reprojecting OS data
146 execute "uk_os_OSTN15_NTv2_OSGBtoETRS.tif" do
147 command "projsync --file uk_os_OSTN15_NTv2_OSGBtoETRS.tif --system-directory"
148 not_if { ::File.exist?("/usr/share/proj/uk_os_OSTN15_NTv2_OSGBtoETRS.tif") }
151 nodejs_package "svgo"
153 python_package "geojson" do
158 apache_module "expires"
159 apache_module "headers"
160 apache_module "proxy"
161 apache_module "proxy_fcgi"
162 apache_module "rewrite"
163 apache_module "suexec"
164 apache_module "userdir"
166 apache_module "wsgi" do
167 package "libapache2-mod-wsgi-py3"
170 package "apache2-suexec-pristine"
175 pm_min_spare_servers 2
176 pm_max_spare_servers 6
183 directory "/srv/dev.openstreetmap.org" do
189 template "/srv/dev.openstreetmap.org/index.html" do
190 source "dev.html.erb"
196 ssl_certificate "dev.openstreetmap.org" do
197 domains "dev.openstreetmap.org"
198 notifies :reload, "service[apache2]"
201 apache_site "dev.openstreetmap.org" do
202 template "apache.dev.erb"
207 template "/etc/phppgadmin/config.inc.php" do
208 source "phppgadmin.conf.erb"
214 file "/etc/apache2/conf.d/phppgadmin" do
218 ssl_certificate "phppgadmin.dev.openstreetmap.org" do
219 domains "phppgadmin.dev.openstreetmap.org"
220 notifies :reload, "service[apache2]"
223 apache_site "phppgadmin.dev.openstreetmap.org" do
224 template "apache.phppgadmin.erb"
227 search(:accounts, "*:*").each do |account|
229 details = node[:accounts][:users][name] || {}
231 next unless %w[user administrator].include?(details[:status])
233 user_home = details[:home] || account["home"] || "#{node[:accounts][:home]}/#{name}"
235 next unless File.directory?("#{user_home}/public_html")
242 pm_min_spare_servers 2
243 pm_max_spare_servers 6
244 pm_max_requests 10000
245 request_terminate_timeout 1800
246 environment "HOSTNAME" => "$HOSTNAME",
247 "PATH" => "/usr/local/bin:/usr/bin:/bin",
251 php_values "max_execution_time" => "300",
252 "memory_limit" => "128M",
253 "post_max_size" => "32M",
254 "upload_max_filesize" => "32M"
255 php_admin_values "sendmail_path" => "/usr/sbin/sendmail -t -i -f #{name}@dev.openstreetmap.org",
256 "open_basedir" => "/home/#{name}/:/tmp/:/usr/share/php/"
257 php_flags "display_errors" => "on"
260 ssl_certificate "#{name}.dev.openstreetmap.org" do
261 domains ["#{name}.dev.openstreetmap.org", "#{name}.dev.osm.org"]
262 notifies :reload, "service[apache2]"
265 apache_site "#{name}.dev.openstreetmap.org" do
266 template "apache.user.erb"
267 directory "#{user_home}/public_html"
268 variables :user => name
271 template "/etc/sudoers.d/#{name}" do
272 source "sudoers.user.erb"
276 variables :user => name
280 node[:postgresql][:versions].each do |version|
281 package "postgresql-#{version}-postgis-3"
284 if node[:postgresql][:clusters][:"15/main"]
285 postgresql_user "apis" do
289 template "/usr/local/bin/cleanup-rails-assets" do
291 source "cleanup-assets.erb"
297 systemd_service "rails-jobs@" do
298 description "Rails job queue runner"
300 environment_file "/etc/default/rails-%i"
302 working_directory "/srv/%i.apis.dev.openstreetmap.org/rails"
303 exec_start "#{node[:ruby][:bundle]} exec rails jobs:work"
306 sandbox :enable_network => true
307 restrict_address_families "AF_UNIX"
308 memory_deny_write_execute false
310 "/srv/%i.apis.dev.openstreetmap.org/logs",
311 "/srv/%i.apis.dev.openstreetmap.org/rails/storage"
315 systemd_service "cgimap@" do
316 description "OpenStreetMap API Server"
318 environment_file "/etc/default/cgimap-%i"
322 exec_start "/srv/%i.apis.dev.openstreetmap.org/cgimap/build/openstreetmap-cgimap --daemon --instances 5"
323 exec_reload "/bin/kill -HUP $MAINPID"
324 runtime_directory "cgimap-%i"
325 sandbox :enable_network => true
326 restrict_address_families "AF_UNIX"
327 read_write_paths ["/srv/%i.apis.dev.openstreetmap.org/logs", "/srv/%i.apis.dev.openstreetmap.org/rails/tmp"]
331 Dir.glob("/srv/*.apis.dev.openstreetmap.org").each do |dir|
332 node.default_unless[:dev][:rails][File.basename(dir).split(".").first] = {}
335 node[:dev][:rails].each do |name, details|
336 database_name = details[:database] || "apis_#{name}"
337 site_name = "#{name}.apis.dev.openstreetmap.org"
338 site_directory = "/srv/#{name}.apis.dev.openstreetmap.org"
339 log_directory = "#{site_directory}/logs"
340 rails_directory = "#{site_directory}/rails"
341 cgimap_directory = "#{site_directory}/cgimap"
342 gpx_directory = "#{site_directory}/gpx"
344 if details[:repository]
345 site_aliases = details[:aliases] || []
346 secret_key_base = persistent_token("dev", "rails", name, "secret_key_base")
348 postgresql_database database_name do
353 postgresql_extension "#{database_name}_btree_gist" do
355 database database_name
356 extension "btree_gist"
359 directory site_directory do
365 directory log_directory do
371 directory gpx_directory do
377 directory "#{gpx_directory}/traces" do
383 directory "#{gpx_directory}/images" do
389 openssl_rsa_private_key "#{site_directory}/doorkeeper.key" do
395 rails_port site_name do
396 directory rails_directory
399 repository details[:repository]
400 revision details[:revision]
401 database_port node[:postgresql][:clusters][:"15/main"][:port]
402 database_name database_name
403 database_username "apis"
404 email_from "OpenStreetMap <web@noreply.openstreetmap.org>"
405 gpx_dir gpx_directory
406 log_path "#{log_directory}/rails.log"
407 memcache_servers ["127.0.0.1"]
410 trace_use_job_queue true
411 doorkeeper_signing_key lazy { File.read("#{site_directory}/doorkeeper.key") }
414 template "#{rails_directory}/config/initializers/setup.rb" do
415 source "rails.setup.rb.erb"
419 variables :site => site_name
420 notifies :restart, "rails_port[#{site_name}]"
423 template "/etc/default/rails-#{name}" do
424 source "rails.environment.erb"
428 variables :secret_key_base => secret_key_base
431 service "rails-jobs@#{name}" do
432 action [:enable, :start]
433 supports :restart => true
434 subscribes :restart, "rails_port[#{site_name}]"
435 subscribes :restart, "systemd_service[rails-jobs@]"
436 only_if "fgrep -q delayed_job #{rails_directory}/Gemfile.lock"
439 if details[:cgimap_repository]
440 git cgimap_directory do
442 repository details[:cgimap_repository]
443 revision details[:cgimap_revision]
448 directory "#{cgimap_directory}/build" do
454 execute "#{cgimap_directory}/CMakeLists.txt" do
457 cwd "#{cgimap_directory}/build"
460 subscribes :run, "git[#{cgimap_directory}]", :immediately
463 execute "#{cgimap_directory}/build/Makefile" do
466 cwd "#{cgimap_directory}/build"
469 subscribes :run, "execute[#{cgimap_directory}/CMakeLists.txt]", :immediately
472 template "/etc/default/cgimap-#{name}" do
473 source "cgimap.environment.erb"
477 variables :cgimap_socket => "/run/cgimap-#{name}/socket",
478 :database_port => node[:postgresql][:clusters][:"15/main"][:port],
479 :database_name => database_name,
480 :log_directory => log_directory,
481 :options => details[:cgimap_options]
484 service "cgimap@#{name}" do
485 action [:start, :enable]
486 subscribes :restart, "execute[#{cgimap_directory}/build/Makefile]"
487 subscribes :restart, "template[/etc/default/cgimap-#{name}]"
488 subscribes :restart, "systemd_service[cgimap@]"
492 ssl_certificate site_name do
493 domains [site_name] + site_aliases
494 notifies :reload, "service[apache2]"
497 apache_site site_name do
498 template "apache.rails.erb"
499 variables :application_name => name,
500 :aliases => site_aliases,
501 :secret_key_base => secret_key_base,
502 :cgimap_enabled => details.key?(:cgimap_repository),
503 :cgimap_socket => "/run/cgimap-#{name}/socket"
506 template "/etc/logrotate.d/apis-#{name}" do
507 source "logrotate.apis.erb"
511 variables :name => name,
512 :log_directory => log_directory,
513 :rails_directory => rails_directory
516 file "/etc/logrotate.d/apis-#{name}" do
520 apache_site site_name do
524 service "cgimap@#{name}" do
525 action [:stop, :disable]
528 file "/etc/default/cgimap-#{name}" do
532 service "rails-jobs@#{name}" do
533 action [:stop, :disable]
536 directory site_directory do
541 file "/etc/cron.daily/rails-#{site_name.tr('.', '-')}" do
545 postgresql_database database_name do
552 directory "/srv/apis.dev.openstreetmap.org" do
558 template "/srv/apis.dev.openstreetmap.org/index.html" do
559 source "apis.html.erb"
565 ssl_certificate "apis.dev.openstreetmap.org" do
566 domains "apis.dev.openstreetmap.org"
567 notifies :reload, "service[apache2]"
570 apache_site "apis.dev.openstreetmap.org" do
571 template "apache.apis.erb"
575 directory "/srv/ooc.openstreetmap.org" do
581 remote_directory "/srv/ooc.openstreetmap.org/html" do
591 ssl_certificate "ooc.openstreetmap.org" do
592 domains ["ooc.openstreetmap.org",
593 "a.ooc.openstreetmap.org",
594 "b.ooc.openstreetmap.org",
595 "c.ooc.openstreetmap.org"]
596 notifies :reload, "service[apache2]"
599 apache_site "ooc.openstreetmap.org" do
600 template "apache.ooc.erb"
603 directory "/etc/systemd/system/user-.slice.d" do
609 template "/etc/systemd/system/user-.slice.d/99-chef.conf" do
610 source "user-slice.conf.erb"