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"
61 libboost-date-time-dev
63 libboost-filesystem-dev
65 libboost-program-options-dev
137 # Add uk_os_OSTN15_NTv2_OSGBtoETRS.tif used for reprojecting OS data
138 execute "uk_os_OSTN15_NTv2_OSGBtoETRS.tif" do
139 command "projsync --file uk_os_OSTN15_NTv2_OSGBtoETRS.tif --system-directory"
140 not_if { ::File.exist?("/usr/share/proj/uk_os_OSTN15_NTv2_OSGBtoETRS.tif") }
143 nodejs_package "svgo"
145 python_package "geojson" do
150 apache_module "expires"
151 apache_module "headers"
152 apache_module "proxy"
153 apache_module "proxy_fcgi"
154 apache_module "rewrite"
155 apache_module "suexec"
156 apache_module "userdir"
158 apache_module "wsgi" do
159 package "libapache2-mod-wsgi-py3"
162 package "apache2-suexec-pristine"
167 pm_min_spare_servers 2
168 pm_max_spare_servers 6
175 directory "/srv/dev.openstreetmap.org" do
181 template "/srv/dev.openstreetmap.org/index.html" do
182 source "dev.html.erb"
188 ssl_certificate "dev.openstreetmap.org" do
189 domains "dev.openstreetmap.org"
190 notifies :reload, "service[apache2]"
193 apache_site "dev.openstreetmap.org" do
194 template "apache.dev.erb"
199 template "/etc/phppgadmin/config.inc.php" do
200 source "phppgadmin.conf.erb"
206 file "/etc/apache2/conf.d/phppgadmin" do
210 ssl_certificate "phppgadmin.dev.openstreetmap.org" do
211 domains "phppgadmin.dev.openstreetmap.org"
212 notifies :reload, "service[apache2]"
215 apache_site "phppgadmin.dev.openstreetmap.org" do
216 template "apache.phppgadmin.erb"
219 search(:accounts, "*:*").each do |account|
221 details = node[:accounts][:users][name] || {}
223 next unless %w[user administrator].include?(details[:status])
225 user_home = details[:home] || account["home"] || "#{node[:accounts][:home]}/#{name}"
227 next unless File.directory?("#{user_home}/public_html")
234 pm_min_spare_servers 2
235 pm_max_spare_servers 6
236 pm_max_requests 10000
237 request_terminate_timeout 1800
238 environment "HOSTNAME" => "$HOSTNAME",
239 "PATH" => "/usr/local/bin:/usr/bin:/bin",
243 php_values "max_execution_time" => "300",
244 "memory_limit" => "128M",
245 "post_max_size" => "32M",
246 "upload_max_filesize" => "32M"
247 php_admin_values "sendmail_path" => "/usr/sbin/sendmail -t -i -f #{name}@dev.openstreetmap.org",
248 "open_basedir" => "/home/#{name}/:/tmp/:/usr/share/php/"
249 php_flags "display_errors" => "on"
252 ssl_certificate "#{name}.dev.openstreetmap.org" do
253 domains ["#{name}.dev.openstreetmap.org", "#{name}.dev.osm.org"]
254 notifies :reload, "service[apache2]"
257 apache_site "#{name}.dev.openstreetmap.org" do
258 template "apache.user.erb"
259 directory "#{user_home}/public_html"
260 variables :user => name
263 template "/etc/sudoers.d/#{name}" do
264 source "sudoers.user.erb"
268 variables :user => name
272 node[:postgresql][:versions].each do |version|
273 package "postgresql-#{version}-postgis-3"
276 if node[:postgresql][:clusters][:"15/main"]
277 postgresql_user "apis" do
281 template "/usr/local/bin/cleanup-rails-assets" do
283 source "cleanup-assets.erb"
289 systemd_service "rails-jobs@" do
290 description "Rails job queue runner"
292 environment "RAILS_ENV" => "production", "SLEEP_DELAY" => "60"
294 working_directory "/srv/%i.apis.dev.openstreetmap.org/rails"
295 exec_start "#{node[:ruby][:bundle]} exec rails jobs:work"
298 sandbox :enable_network => true
299 restrict_address_families "AF_UNIX"
300 memory_deny_write_execute false
302 "/srv/%i.apis.dev.openstreetmap.org/logs",
303 "/srv/%i.apis.dev.openstreetmap.org/rails/storage"
307 systemd_service "cgimap@" do
308 description "OpenStreetMap API Server"
310 environment_file "/etc/default/cgimap-%i"
312 exec_start "/srv/%i.apis.dev.openstreetmap.org/cgimap/openstreetmap-cgimap --daemon --port $CGIMAP_PORT --instances 5"
313 exec_reload "/bin/kill -HUP $MAINPID"
314 sandbox :enable_network => true
315 restrict_address_families "AF_UNIX"
316 read_write_paths ["/srv/%i.apis.dev.openstreetmap.org/logs", "/srv/%i.apis.dev.openstreetmap.org/rails/tmp"]
322 Dir.glob("/srv/*.apis.dev.openstreetmap.org").each do |dir|
323 node.default_unless[:dev][:rails][File.basename(dir).split(".").first] = {}
326 node[:dev][:rails].each do |name, details|
327 database_name = details[:database] || "apis_#{name}"
328 site_name = "#{name}.apis.dev.openstreetmap.org"
329 site_directory = "/srv/#{name}.apis.dev.openstreetmap.org"
330 log_directory = "#{site_directory}/logs"
331 rails_directory = "#{site_directory}/rails"
332 cgimap_directory = "#{site_directory}/cgimap"
333 gpx_directory = "#{site_directory}/gpx"
335 if details[:repository]
336 site_aliases = details[:aliases] || []
337 secret_key_base = persistent_token("dev", "rails", name, "secret_key_base")
339 postgresql_database database_name do
344 postgresql_extension "#{database_name}_btree_gist" do
346 database database_name
347 extension "btree_gist"
350 directory site_directory do
356 directory log_directory do
362 directory gpx_directory do
368 directory "#{gpx_directory}/traces" do
374 directory "#{gpx_directory}/images" do
380 rails_port site_name do
381 directory rails_directory
384 repository details[:repository]
385 revision details[:revision]
386 database_port node[:postgresql][:clusters][:"15/main"][:port]
387 database_name database_name
388 database_username "apis"
389 email_from "OpenStreetMap <web@noreply.openstreetmap.org>"
390 gpx_dir gpx_directory
391 log_path "#{log_directory}/rails.log"
392 memcache_servers ["127.0.0.1"]
395 trace_use_job_queue true
398 template "#{rails_directory}/config/initializers/setup.rb" do
399 source "rails.setup.rb.erb"
403 variables :site => site_name
404 notifies :restart, "rails_port[#{site_name}]"
407 service "rails-jobs@#{name}" do
408 action [:enable, :start]
409 supports :restart => true
410 subscribes :restart, "rails_port[#{site_name}]"
411 subscribes :restart, "systemd_service[rails-jobs@]"
412 only_if "fgrep -q delayed_job #{rails_directory}/Gemfile.lock"
415 if details[:cgimap_repository]
416 git cgimap_directory do
418 repository details[:cgimap_repository]
419 revision details[:cgimap_revision]
424 execute "#{cgimap_directory}/autogen.sh" do
426 command "./autogen.sh"
430 subscribes :run, "git[#{cgimap_directory}]", :immediately
433 execute "#{cgimap_directory}/configure" do
435 command "./configure --with-fcgi=/usr --with-boost-libdir=/usr/lib/x86_64-linux-gnu --enable-yajl"
439 subscribes :run, "execute[#{cgimap_directory}/autogen.sh]", :immediately
442 execute "#{cgimap_directory}/Makefile" do
448 subscribes :run, "execute[#{cgimap_directory}/configure]", :immediately
451 template "/etc/default/cgimap-#{name}" do
452 source "cgimap.environment.erb"
456 variables :cgimap_port => cgimap_port,
457 :database_port => node[:postgresql][:clusters][:"15/main"][:port],
458 :database_name => database_name,
459 :log_directory => log_directory
462 service "cgimap@#{name}" do
463 action [:start, :enable]
464 subscribes :restart, "execute[#{cgimap_directory}/Makefile]"
465 subscribes :restart, "template[/etc/default/cgimap-#{name}]"
466 subscribes :restart, "systemd_service[cgimap@]"
470 ssl_certificate site_name do
471 domains [site_name] + site_aliases
472 notifies :reload, "service[apache2]"
475 apache_site site_name do
476 template "apache.rails.erb"
477 variables :application_name => name,
478 :aliases => site_aliases,
479 :secret_key_base => secret_key_base,
480 :cgimap_enabled => details.key?(:cgimap_repository),
481 :cgimap_port => cgimap_port
484 template "/etc/logrotate.d/apis-#{name}" do
485 source "logrotate.apis.erb"
489 variables :name => name,
490 :log_directory => log_directory,
491 :rails_directory => rails_directory
496 file "/etc/logrotate.d/apis-#{name}" do
500 apache_site site_name do
504 service "cgimap@#{name}" do
505 action [:stop, :disable]
508 file "/etc/default/cgimap-#{name}" do
512 service "rails-jobs@#{name}" do
513 action [:stop, :disable]
516 directory site_directory do
521 file "/etc/cron.daily/rails-#{site_name.tr('.', '-')}" do
525 postgresql_database database_name do
532 directory "/srv/apis.dev.openstreetmap.org" do
538 template "/srv/apis.dev.openstreetmap.org/index.html" do
539 source "apis.html.erb"
545 ssl_certificate "apis.dev.openstreetmap.org" do
546 domains "apis.dev.openstreetmap.org"
547 notifies :reload, "service[apache2]"
550 apache_site "apis.dev.openstreetmap.org" do
551 template "apache.apis.erb"
554 node[:postgresql][:clusters].each_key do |name|
555 postgresql_munin name do
562 directory "/srv/ooc.openstreetmap.org" do
568 remote_directory "/srv/ooc.openstreetmap.org/html" do
578 ssl_certificate "ooc.openstreetmap.org" do
579 domains ["ooc.openstreetmap.org",
580 "a.ooc.openstreetmap.org",
581 "b.ooc.openstreetmap.org",
582 "c.ooc.openstreetmap.org"]
583 notifies :reload, "service[apache2]"
586 apache_site "ooc.openstreetmap.org" do
587 template "apache.ooc.erb"