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
128 nodejs_package "svgo"
130 python_package "geojson" do
135 apache_module "expires"
136 apache_module "headers"
137 apache_module "proxy"
138 apache_module "proxy_fcgi"
139 apache_module "rewrite"
140 apache_module "suexec"
141 apache_module "userdir"
143 apache_module "wsgi" do
144 package "libapache2-mod-wsgi-py3"
147 package "apache2-suexec-pristine"
152 pm_min_spare_servers 2
153 pm_max_spare_servers 6
160 directory "/srv/dev.openstreetmap.org" do
166 template "/srv/dev.openstreetmap.org/index.html" do
167 source "dev.html.erb"
173 ssl_certificate "dev.openstreetmap.org" do
174 domains "dev.openstreetmap.org"
175 notifies :reload, "service[apache2]"
178 apache_site "dev.openstreetmap.org" do
179 template "apache.dev.erb"
184 template "/etc/phppgadmin/config.inc.php" do
185 source "phppgadmin.conf.erb"
191 file "/etc/apache2/conf.d/phppgadmin" do
195 ssl_certificate "phppgadmin.dev.openstreetmap.org" do
196 domains "phppgadmin.dev.openstreetmap.org"
197 notifies :reload, "service[apache2]"
200 apache_site "phppgadmin.dev.openstreetmap.org" do
201 template "apache.phppgadmin.erb"
204 search(:accounts, "*:*").each do |account|
206 details = node[:accounts][:users][name] || {}
208 next unless %w[user administrator].include?(details[:status])
210 user_home = details[:home] || account["home"] || "#{node[:accounts][:home]}/#{name}"
212 next unless File.directory?("#{user_home}/public_html")
219 pm_min_spare_servers 2
220 pm_max_spare_servers 6
221 pm_max_requests 10000
222 request_terminate_timeout 1800
223 environment "HOSTNAME" => "$HOSTNAME",
224 "PATH" => "/usr/local/bin:/usr/bin:/bin",
228 php_values "max_execution_time" => "300",
229 "memory_limit" => "128M",
230 "post_max_size" => "32M",
231 "upload_max_filesize" => "32M"
232 php_admin_values "sendmail_path" => "/usr/sbin/sendmail -t -i -f #{name}@errol.openstreetmap.org",
233 "open_basedir" => "/home/#{name}/:/tmp/:/usr/share/php/"
234 php_flags "display_errors" => "on"
237 ssl_certificate "#{name}.dev.openstreetmap.org" do
238 domains ["#{name}.dev.openstreetmap.org", "#{name}.dev.osm.org"]
239 notifies :reload, "service[apache2]"
242 apache_site "#{name}.dev.openstreetmap.org" do
243 template "apache.user.erb"
244 directory "#{user_home}/public_html"
245 variables :user => name
248 template "/etc/sudoers.d/#{name}" do
249 source "sudoers.user.erb"
253 variables :user => name
257 node[:postgresql][:versions].each do |version|
258 package "postgresql-#{version}-postgis-3"
261 if node[:postgresql][:clusters][:"14/main"]
262 postgresql_user "apis" do
266 template "/usr/local/bin/cleanup-rails-assets" do
268 source "cleanup-assets.erb"
274 systemd_service "rails-jobs@" do
275 description "Rails job queue runner"
277 environment "RAILS_ENV" => "production", "SLEEP_DELAY" => "60"
279 working_directory "/srv/%i.apis.dev.openstreetmap.org/rails"
280 exec_start "#{node[:ruby][:bundle]} exec rails jobs:work"
285 protect_system "full"
287 no_new_privileges true
290 systemd_service "cgimap@" do
291 description "OpenStreetMap API Server"
293 environment_file "/etc/default/cgimap-%i"
295 exec_start "/srv/%i.apis.dev.openstreetmap.org/cgimap/openstreetmap-cgimap --daemon --port $CGIMAP_PORT --instances 5"
296 exec_reload "/bin/kill -HUP $MAINPID"
299 protect_system "full"
301 no_new_privileges true
307 Dir.glob("/srv/*.apis.dev.openstreetmap.org").each do |dir|
308 node.default_unless[:dev][:rails][File.basename(dir).split(".").first] = {}
311 node[:dev][:rails].each do |name, details|
312 database_name = details[:database] || "apis_#{name}"
313 site_name = "#{name}.apis.dev.openstreetmap.org"
314 site_directory = "/srv/#{name}.apis.dev.openstreetmap.org"
315 log_directory = "#{site_directory}/logs"
316 rails_directory = "#{site_directory}/rails"
317 cgimap_directory = "#{site_directory}/cgimap"
318 gpx_directory = "#{site_directory}/gpx"
320 if details[:repository]
321 site_aliases = details[:aliases] || []
322 secret_key_base = persistent_token("dev", "rails", name, "secret_key_base")
324 postgresql_database database_name do
329 postgresql_extension "#{database_name}_btree_gist" do
331 database database_name
332 extension "btree_gist"
335 directory site_directory do
341 directory log_directory do
347 directory gpx_directory do
353 directory "#{gpx_directory}/traces" do
359 directory "#{gpx_directory}/images" do
365 rails_port site_name do
366 directory rails_directory
369 repository details[:repository]
370 revision details[:revision]
371 database_port node[:postgresql][:clusters][:"14/main"][:port]
372 database_name database_name
373 database_username "apis"
374 email_from "OpenStreetMap <web@noreply.openstreetmap.org>"
375 gpx_dir gpx_directory
376 log_path "#{log_directory}/rails.log"
377 memcache_servers ["127.0.0.1"]
380 trace_use_job_queue true
383 template "#{rails_directory}/config/initializers/setup.rb" do
384 source "rails.setup.rb.erb"
388 variables :site => site_name
389 notifies :restart, "rails_port[#{site_name}]"
392 service "rails-jobs@#{name}" do
393 action [:enable, :start]
394 supports :restart => true
395 subscribes :restart, "rails_port[#{site_name}]"
396 subscribes :restart, "systemd_service[#{name}]"
397 only_if "fgrep -q delayed_job #{rails_directory}/Gemfile.lock"
400 if details[:cgimap_repository]
401 git cgimap_directory do
403 repository details[:cgimap_repository]
404 revision details[:cgimap_revision]
409 execute "#{cgimap_directory}/autogen.sh" do
411 command "./autogen.sh"
415 subscribes :run, "git[#{cgimap_directory}]", :immediately
418 execute "#{cgimap_directory}/configure" do
420 command "./configure --with-fcgi=/usr --with-boost-libdir=/usr/lib/x86_64-linux-gnu --enable-yajl"
424 subscribes :run, "execute[#{cgimap_directory}/autogen.sh]", :immediately
427 execute "#{cgimap_directory}/Makefile" do
433 subscribes :run, "execute[#{cgimap_directory}/configure]", :immediately
434 notifies :restart, "service[cgimap@#{name}]"
437 template "/etc/default/cgimap-#{name}" do
438 source "cgimap.environment.erb"
442 variables :cgimap_port => cgimap_port,
443 :database_port => node[:postgresql][:clusters][:"14/main"][:port],
444 :database_name => database_name,
445 :log_directory => log_directory
446 notifies :restart, "service[cgimap@#{name}]"
449 service "cgimap@#{name}" do
450 action [:start, :enable]
454 ssl_certificate site_name do
455 domains [site_name] + site_aliases
456 notifies :reload, "service[apache2]"
459 apache_site site_name do
460 template "apache.rails.erb"
461 variables :application_name => name,
462 :aliases => site_aliases,
463 :secret_key_base => secret_key_base,
464 :cgimap_enabled => details.key?(:cgimap_repository),
465 :cgimap_port => cgimap_port
468 template "/etc/logrotate.d/apis-#{name}" do
469 source "logrotate.apis.erb"
473 variables :name => name,
474 :log_directory => log_directory,
475 :rails_directory => rails_directory
480 file "/etc/logrotate.d/apis-#{name}" do
484 apache_site site_name do
488 service "cgimap@#{name}" do
489 action [:stop, :disable]
492 file "/etc/default/cgimap-#{name}" do
496 service "rails-jobs@#{name}" do
497 action [:stop, :disable]
500 directory site_directory do
505 file "/etc/cron.daily/rails-#{site_name.tr('.', '-')}" do
509 postgresql_database database_name do
516 directory "/srv/apis.dev.openstreetmap.org" do
522 template "/srv/apis.dev.openstreetmap.org/index.html" do
523 source "apis.html.erb"
529 ssl_certificate "apis.dev.openstreetmap.org" do
530 domains "apis.dev.openstreetmap.org"
531 notifies :reload, "service[apache2]"
534 apache_site "apis.dev.openstreetmap.org" do
535 template "apache.apis.erb"
538 node[:postgresql][:clusters].each_key do |name|
539 postgresql_munin name do
546 directory "/srv/ooc.openstreetmap.org" do
552 remote_directory "/srv/ooc.openstreetmap.org/html" do
562 ssl_certificate "ooc.openstreetmap.org" do
563 domains ["ooc.openstreetmap.org",
564 "a.ooc.openstreetmap.org",
565 "b.ooc.openstreetmap.org",
566 "c.ooc.openstreetmap.org"]
567 notifies :reload, "service[apache2]"
570 apache_site "ooc.openstreetmap.org" do
571 template "apache.ooc.erb"