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"
321 exec_start "/srv/%i.apis.dev.openstreetmap.org/cgimap/openstreetmap-cgimap --daemon --port $CGIMAP_PORT --instances 5"
322 exec_reload "/bin/kill -HUP $MAINPID"
323 sandbox :enable_network => true
324 restrict_address_families "AF_UNIX"
325 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 execute "#{cgimap_directory}/autogen.sh" do
450 command "./autogen.sh"
454 subscribes :run, "git[#{cgimap_directory}]", :immediately
457 execute "#{cgimap_directory}/configure" do
459 command "./configure --with-fcgi=/usr --with-boost-libdir=/usr/lib/x86_64-linux-gnu --enable-yajl"
463 subscribes :run, "execute[#{cgimap_directory}/autogen.sh]", :immediately
466 execute "#{cgimap_directory}/Makefile" do
472 subscribes :run, "execute[#{cgimap_directory}/configure]", :immediately
475 template "/etc/default/cgimap-#{name}" do
476 source "cgimap.environment.erb"
480 variables :cgimap_port => cgimap_port,
481 :database_port => node[:postgresql][:clusters][:"15/main"][:port],
482 :database_name => database_name,
483 :log_directory => log_directory,
484 :options => details[:cgimap_options]
487 service "cgimap@#{name}" do
488 action [:start, :enable]
489 subscribes :restart, "execute[#{cgimap_directory}/Makefile]"
490 subscribes :restart, "template[/etc/default/cgimap-#{name}]"
491 subscribes :restart, "systemd_service[cgimap@]"
495 ssl_certificate site_name do
496 domains [site_name] + site_aliases
497 notifies :reload, "service[apache2]"
500 apache_site site_name do
501 template "apache.rails.erb"
502 variables :application_name => name,
503 :aliases => site_aliases,
504 :secret_key_base => secret_key_base,
505 :cgimap_enabled => details.key?(:cgimap_repository),
506 :cgimap_port => cgimap_port
509 template "/etc/logrotate.d/apis-#{name}" do
510 source "logrotate.apis.erb"
514 variables :name => name,
515 :log_directory => log_directory,
516 :rails_directory => rails_directory
521 file "/etc/logrotate.d/apis-#{name}" do
525 apache_site site_name do
529 service "cgimap@#{name}" do
530 action [:stop, :disable]
533 file "/etc/default/cgimap-#{name}" do
537 service "rails-jobs@#{name}" do
538 action [:stop, :disable]
541 directory site_directory do
546 file "/etc/cron.daily/rails-#{site_name.tr('.', '-')}" do
550 postgresql_database database_name do
557 directory "/srv/apis.dev.openstreetmap.org" do
563 template "/srv/apis.dev.openstreetmap.org/index.html" do
564 source "apis.html.erb"
570 ssl_certificate "apis.dev.openstreetmap.org" do
571 domains "apis.dev.openstreetmap.org"
572 notifies :reload, "service[apache2]"
575 apache_site "apis.dev.openstreetmap.org" do
576 template "apache.apis.erb"
579 node[:postgresql][:clusters].each_key do |name|
580 postgresql_munin name do
587 directory "/srv/ooc.openstreetmap.org" do
593 remote_directory "/srv/ooc.openstreetmap.org/html" do
603 ssl_certificate "ooc.openstreetmap.org" do
604 domains ["ooc.openstreetmap.org",
605 "a.ooc.openstreetmap.org",
606 "b.ooc.openstreetmap.org",
607 "c.ooc.openstreetmap.org"]
608 notifies :reload, "service[apache2]"
611 apache_site "ooc.openstreetmap.org" do
612 template "apache.ooc.erb"
615 directory "/etc/systemd/system/user-.slice.d" do
621 template "/etc/systemd/system/user-.slice.d/99-chef.conf" do
622 source "user-slice.conf.erb"