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 "RAILS_ENV" => "production", "SLEEP_DELAY" => "60"
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 rails_port site_name do
390 directory rails_directory
393 repository details[:repository]
394 revision details[:revision]
395 database_port node[:postgresql][:clusters][:"15/main"][:port]
396 database_name database_name
397 database_username "apis"
398 email_from "OpenStreetMap <web@noreply.openstreetmap.org>"
399 gpx_dir gpx_directory
400 log_path "#{log_directory}/rails.log"
401 memcache_servers ["127.0.0.1"]
404 trace_use_job_queue true
407 template "#{rails_directory}/config/initializers/setup.rb" do
408 source "rails.setup.rb.erb"
412 variables :site => site_name
413 notifies :restart, "rails_port[#{site_name}]"
416 service "rails-jobs@#{name}" do
417 action [:enable, :start]
418 supports :restart => true
419 subscribes :restart, "rails_port[#{site_name}]"
420 subscribes :restart, "systemd_service[rails-jobs@]"
421 only_if "fgrep -q delayed_job #{rails_directory}/Gemfile.lock"
424 if details[:cgimap_repository]
425 git cgimap_directory do
427 repository details[:cgimap_repository]
428 revision details[:cgimap_revision]
433 execute "#{cgimap_directory}/autogen.sh" do
435 command "./autogen.sh"
439 subscribes :run, "git[#{cgimap_directory}]", :immediately
442 execute "#{cgimap_directory}/configure" do
444 command "./configure --with-fcgi=/usr --with-boost-libdir=/usr/lib/x86_64-linux-gnu --enable-yajl"
448 subscribes :run, "execute[#{cgimap_directory}/autogen.sh]", :immediately
451 execute "#{cgimap_directory}/Makefile" do
457 subscribes :run, "execute[#{cgimap_directory}/configure]", :immediately
460 template "/etc/default/cgimap-#{name}" do
461 source "cgimap.environment.erb"
465 variables :cgimap_port => cgimap_port,
466 :database_port => node[:postgresql][:clusters][:"15/main"][:port],
467 :database_name => database_name,
468 :log_directory => log_directory,
469 :options => details[:cgimap_options]
472 service "cgimap@#{name}" do
473 action [:start, :enable]
474 subscribes :restart, "execute[#{cgimap_directory}/Makefile]"
475 subscribes :restart, "template[/etc/default/cgimap-#{name}]"
476 subscribes :restart, "systemd_service[cgimap@]"
480 ssl_certificate site_name do
481 domains [site_name] + site_aliases
482 notifies :reload, "service[apache2]"
485 apache_site site_name do
486 template "apache.rails.erb"
487 variables :application_name => name,
488 :aliases => site_aliases,
489 :secret_key_base => secret_key_base,
490 :cgimap_enabled => details.key?(:cgimap_repository),
491 :cgimap_port => cgimap_port
494 template "/etc/logrotate.d/apis-#{name}" do
495 source "logrotate.apis.erb"
499 variables :name => name,
500 :log_directory => log_directory,
501 :rails_directory => rails_directory
506 file "/etc/logrotate.d/apis-#{name}" do
510 apache_site site_name do
514 service "cgimap@#{name}" do
515 action [:stop, :disable]
518 file "/etc/default/cgimap-#{name}" do
522 service "rails-jobs@#{name}" do
523 action [:stop, :disable]
526 directory site_directory do
531 file "/etc/cron.daily/rails-#{site_name.tr('.', '-')}" do
535 postgresql_database database_name do
542 directory "/srv/apis.dev.openstreetmap.org" do
548 template "/srv/apis.dev.openstreetmap.org/index.html" do
549 source "apis.html.erb"
555 ssl_certificate "apis.dev.openstreetmap.org" do
556 domains "apis.dev.openstreetmap.org"
557 notifies :reload, "service[apache2]"
560 apache_site "apis.dev.openstreetmap.org" do
561 template "apache.apis.erb"
564 node[:postgresql][:clusters].each_key do |name|
565 postgresql_munin name do
572 directory "/srv/ooc.openstreetmap.org" do
578 remote_directory "/srv/ooc.openstreetmap.org/html" do
588 ssl_certificate "ooc.openstreetmap.org" do
589 domains ["ooc.openstreetmap.org",
590 "a.ooc.openstreetmap.org",
591 "b.ooc.openstreetmap.org",
592 "c.ooc.openstreetmap.org"]
593 notifies :reload, "service[apache2]"
596 apache_site "ooc.openstreetmap.org" do
597 template "apache.ooc.erb"