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"
89 libboost-program-options-dev
90 libboost-date-time-dev
91 libboost-filesystem-dev
132 # Add uk_os_OSTN15_NTv2_OSGBtoETRS.tif used for reprojecting OS data
133 execute "uk_os_OSTN15_NTv2_OSGBtoETRS.tif" do
134 command "projsync --file uk_os_OSTN15_NTv2_OSGBtoETRS.tif --system-directory"
135 not_if { ::File.exist?("/usr/share/proj/uk_os_OSTN15_NTv2_OSGBtoETRS.tif") }
138 nodejs_package "svgo"
140 python_package "geojson" do
145 apache_module "expires"
146 apache_module "headers"
147 apache_module "proxy"
148 apache_module "proxy_fcgi"
149 apache_module "rewrite"
150 apache_module "suexec"
151 apache_module "userdir"
153 apache_module "wsgi" do
154 package "libapache2-mod-wsgi-py3"
157 package "apache2-suexec-pristine"
162 pm_min_spare_servers 2
163 pm_max_spare_servers 6
170 directory "/srv/dev.openstreetmap.org" do
176 template "/srv/dev.openstreetmap.org/index.html" do
177 source "dev.html.erb"
183 ssl_certificate "dev.openstreetmap.org" do
184 domains "dev.openstreetmap.org"
185 notifies :reload, "service[apache2]"
188 apache_site "dev.openstreetmap.org" do
189 template "apache.dev.erb"
194 template "/etc/phppgadmin/config.inc.php" do
195 source "phppgadmin.conf.erb"
201 file "/etc/apache2/conf.d/phppgadmin" do
205 ssl_certificate "phppgadmin.dev.openstreetmap.org" do
206 domains "phppgadmin.dev.openstreetmap.org"
207 notifies :reload, "service[apache2]"
210 apache_site "phppgadmin.dev.openstreetmap.org" do
211 template "apache.phppgadmin.erb"
214 search(:accounts, "*:*").each do |account|
216 details = node[:accounts][:users][name] || {}
218 next unless %w[user administrator].include?(details[:status])
220 user_home = details[:home] || account["home"] || "#{node[:accounts][:home]}/#{name}"
222 next unless File.directory?("#{user_home}/public_html")
229 pm_min_spare_servers 2
230 pm_max_spare_servers 6
231 pm_max_requests 10000
232 request_terminate_timeout 1800
233 environment "HOSTNAME" => "$HOSTNAME",
234 "PATH" => "/usr/local/bin:/usr/bin:/bin",
238 php_values "max_execution_time" => "300",
239 "memory_limit" => "128M",
240 "post_max_size" => "32M",
241 "upload_max_filesize" => "32M"
242 php_admin_values "sendmail_path" => "/usr/sbin/sendmail -t -i -f #{name}@errol.openstreetmap.org",
243 "open_basedir" => "/home/#{name}/:/tmp/:/usr/share/php/"
244 php_flags "display_errors" => "on"
247 ssl_certificate "#{name}.dev.openstreetmap.org" do
248 domains ["#{name}.dev.openstreetmap.org", "#{name}.dev.osm.org"]
249 notifies :reload, "service[apache2]"
252 apache_site "#{name}.dev.openstreetmap.org" do
253 template "apache.user.erb"
254 directory "#{user_home}/public_html"
255 variables :user => name
258 template "/etc/sudoers.d/#{name}" do
259 source "sudoers.user.erb"
263 variables :user => name
267 node[:postgresql][:versions].each do |version|
268 package "postgresql-#{version}-postgis-3"
271 if node[:postgresql][:clusters][:"14/main"]
272 postgresql_user "apis" do
276 template "/usr/local/bin/cleanup-rails-assets" do
278 source "cleanup-assets.erb"
284 systemd_service "rails-jobs@" do
285 description "Rails job queue runner"
287 environment "RAILS_ENV" => "production", "SLEEP_DELAY" => "60"
289 working_directory "/srv/%i.apis.dev.openstreetmap.org/rails"
290 exec_start "#{node[:ruby][:bundle]} exec rails jobs:work"
295 protect_system "strict"
297 read_write_paths "/srv/%i.apis.dev.openstreetmap.org/logs"
298 no_new_privileges true
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"
310 protect_system "strict"
312 read_write_paths ["/srv/%i.apis.dev.openstreetmap.org/logs", "/srv/%i.apis.dev.openstreetmap.org/rails/tmp"]
313 no_new_privileges true
319 Dir.glob("/srv/*.apis.dev.openstreetmap.org").each do |dir|
320 node.default_unless[:dev][:rails][File.basename(dir).split(".").first] = {}
323 node[:dev][:rails].each do |name, details|
324 database_name = details[:database] || "apis_#{name}"
325 site_name = "#{name}.apis.dev.openstreetmap.org"
326 site_directory = "/srv/#{name}.apis.dev.openstreetmap.org"
327 log_directory = "#{site_directory}/logs"
328 rails_directory = "#{site_directory}/rails"
329 cgimap_directory = "#{site_directory}/cgimap"
330 gpx_directory = "#{site_directory}/gpx"
332 if details[:repository]
333 site_aliases = details[:aliases] || []
334 secret_key_base = persistent_token("dev", "rails", name, "secret_key_base")
336 postgresql_database database_name do
341 postgresql_extension "#{database_name}_btree_gist" do
343 database database_name
344 extension "btree_gist"
347 directory site_directory do
353 directory log_directory do
359 directory gpx_directory do
365 directory "#{gpx_directory}/traces" do
371 directory "#{gpx_directory}/images" do
377 rails_port site_name do
378 directory rails_directory
381 repository details[:repository]
382 revision details[:revision]
383 database_port node[:postgresql][:clusters][:"14/main"][:port]
384 database_name database_name
385 database_username "apis"
386 email_from "OpenStreetMap <web@noreply.openstreetmap.org>"
387 gpx_dir gpx_directory
388 log_path "#{log_directory}/rails.log"
389 memcache_servers ["127.0.0.1"]
392 trace_use_job_queue true
395 template "#{rails_directory}/config/initializers/setup.rb" do
396 source "rails.setup.rb.erb"
400 variables :site => site_name
401 notifies :restart, "rails_port[#{site_name}]"
404 service "rails-jobs@#{name}" do
405 action [:enable, :start]
406 supports :restart => true
407 subscribes :restart, "rails_port[#{site_name}]"
408 subscribes :restart, "systemd_service[#{name}]"
409 only_if "fgrep -q delayed_job #{rails_directory}/Gemfile.lock"
412 if details[:cgimap_repository]
413 git cgimap_directory do
415 repository details[:cgimap_repository]
416 revision details[:cgimap_revision]
421 execute "#{cgimap_directory}/autogen.sh" do
423 command "./autogen.sh"
427 subscribes :run, "git[#{cgimap_directory}]", :immediately
430 execute "#{cgimap_directory}/configure" do
432 command "./configure --with-fcgi=/usr --with-boost-libdir=/usr/lib/x86_64-linux-gnu --enable-yajl"
436 subscribes :run, "execute[#{cgimap_directory}/autogen.sh]", :immediately
439 execute "#{cgimap_directory}/Makefile" do
445 subscribes :run, "execute[#{cgimap_directory}/configure]", :immediately
446 notifies :restart, "service[cgimap@#{name}]"
449 template "/etc/default/cgimap-#{name}" do
450 source "cgimap.environment.erb"
454 variables :cgimap_port => cgimap_port,
455 :database_port => node[:postgresql][:clusters][:"14/main"][:port],
456 :database_name => database_name,
457 :log_directory => log_directory
458 notifies :restart, "service[cgimap@#{name}]"
461 service "cgimap@#{name}" do
462 action [:start, :enable]
466 ssl_certificate site_name do
467 domains [site_name] + site_aliases
468 notifies :reload, "service[apache2]"
471 apache_site site_name do
472 template "apache.rails.erb"
473 variables :application_name => name,
474 :aliases => site_aliases,
475 :secret_key_base => secret_key_base,
476 :cgimap_enabled => details.key?(:cgimap_repository),
477 :cgimap_port => cgimap_port
480 template "/etc/logrotate.d/apis-#{name}" do
481 source "logrotate.apis.erb"
485 variables :name => name,
486 :log_directory => log_directory,
487 :rails_directory => rails_directory
492 file "/etc/logrotate.d/apis-#{name}" do
496 apache_site site_name do
500 service "cgimap@#{name}" do
501 action [:stop, :disable]
504 file "/etc/default/cgimap-#{name}" do
508 service "rails-jobs@#{name}" do
509 action [:stop, :disable]
512 directory site_directory do
517 file "/etc/cron.daily/rails-#{site_name.tr('.', '-')}" do
521 postgresql_database database_name do
528 directory "/srv/apis.dev.openstreetmap.org" do
534 template "/srv/apis.dev.openstreetmap.org/index.html" do
535 source "apis.html.erb"
541 ssl_certificate "apis.dev.openstreetmap.org" do
542 domains "apis.dev.openstreetmap.org"
543 notifies :reload, "service[apache2]"
546 apache_site "apis.dev.openstreetmap.org" do
547 template "apache.apis.erb"
550 node[:postgresql][:clusters].each_key do |name|
551 postgresql_munin name do
558 directory "/srv/ooc.openstreetmap.org" do
564 remote_directory "/srv/ooc.openstreetmap.org/html" do
574 ssl_certificate "ooc.openstreetmap.org" do
575 domains ["ooc.openstreetmap.org",
576 "a.ooc.openstreetmap.org",
577 "b.ooc.openstreetmap.org",
578 "c.ooc.openstreetmap.org"]
579 notifies :reload, "service[apache2]"
582 apache_site "ooc.openstreetmap.org" do
583 template "apache.ooc.erb"