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"
91 libboost-program-options-dev
92 libboost-date-time-dev
93 libboost-filesystem-dev
134 # Add uk_os_OSTN15_NTv2_OSGBtoETRS.tif used for reprojecting OS data
135 execute "uk_os_OSTN15_NTv2_OSGBtoETRS.tif" do
136 command "projsync --file uk_os_OSTN15_NTv2_OSGBtoETRS.tif --system-directory"
137 not_if { ::File.exist?("/usr/share/proj/uk_os_OSTN15_NTv2_OSGBtoETRS.tif") }
140 nodejs_package "svgo"
142 python_package "geojson" do
147 apache_module "expires"
148 apache_module "headers"
149 apache_module "proxy"
150 apache_module "proxy_fcgi"
151 apache_module "rewrite"
152 apache_module "suexec"
153 apache_module "userdir"
155 apache_module "wsgi" do
156 package "libapache2-mod-wsgi-py3"
159 package "apache2-suexec-pristine"
164 pm_min_spare_servers 2
165 pm_max_spare_servers 6
172 directory "/srv/dev.openstreetmap.org" do
178 template "/srv/dev.openstreetmap.org/index.html" do
179 source "dev.html.erb"
185 ssl_certificate "dev.openstreetmap.org" do
186 domains "dev.openstreetmap.org"
187 notifies :reload, "service[apache2]"
190 apache_site "dev.openstreetmap.org" do
191 template "apache.dev.erb"
196 template "/etc/phppgadmin/config.inc.php" do
197 source "phppgadmin.conf.erb"
203 file "/etc/apache2/conf.d/phppgadmin" do
207 ssl_certificate "phppgadmin.dev.openstreetmap.org" do
208 domains "phppgadmin.dev.openstreetmap.org"
209 notifies :reload, "service[apache2]"
212 apache_site "phppgadmin.dev.openstreetmap.org" do
213 template "apache.phppgadmin.erb"
216 search(:accounts, "*:*").each do |account|
218 details = node[:accounts][:users][name] || {}
220 next unless %w[user administrator].include?(details[:status])
222 user_home = details[:home] || account["home"] || "#{node[:accounts][:home]}/#{name}"
224 next unless File.directory?("#{user_home}/public_html")
231 pm_min_spare_servers 2
232 pm_max_spare_servers 6
233 pm_max_requests 10000
234 request_terminate_timeout 1800
235 environment "HOSTNAME" => "$HOSTNAME",
236 "PATH" => "/usr/local/bin:/usr/bin:/bin",
240 php_values "max_execution_time" => "300",
241 "memory_limit" => "128M",
242 "post_max_size" => "32M",
243 "upload_max_filesize" => "32M"
244 php_admin_values "sendmail_path" => "/usr/sbin/sendmail -t -i -f #{name}@dev.openstreetmap.org",
245 "open_basedir" => "/home/#{name}/:/tmp/:/usr/share/php/"
246 php_flags "display_errors" => "on"
249 ssl_certificate "#{name}.dev.openstreetmap.org" do
250 domains ["#{name}.dev.openstreetmap.org", "#{name}.dev.osm.org"]
251 notifies :reload, "service[apache2]"
254 apache_site "#{name}.dev.openstreetmap.org" do
255 template "apache.user.erb"
256 directory "#{user_home}/public_html"
257 variables :user => name
260 template "/etc/sudoers.d/#{name}" do
261 source "sudoers.user.erb"
265 variables :user => name
269 node[:postgresql][:versions].each do |version|
270 package "postgresql-#{version}-postgis-3"
273 if node[:postgresql][:clusters][:"14/main"]
274 postgresql_user "apis" do
278 template "/usr/local/bin/cleanup-rails-assets" do
280 source "cleanup-assets.erb"
286 systemd_service "rails-jobs@" do
287 description "Rails job queue runner"
289 environment "RAILS_ENV" => "production", "SLEEP_DELAY" => "60"
291 working_directory "/srv/%i.apis.dev.openstreetmap.org/rails"
292 exec_start "#{node[:ruby][:bundle]} exec rails jobs:work"
295 sandbox :enable_network => true
296 restrict_address_families "AF_UNIX"
297 memory_deny_write_execute false
298 read_write_paths "/srv/%i.apis.dev.openstreetmap.org/logs"
301 systemd_service "cgimap@" do
302 description "OpenStreetMap API Server"
304 environment_file "/etc/default/cgimap-%i"
306 exec_start "/srv/%i.apis.dev.openstreetmap.org/cgimap/openstreetmap-cgimap --daemon --port $CGIMAP_PORT --instances 5"
307 exec_reload "/bin/kill -HUP $MAINPID"
308 sandbox :enable_network => true
309 restrict_address_families "AF_UNIX"
310 read_write_paths ["/srv/%i.apis.dev.openstreetmap.org/logs", "/srv/%i.apis.dev.openstreetmap.org/rails/tmp"]
316 Dir.glob("/srv/*.apis.dev.openstreetmap.org").each do |dir|
317 node.default_unless[:dev][:rails][File.basename(dir).split(".").first] = {}
320 node[:dev][:rails].each do |name, details|
321 database_name = details[:database] || "apis_#{name}"
322 site_name = "#{name}.apis.dev.openstreetmap.org"
323 site_directory = "/srv/#{name}.apis.dev.openstreetmap.org"
324 log_directory = "#{site_directory}/logs"
325 rails_directory = "#{site_directory}/rails"
326 cgimap_directory = "#{site_directory}/cgimap"
327 gpx_directory = "#{site_directory}/gpx"
329 if details[:repository]
330 site_aliases = details[:aliases] || []
331 secret_key_base = persistent_token("dev", "rails", name, "secret_key_base")
333 postgresql_database database_name do
338 postgresql_extension "#{database_name}_btree_gist" do
340 database database_name
341 extension "btree_gist"
344 directory site_directory do
350 directory log_directory do
356 directory gpx_directory do
362 directory "#{gpx_directory}/traces" do
368 directory "#{gpx_directory}/images" do
374 rails_port site_name do
375 directory rails_directory
378 repository details[:repository]
379 revision details[:revision]
380 database_port node[:postgresql][:clusters][:"14/main"][:port]
381 database_name database_name
382 database_username "apis"
383 email_from "OpenStreetMap <web@noreply.openstreetmap.org>"
384 gpx_dir gpx_directory
385 log_path "#{log_directory}/rails.log"
386 memcache_servers ["127.0.0.1"]
389 trace_use_job_queue true
392 template "#{rails_directory}/config/initializers/setup.rb" do
393 source "rails.setup.rb.erb"
397 variables :site => site_name
398 notifies :restart, "rails_port[#{site_name}]"
401 service "rails-jobs@#{name}" do
402 action [:enable, :start]
403 supports :restart => true
404 subscribes :restart, "rails_port[#{site_name}]"
405 subscribes :restart, "systemd_service[rails-jobs@]"
406 only_if "fgrep -q delayed_job #{rails_directory}/Gemfile.lock"
409 if details[:cgimap_repository]
410 git cgimap_directory do
412 repository details[:cgimap_repository]
413 revision details[:cgimap_revision]
418 execute "#{cgimap_directory}/autogen.sh" do
420 command "./autogen.sh"
424 subscribes :run, "git[#{cgimap_directory}]", :immediately
427 execute "#{cgimap_directory}/configure" do
429 command "./configure --with-fcgi=/usr --with-boost-libdir=/usr/lib/x86_64-linux-gnu --enable-yajl"
433 subscribes :run, "execute[#{cgimap_directory}/autogen.sh]", :immediately
436 execute "#{cgimap_directory}/Makefile" do
442 subscribes :run, "execute[#{cgimap_directory}/configure]", :immediately
445 template "/etc/default/cgimap-#{name}" do
446 source "cgimap.environment.erb"
450 variables :cgimap_port => cgimap_port,
451 :database_port => node[:postgresql][:clusters][:"14/main"][:port],
452 :database_name => database_name,
453 :log_directory => log_directory
456 service "cgimap@#{name}" do
457 action [:start, :enable]
458 subscribes :restart, "execute[#{cgimap_directory}/Makefile]"
459 subscribes :restart, "template[/etc/default/cgimap-#{name}]"
460 subscribes :restart, "systemd_service[cgimap@]"
464 ssl_certificate site_name do
465 domains [site_name] + site_aliases
466 notifies :reload, "service[apache2]"
469 apache_site site_name do
470 template "apache.rails.erb"
471 variables :application_name => name,
472 :aliases => site_aliases,
473 :secret_key_base => secret_key_base,
474 :cgimap_enabled => details.key?(:cgimap_repository),
475 :cgimap_port => cgimap_port
478 template "/etc/logrotate.d/apis-#{name}" do
479 source "logrotate.apis.erb"
483 variables :name => name,
484 :log_directory => log_directory,
485 :rails_directory => rails_directory
490 file "/etc/logrotate.d/apis-#{name}" do
494 apache_site site_name do
498 service "cgimap@#{name}" do
499 action [:stop, :disable]
502 file "/etc/default/cgimap-#{name}" do
506 service "rails-jobs@#{name}" do
507 action [:stop, :disable]
510 directory site_directory do
515 file "/etc/cron.daily/rails-#{site_name.tr('.', '-')}" do
519 postgresql_database database_name do
526 directory "/srv/apis.dev.openstreetmap.org" do
532 template "/srv/apis.dev.openstreetmap.org/index.html" do
533 source "apis.html.erb"
539 ssl_certificate "apis.dev.openstreetmap.org" do
540 domains "apis.dev.openstreetmap.org"
541 notifies :reload, "service[apache2]"
544 apache_site "apis.dev.openstreetmap.org" do
545 template "apache.apis.erb"
548 node[:postgresql][:clusters].each_key do |name|
549 postgresql_munin name do
556 directory "/srv/ooc.openstreetmap.org" do
562 remote_directory "/srv/ooc.openstreetmap.org/html" do
572 ssl_certificate "ooc.openstreetmap.org" do
573 domains ["ooc.openstreetmap.org",
574 "a.ooc.openstreetmap.org",
575 "b.ooc.openstreetmap.org",
576 "c.ooc.openstreetmap.org"]
577 notifies :reload, "service[apache2]"
580 apache_site "ooc.openstreetmap.org" do
581 template "apache.ooc.erb"