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"
88 libboost-program-options-dev
89 libboost-date-time-dev
90 libboost-filesystem-dev
131 nodejs_package "svgo"
133 python_package "geojson" do
138 apache_module "expires"
139 apache_module "headers"
140 apache_module "proxy"
141 apache_module "proxy_fcgi"
142 apache_module "rewrite"
143 apache_module "suexec"
144 apache_module "userdir"
146 apache_module "wsgi" do
147 package "libapache2-mod-wsgi-py3"
150 package "apache2-suexec-pristine"
155 pm_min_spare_servers 2
156 pm_max_spare_servers 6
163 directory "/srv/dev.openstreetmap.org" do
169 template "/srv/dev.openstreetmap.org/index.html" do
170 source "dev.html.erb"
176 ssl_certificate "dev.openstreetmap.org" do
177 domains "dev.openstreetmap.org"
178 notifies :reload, "service[apache2]"
181 apache_site "dev.openstreetmap.org" do
182 template "apache.dev.erb"
187 template "/etc/phppgadmin/config.inc.php" do
188 source "phppgadmin.conf.erb"
194 file "/etc/apache2/conf.d/phppgadmin" do
198 ssl_certificate "phppgadmin.dev.openstreetmap.org" do
199 domains "phppgadmin.dev.openstreetmap.org"
200 notifies :reload, "service[apache2]"
203 apache_site "phppgadmin.dev.openstreetmap.org" do
204 template "apache.phppgadmin.erb"
207 search(:accounts, "*:*").each do |account|
209 details = node[:accounts][:users][name] || {}
211 next unless %w[user administrator].include?(details[:status])
213 user_home = details[:home] || account["home"] || "#{node[:accounts][:home]}/#{name}"
215 next unless File.directory?("#{user_home}/public_html")
222 pm_min_spare_servers 2
223 pm_max_spare_servers 6
224 pm_max_requests 10000
225 request_terminate_timeout 1800
226 environment "HOSTNAME" => "$HOSTNAME",
227 "PATH" => "/usr/local/bin:/usr/bin:/bin",
231 php_values "max_execution_time" => "300",
232 "memory_limit" => "128M",
233 "post_max_size" => "32M",
234 "upload_max_filesize" => "32M"
235 php_admin_values "sendmail_path" => "/usr/sbin/sendmail -t -i -f #{name}@errol.openstreetmap.org",
236 "open_basedir" => "/home/#{name}/:/tmp/:/usr/share/php/"
237 php_flags "display_errors" => "on"
240 ssl_certificate "#{name}.dev.openstreetmap.org" do
241 domains ["#{name}.dev.openstreetmap.org", "#{name}.dev.osm.org"]
242 notifies :reload, "service[apache2]"
245 apache_site "#{name}.dev.openstreetmap.org" do
246 template "apache.user.erb"
247 directory "#{user_home}/public_html"
248 variables :user => name
251 template "/etc/sudoers.d/#{name}" do
252 source "sudoers.user.erb"
256 variables :user => name
260 node[:postgresql][:versions].each do |version|
261 package "postgresql-#{version}-postgis-3"
264 if node[:postgresql][:clusters][:"14/main"]
265 postgresql_user "apis" do
269 template "/usr/local/bin/cleanup-rails-assets" do
271 source "cleanup-assets.erb"
277 systemd_service "rails-jobs@" do
278 description "Rails job queue runner"
280 environment "RAILS_ENV" => "production", "SLEEP_DELAY" => "60"
282 working_directory "/srv/%i.apis.dev.openstreetmap.org/rails"
283 exec_start "#{node[:ruby][:bundle]} exec rails jobs:work"
288 protect_system "full"
290 no_new_privileges true
293 systemd_service "cgimap@" do
294 description "OpenStreetMap API Server"
296 environment_file "/etc/default/cgimap-%i"
298 exec_start "/srv/%i.apis.dev.openstreetmap.org/cgimap/openstreetmap-cgimap --daemon --port $CGIMAP_PORT --instances 5"
299 exec_reload "/bin/kill -HUP $MAINPID"
302 protect_system "full"
304 no_new_privileges true
310 Dir.glob("/srv/*.apis.dev.openstreetmap.org").each do |dir|
311 node.default_unless[:dev][:rails][File.basename(dir).split(".").first] = {}
314 node[:dev][:rails].each do |name, details|
315 database_name = details[:database] || "apis_#{name}"
316 site_name = "#{name}.apis.dev.openstreetmap.org"
317 site_directory = "/srv/#{name}.apis.dev.openstreetmap.org"
318 log_directory = "#{site_directory}/logs"
319 rails_directory = "#{site_directory}/rails"
320 cgimap_directory = "#{site_directory}/cgimap"
321 gpx_directory = "#{site_directory}/gpx"
323 if details[:repository]
324 site_aliases = details[:aliases] || []
325 secret_key_base = persistent_token("dev", "rails", name, "secret_key_base")
327 postgresql_database database_name do
332 postgresql_extension "#{database_name}_btree_gist" do
334 database database_name
335 extension "btree_gist"
338 directory site_directory do
344 directory log_directory do
350 directory gpx_directory do
356 directory "#{gpx_directory}/traces" do
362 directory "#{gpx_directory}/images" do
368 rails_port site_name do
369 directory rails_directory
372 repository details[:repository]
373 revision details[:revision]
374 database_port node[:postgresql][:clusters][:"14/main"][:port]
375 database_name database_name
376 database_username "apis"
377 email_from "OpenStreetMap <web@noreply.openstreetmap.org>"
378 gpx_dir gpx_directory
379 log_path "#{log_directory}/rails.log"
380 memcache_servers ["127.0.0.1"]
383 trace_use_job_queue true
386 template "#{rails_directory}/config/initializers/setup.rb" do
387 source "rails.setup.rb.erb"
391 variables :site => site_name
392 notifies :restart, "rails_port[#{site_name}]"
395 service "rails-jobs@#{name}" do
396 action [:enable, :start]
397 supports :restart => true
398 subscribes :restart, "rails_port[#{site_name}]"
399 subscribes :restart, "systemd_service[#{name}]"
400 only_if "fgrep -q delayed_job #{rails_directory}/Gemfile.lock"
403 if details[:cgimap_repository]
404 git cgimap_directory do
406 repository details[:cgimap_repository]
407 revision details[:cgimap_revision]
412 execute "#{cgimap_directory}/autogen.sh" do
414 command "./autogen.sh"
418 subscribes :run, "git[#{cgimap_directory}]", :immediately
421 execute "#{cgimap_directory}/configure" do
423 command "./configure --with-fcgi=/usr --with-boost-libdir=/usr/lib/x86_64-linux-gnu --enable-yajl"
427 subscribes :run, "execute[#{cgimap_directory}/autogen.sh]", :immediately
430 execute "#{cgimap_directory}/Makefile" do
436 subscribes :run, "execute[#{cgimap_directory}/configure]", :immediately
437 notifies :restart, "service[cgimap@#{name}]"
440 template "/etc/default/cgimap-#{name}" do
441 source "cgimap.environment.erb"
445 variables :cgimap_port => cgimap_port,
446 :database_port => node[:postgresql][:clusters][:"14/main"][:port],
447 :database_name => database_name,
448 :log_directory => log_directory
449 notifies :restart, "service[cgimap@#{name}]"
452 service "cgimap@#{name}" do
453 action [:start, :enable]
457 ssl_certificate site_name do
458 domains [site_name] + site_aliases
459 notifies :reload, "service[apache2]"
462 apache_site site_name do
463 template "apache.rails.erb"
464 variables :application_name => name,
465 :aliases => site_aliases,
466 :secret_key_base => secret_key_base,
467 :cgimap_enabled => details.key?(:cgimap_repository),
468 :cgimap_port => cgimap_port
471 template "/etc/logrotate.d/apis-#{name}" do
472 source "logrotate.apis.erb"
476 variables :name => name,
477 :log_directory => log_directory,
478 :rails_directory => rails_directory
483 file "/etc/logrotate.d/apis-#{name}" do
487 apache_site site_name do
491 service "cgimap@#{name}" do
492 action [:stop, :disable]
495 file "/etc/default/cgimap-#{name}" do
499 service "rails-jobs@#{name}" do
500 action [:stop, :disable]
503 directory site_directory do
508 file "/etc/cron.daily/rails-#{site_name.tr('.', '-')}" do
512 postgresql_database database_name do
519 directory "/srv/apis.dev.openstreetmap.org" do
525 template "/srv/apis.dev.openstreetmap.org/index.html" do
526 source "apis.html.erb"
532 ssl_certificate "apis.dev.openstreetmap.org" do
533 domains "apis.dev.openstreetmap.org"
534 notifies :reload, "service[apache2]"
537 apache_site "apis.dev.openstreetmap.org" do
538 template "apache.apis.erb"
541 node[:postgresql][:clusters].each_key do |name|
542 postgresql_munin name do
549 directory "/srv/ooc.openstreetmap.org" do
555 remote_directory "/srv/ooc.openstreetmap.org/html" do
565 ssl_certificate "ooc.openstreetmap.org" do
566 domains ["ooc.openstreetmap.org",
567 "a.ooc.openstreetmap.org",
568 "b.ooc.openstreetmap.org",
569 "c.ooc.openstreetmap.org"]
570 notifies :reload, "service[apache2]"
573 apache_site "ooc.openstreetmap.org" do
574 template "apache.ooc.erb"