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"
75 libboost-program-options-dev
76 libboost-date-time-dev
77 libboost-filesystem-dev
90 python_package "geojson" do
95 apache_module "expires"
96 apache_module "headers"
98 apache_module "proxy_fcgi"
99 apache_module "rewrite"
100 apache_module "suexec"
101 apache_module "userdir"
103 apache_module "wsgi" do
104 package "libapache2-mod-wsgi-py3"
107 package "apache2-suexec-pristine"
112 pm_min_spare_servers 2
113 pm_max_spare_servers 6
120 directory "/srv/dev.openstreetmap.org" do
126 template "/srv/dev.openstreetmap.org/index.html" do
127 source "dev.html.erb"
133 ssl_certificate "dev.openstreetmap.org" do
134 domains "dev.openstreetmap.org"
135 notifies :reload, "service[apache2]"
138 apache_site "dev.openstreetmap.org" do
139 template "apache.dev.erb"
144 template "/etc/phppgadmin/config.inc.php" do
145 source "phppgadmin.conf.erb"
151 file "/etc/apache2/conf.d/phppgadmin" do
155 ssl_certificate "phppgadmin.dev.openstreetmap.org" do
156 domains "phppgadmin.dev.openstreetmap.org"
157 notifies :reload, "service[apache2]"
160 apache_site "phppgadmin.dev.openstreetmap.org" do
161 template "apache.phppgadmin.erb"
164 search(:accounts, "*:*").each do |account|
166 details = node[:accounts][:users][name] || {}
168 next unless %w[user administrator].include?(details[:status])
170 user_home = details[:home] || account["home"] || "#{node[:accounts][:home]}/#{name}"
172 next unless File.directory?("#{user_home}/public_html")
179 pm_min_spare_servers 2
180 pm_max_spare_servers 6
181 pm_max_requests 10000
182 request_terminate_timeout 1800
183 environment "HOSTNAME" => "$HOSTNAME",
184 "PATH" => "/usr/local/bin:/usr/bin:/bin",
188 php_values "max_execution_time" => "300",
189 "memory_limit" => "128M",
190 "post_max_size" => "32M",
191 "upload_max_filesize" => "32M"
192 php_admin_values "sendmail_path" => "/usr/sbin/sendmail -t -i -f #{name}@errol.openstreetmap.org",
193 "open_basedir" => "/home/#{name}/:/tmp/:/usr/share/php/"
194 php_flags "display_errors" => "on"
197 ssl_certificate "#{name}.dev.openstreetmap.org" do
198 domains ["#{name}.dev.openstreetmap.org", "#{name}.dev.osm.org"]
199 notifies :reload, "service[apache2]"
202 apache_site "#{name}.dev.openstreetmap.org" do
203 template "apache.user.erb"
204 directory "#{user_home}/public_html"
205 variables :user => name
208 template "/etc/sudoers.d/#{name}" do
209 source "sudoers.user.erb"
213 variables :user => name
217 if node[:postgresql][:clusters][:"14/main"]
218 postgresql_user "apis" do
222 template "/usr/local/bin/cleanup-rails-assets" do
224 source "cleanup-assets.erb"
230 systemd_service "rails-jobs@" do
231 description "Rails job queue runner"
233 environment "RAILS_ENV" => "production", "SLEEP_DELAY" => "60"
235 working_directory "/srv/%i.apis.dev.openstreetmap.org/rails"
236 exec_start "#{node[:ruby][:bundle]} exec rails jobs:work"
241 protect_system "full"
243 no_new_privileges true
246 systemd_service "cgimap@" do
247 description "OpenStreetMap API Server"
249 environment_file "/etc/default/cgimap-%i"
251 exec_start "/srv/%i.apis.dev.openstreetmap.org/cgimap/openstreetmap-cgimap --daemon --port $CGIMAP_PORT --instances 5"
252 exec_reload "/bin/kill -HUP $MAINPID"
255 protect_system "full"
257 no_new_privileges true
263 Dir.glob("/srv/*.apis.dev.openstreetmap.org").each do |dir|
264 node.default_unless[:dev][:rails][File.basename(dir).split(".").first] = {}
267 node[:dev][:rails].each do |name, details|
268 database_name = details[:database] || "apis_#{name}"
269 site_name = "#{name}.apis.dev.openstreetmap.org"
270 site_directory = "/srv/#{name}.apis.dev.openstreetmap.org"
271 log_directory = "#{site_directory}/logs"
272 rails_directory = "#{site_directory}/rails"
273 cgimap_directory = "#{site_directory}/cgimap"
274 gpx_directory = "#{site_directory}/gpx"
276 if details[:repository]
277 site_aliases = details[:aliases] || []
278 secret_key_base = persistent_token("dev", "rails", name, "secret_key_base")
280 postgresql_database database_name do
285 postgresql_extension "#{database_name}_btree_gist" do
287 database database_name
288 extension "btree_gist"
291 directory site_directory do
297 directory log_directory do
303 directory gpx_directory do
309 directory "#{gpx_directory}/traces" do
315 directory "#{gpx_directory}/images" do
321 rails_port site_name do
322 directory rails_directory
325 repository details[:repository]
326 revision details[:revision]
327 database_port node[:postgresql][:clusters][:"14/main"][:port]
328 database_name database_name
329 database_username "apis"
330 email_from "OpenStreetMap <web@noreply.openstreetmap.org>"
331 gpx_dir gpx_directory
332 log_path "#{log_directory}/rails.log"
333 memcache_servers ["127.0.0.1"]
336 trace_use_job_queue true
339 template "#{rails_directory}/config/initializers/setup.rb" do
340 source "rails.setup.rb.erb"
344 variables :site => site_name
345 notifies :restart, "rails_port[#{site_name}]"
348 service "rails-jobs@#{name}" do
349 action [:enable, :start]
350 supports :restart => true
351 subscribes :restart, "rails_port[#{site_name}]"
352 subscribes :restart, "systemd_service[#{name}]"
353 only_if "fgrep -q delayed_job #{rails_directory}/Gemfile.lock"
356 if details[:cgimap_repository]
357 git cgimap_directory do
359 repository details[:cgimap_repository]
360 revision details[:cgimap_revision]
365 execute "#{cgimap_directory}/autogen.sh" do
367 command "./autogen.sh"
371 subscribes :run, "git[#{cgimap_directory}]", :immediately
374 execute "#{cgimap_directory}/configure" do
376 command "./configure --with-fcgi=/usr --with-boost-libdir=/usr/lib/x86_64-linux-gnu --enable-yajl"
380 subscribes :run, "execute[#{cgimap_directory}/autogen.sh]", :immediately
383 execute "#{cgimap_directory}/Makefile" do
389 subscribes :run, "execute[#{cgimap_directory}/configure]", :immediately
390 notifies :restart, "service[cgimap@#{name}]"
393 template "/etc/default/cgimap-#{name}" do
394 source "cgimap.environment.erb"
398 variables :cgimap_port => cgimap_port,
399 :database_port => node[:postgresql][:clusters][:"14/main"][:port],
400 :database_name => database_name,
401 :log_directory => log_directory
402 notifies :restart, "service[cgimap@#{name}]"
405 service "cgimap@#{name}" do
406 action [:start, :enable]
410 ssl_certificate site_name do
411 domains [site_name] + site_aliases
412 notifies :reload, "service[apache2]"
415 apache_site site_name do
416 template "apache.rails.erb"
417 variables :application_name => name,
418 :aliases => site_aliases,
419 :secret_key_base => secret_key_base,
420 :cgimap_enabled => details.key?(:cgimap_repository),
421 :cgimap_port => cgimap_port
424 template "/etc/logrotate.d/apis-#{name}" do
425 source "logrotate.apis.erb"
429 variables :name => name,
430 :log_directory => log_directory,
431 :rails_directory => rails_directory
436 file "/etc/logrotate.d/apis-#{name}" do
440 apache_site site_name do
444 service "cgimap@#{name}" do
445 action [:stop, :disable]
448 file "/etc/default/cgimap-#{name}" do
452 service "rails-jobs@#{name}" do
453 action [:stop, :disable]
456 directory site_directory do
461 file "/etc/cron.daily/rails-#{site_name.tr('.', '-')}" do
465 postgresql_database database_name do
472 directory "/srv/apis.dev.openstreetmap.org" do
478 template "/srv/apis.dev.openstreetmap.org/index.html" do
479 source "apis.html.erb"
485 ssl_certificate "apis.dev.openstreetmap.org" do
486 domains "apis.dev.openstreetmap.org"
487 notifies :reload, "service[apache2]"
490 apache_site "apis.dev.openstreetmap.org" do
491 template "apache.apis.erb"
494 node[:postgresql][:clusters].each_key do |name|
495 postgresql_munin name do
502 directory "/srv/ooc.openstreetmap.org" do
508 remote_directory "/srv/ooc.openstreetmap.org/html" do
518 ssl_certificate "ooc.openstreetmap.org" do
519 domains ["ooc.openstreetmap.org",
520 "a.ooc.openstreetmap.org",
521 "b.ooc.openstreetmap.org",
522 "c.ooc.openstreetmap.org"]
523 notifies :reload, "service[apache2]"
526 apache_site "ooc.openstreetmap.org" do
527 template "apache.ooc.erb"