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
144 # Add uk_os_OSTN15_NTv2_OSGBtoETRS.tif used for reprojecting OS data
145 execute "uk_os_OSTN15_NTv2_OSGBtoETRS.tif" do
146 command "projsync --file uk_os_OSTN15_NTv2_OSGBtoETRS.tif --system-directory"
147 not_if { ::File.exist?("/usr/share/proj/uk_os_OSTN15_NTv2_OSGBtoETRS.tif") }
150 nodejs_package "svgo"
152 python_package "geojson" do
157 apache_module "expires"
158 apache_module "headers"
159 apache_module "proxy"
160 apache_module "proxy_fcgi"
161 apache_module "rewrite"
162 apache_module "suexec"
163 apache_module "userdir"
165 apache_module "wsgi" do
166 package "libapache2-mod-wsgi-py3"
169 package "apache2-suexec-pristine"
174 pm_min_spare_servers 2
175 pm_max_spare_servers 6
182 directory "/srv/dev.openstreetmap.org" do
188 template "/srv/dev.openstreetmap.org/index.html" do
189 source "dev.html.erb"
195 ssl_certificate "dev.openstreetmap.org" do
196 domains "dev.openstreetmap.org"
197 notifies :reload, "service[apache2]"
200 apache_site "dev.openstreetmap.org" do
201 template "apache.dev.erb"
206 template "/etc/phppgadmin/config.inc.php" do
207 source "phppgadmin.conf.erb"
213 file "/etc/apache2/conf.d/phppgadmin" do
217 ssl_certificate "phppgadmin.dev.openstreetmap.org" do
218 domains "phppgadmin.dev.openstreetmap.org"
219 notifies :reload, "service[apache2]"
222 apache_site "phppgadmin.dev.openstreetmap.org" do
223 template "apache.phppgadmin.erb"
226 search(:accounts, "*:*").each do |account|
228 details = node[:accounts][:users][name] || {}
230 next unless %w[user administrator].include?(details[:status])
232 user_home = details[:home] || account["home"] || "#{node[:accounts][:home]}/#{name}"
234 next unless File.directory?("#{user_home}/public_html")
241 pm_min_spare_servers 2
242 pm_max_spare_servers 6
243 pm_max_requests 10000
244 request_terminate_timeout 1800
245 environment "HOSTNAME" => "$HOSTNAME",
246 "PATH" => "/usr/local/bin:/usr/bin:/bin",
250 php_values "max_execution_time" => "300",
251 "memory_limit" => "128M",
252 "post_max_size" => "32M",
253 "upload_max_filesize" => "32M"
254 php_admin_values "sendmail_path" => "/usr/sbin/sendmail -t -i -f #{name}@dev.openstreetmap.org",
255 "open_basedir" => "/home/#{name}/:/tmp/:/usr/share/php/"
256 php_flags "display_errors" => "on"
259 ssl_certificate "#{name}.dev.openstreetmap.org" do
260 domains ["#{name}.dev.openstreetmap.org", "#{name}.dev.osm.org"]
261 notifies :reload, "service[apache2]"
264 apache_site "#{name}.dev.openstreetmap.org" do
265 template "apache.user.erb"
266 directory "#{user_home}/public_html"
267 variables :user => name
270 template "/etc/sudoers.d/#{name}" do
271 source "sudoers.user.erb"
275 variables :user => name
279 node[:postgresql][:versions].each do |version|
280 package "postgresql-#{version}-postgis-3"
283 if node[:postgresql][:clusters][:"15/main"]
284 postgresql_user "apis" do
288 template "/usr/local/bin/cleanup-rails-assets" do
290 source "cleanup-assets.erb"
296 systemd_service "rails-jobs@" do
297 description "Rails job queue runner"
299 environment "RAILS_ENV" => "production", "SLEEP_DELAY" => "60"
301 working_directory "/srv/%i.apis.dev.openstreetmap.org/rails"
302 exec_start "#{node[:ruby][:bundle]} exec rails jobs:work"
305 sandbox :enable_network => true
306 restrict_address_families "AF_UNIX"
307 memory_deny_write_execute false
309 "/srv/%i.apis.dev.openstreetmap.org/logs",
310 "/srv/%i.apis.dev.openstreetmap.org/rails/storage"
314 systemd_service "cgimap@" do
315 description "OpenStreetMap API Server"
317 environment_file "/etc/default/cgimap-%i"
319 exec_start "/srv/%i.apis.dev.openstreetmap.org/cgimap/openstreetmap-cgimap --daemon --port $CGIMAP_PORT --instances 5"
320 exec_reload "/bin/kill -HUP $MAINPID"
321 sandbox :enable_network => true
322 restrict_address_families "AF_UNIX"
323 read_write_paths ["/srv/%i.apis.dev.openstreetmap.org/logs", "/srv/%i.apis.dev.openstreetmap.org/rails/tmp"]
329 Dir.glob("/srv/*.apis.dev.openstreetmap.org").each do |dir|
330 node.default_unless[:dev][:rails][File.basename(dir).split(".").first] = {}
333 node[:dev][:rails].each do |name, details|
334 database_name = details[:database] || "apis_#{name}"
335 site_name = "#{name}.apis.dev.openstreetmap.org"
336 site_directory = "/srv/#{name}.apis.dev.openstreetmap.org"
337 log_directory = "#{site_directory}/logs"
338 rails_directory = "#{site_directory}/rails"
339 cgimap_directory = "#{site_directory}/cgimap"
340 gpx_directory = "#{site_directory}/gpx"
342 if details[:repository]
343 site_aliases = details[:aliases] || []
344 secret_key_base = persistent_token("dev", "rails", name, "secret_key_base")
346 postgresql_database database_name do
351 postgresql_extension "#{database_name}_btree_gist" do
353 database database_name
354 extension "btree_gist"
357 directory site_directory do
363 directory log_directory do
369 directory gpx_directory do
375 directory "#{gpx_directory}/traces" do
381 directory "#{gpx_directory}/images" do
387 rails_port site_name do
388 directory rails_directory
391 repository details[:repository]
392 revision details[:revision]
393 database_port node[:postgresql][:clusters][:"15/main"][:port]
394 database_name database_name
395 database_username "apis"
396 email_from "OpenStreetMap <web@noreply.openstreetmap.org>"
397 gpx_dir gpx_directory
398 log_path "#{log_directory}/rails.log"
399 memcache_servers ["127.0.0.1"]
402 trace_use_job_queue true
405 template "#{rails_directory}/config/initializers/setup.rb" do
406 source "rails.setup.rb.erb"
410 variables :site => site_name
411 notifies :restart, "rails_port[#{site_name}]"
414 service "rails-jobs@#{name}" do
415 action [:enable, :start]
416 supports :restart => true
417 subscribes :restart, "rails_port[#{site_name}]"
418 subscribes :restart, "systemd_service[rails-jobs@]"
419 only_if "fgrep -q delayed_job #{rails_directory}/Gemfile.lock"
422 if details[:cgimap_repository]
423 git cgimap_directory do
425 repository details[:cgimap_repository]
426 revision details[:cgimap_revision]
431 execute "#{cgimap_directory}/autogen.sh" do
433 command "./autogen.sh"
437 subscribes :run, "git[#{cgimap_directory}]", :immediately
440 execute "#{cgimap_directory}/configure" do
442 command "./configure --with-fcgi=/usr --with-boost-libdir=/usr/lib/x86_64-linux-gnu --enable-yajl"
446 subscribes :run, "execute[#{cgimap_directory}/autogen.sh]", :immediately
449 execute "#{cgimap_directory}/Makefile" do
455 subscribes :run, "execute[#{cgimap_directory}/configure]", :immediately
458 template "/etc/default/cgimap-#{name}" do
459 source "cgimap.environment.erb"
463 variables :cgimap_port => cgimap_port,
464 :database_port => node[:postgresql][:clusters][:"15/main"][:port],
465 :database_name => database_name,
466 :log_directory => log_directory
469 service "cgimap@#{name}" do
470 action [:start, :enable]
471 subscribes :restart, "execute[#{cgimap_directory}/Makefile]"
472 subscribes :restart, "template[/etc/default/cgimap-#{name}]"
473 subscribes :restart, "systemd_service[cgimap@]"
477 ssl_certificate site_name do
478 domains [site_name] + site_aliases
479 notifies :reload, "service[apache2]"
482 apache_site site_name do
483 template "apache.rails.erb"
484 variables :application_name => name,
485 :aliases => site_aliases,
486 :secret_key_base => secret_key_base,
487 :cgimap_enabled => details.key?(:cgimap_repository),
488 :cgimap_port => cgimap_port
491 template "/etc/logrotate.d/apis-#{name}" do
492 source "logrotate.apis.erb"
496 variables :name => name,
497 :log_directory => log_directory,
498 :rails_directory => rails_directory
503 file "/etc/logrotate.d/apis-#{name}" do
507 apache_site site_name do
511 service "cgimap@#{name}" do
512 action [:stop, :disable]
515 file "/etc/default/cgimap-#{name}" do
519 service "rails-jobs@#{name}" do
520 action [:stop, :disable]
523 directory site_directory do
528 file "/etc/cron.daily/rails-#{site_name.tr('.', '-')}" do
532 postgresql_database database_name do
539 directory "/srv/apis.dev.openstreetmap.org" do
545 template "/srv/apis.dev.openstreetmap.org/index.html" do
546 source "apis.html.erb"
552 ssl_certificate "apis.dev.openstreetmap.org" do
553 domains "apis.dev.openstreetmap.org"
554 notifies :reload, "service[apache2]"
557 apache_site "apis.dev.openstreetmap.org" do
558 template "apache.apis.erb"
561 node[:postgresql][:clusters].each_key do |name|
562 postgresql_munin name do
569 directory "/srv/ooc.openstreetmap.org" do
575 remote_directory "/srv/ooc.openstreetmap.org/html" do
585 ssl_certificate "ooc.openstreetmap.org" do
586 domains ["ooc.openstreetmap.org",
587 "a.ooc.openstreetmap.org",
588 "b.ooc.openstreetmap.org",
589 "c.ooc.openstreetmap.org"]
590 notifies :reload, "service[apache2]"
593 apache_site "ooc.openstreetmap.org" do
594 template "apache.ooc.erb"