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"
67 libboost-program-options-dev
68 libboost-date-time-dev
69 libboost-filesystem-dev
79 python_package "geojson" do
84 apache_module "expires"
85 apache_module "headers"
87 apache_module "proxy_fcgi"
88 apache_module "rewrite"
89 apache_module "suexec"
90 apache_module "userdir"
92 apache_module "wsgi" do
93 package "libapache2-mod-wsgi-py3"
96 package "apache2-suexec-pristine"
101 pm_min_spare_servers 2
102 pm_max_spare_servers 6
109 directory "/srv/dev.openstreetmap.org" do
115 template "/srv/dev.openstreetmap.org/index.html" do
116 source "dev.html.erb"
122 ssl_certificate "dev.openstreetmap.org" do
123 domains "dev.openstreetmap.org"
124 notifies :reload, "service[apache2]"
127 apache_site "dev.openstreetmap.org" do
128 template "apache.dev.erb"
133 template "/etc/phppgadmin/config.inc.php" do
134 source "phppgadmin.conf.erb"
140 file "/etc/apache2/conf.d/phppgadmin" do
144 ssl_certificate "phppgadmin.dev.openstreetmap.org" do
145 domains "phppgadmin.dev.openstreetmap.org"
146 notifies :reload, "service[apache2]"
149 apache_site "phppgadmin.dev.openstreetmap.org" do
150 template "apache.phppgadmin.erb"
153 search(:accounts, "*:*").each do |account|
155 details = node[:accounts][:users][name] || {}
157 next unless %w[user administrator].include?(details[:status])
159 user_home = details[:home] || account["home"] || "#{node[:accounts][:home]}/#{name}"
161 next unless File.directory?("#{user_home}/public_html")
168 pm_min_spare_servers 2
169 pm_max_spare_servers 6
170 pm_max_requests 10000
171 request_terminate_timeout 1800
172 environment "HOSTNAME" => "$HOSTNAME",
173 "PATH" => "/usr/local/bin:/usr/bin:/bin",
177 php_values "max_execution_time" => "300",
178 "memory_limit" => "128M",
179 "post_max_size" => "32M",
180 "upload_max_filesize" => "32M"
181 php_admin_values "sendmail_path" => "/usr/sbin/sendmail -t -i -f #{name}@errol.openstreetmap.org",
182 "open_basedir" => "/home/#{name}/:/tmp/:/usr/share/php/"
183 php_flags "display_errors" => "on"
186 ssl_certificate "#{name}.dev.openstreetmap.org" do
187 domains ["#{name}.dev.openstreetmap.org", "#{name}.dev.osm.org"]
188 notifies :reload, "service[apache2]"
191 apache_site "#{name}.dev.openstreetmap.org" do
192 template "apache.user.erb"
193 directory "#{user_home}/public_html"
194 variables :user => name
197 template "/etc/sudoers.d/#{name}" do
198 source "sudoers.user.erb"
202 variables :user => name
206 if node[:postgresql][:clusters][:"14/main"]
207 postgresql_user "apis" do
211 template "/usr/local/bin/cleanup-rails-assets" do
213 source "cleanup-assets.erb"
219 systemd_service "rails-jobs@" do
220 description "Rails job queue runner"
223 working_directory "/srv/%i.apis.dev.openstreetmap.org/rails"
224 exec_start "#{node[:ruby][:bundle]} exec rake jobs:work"
228 protect_system "full"
230 no_new_privileges true
233 systemd_service "cgimap@" do
234 description "OpenStreetMap API Server"
236 environment_file "/etc/default/cgimap-%i"
238 exec_start "/srv/%i.apis.dev.openstreetmap.org/cgimap/openstreetmap-cgimap --daemon --port $CGIMAP_PORT --instances 5"
239 exec_reload "/bin/kill -HUP $MAINPID"
242 protect_system "full"
244 no_new_privileges true
250 Dir.glob("/srv/*.apis.dev.openstreetmap.org").each do |dir|
251 node.default_unless[:dev][:rails][File.basename(dir).split(".").first] = {}
254 node[:dev][:rails].each do |name, details|
255 database_name = details[:database] || "apis_#{name}"
256 site_name = "#{name}.apis.dev.openstreetmap.org"
257 site_directory = "/srv/#{name}.apis.dev.openstreetmap.org"
258 log_directory = "#{site_directory}/logs"
259 rails_directory = "#{site_directory}/rails"
260 cgimap_directory = "#{site_directory}/cgimap"
261 gpx_directory = "#{site_directory}/gpx"
263 if details[:repository]
264 site_aliases = details[:aliases] || []
265 secret_key_base = persistent_token("dev", "rails", name, "secret_key_base")
267 postgresql_database database_name do
272 postgresql_extension "#{database_name}_btree_gist" do
274 database database_name
275 extension "btree_gist"
278 directory site_directory do
284 directory log_directory do
290 directory gpx_directory do
296 directory "#{gpx_directory}/traces" do
302 directory "#{gpx_directory}/images" do
308 rails_port site_name do
309 directory rails_directory
312 repository details[:repository]
313 revision details[:revision]
314 database_port node[:postgresql][:clusters][:"14/main"][:port]
315 database_name database_name
316 database_username "apis"
317 email_from "OpenStreetMap <web@noreply.openstreetmap.org>"
318 gpx_dir gpx_directory
319 log_path "#{log_directory}/rails.log"
320 memcache_servers ["127.0.0.1"]
323 trace_use_job_queue true
326 template "#{rails_directory}/config/initializers/setup.rb" do
327 source "rails.setup.rb.erb"
331 variables :site => site_name
332 notifies :restart, "rails_port[#{site_name}]"
335 service "rails-jobs@#{name}" do
336 action [:enable, :start]
337 supports :restart => true
338 subscribes :restart, "rails_port[#{site_name}]"
339 subscribes :restart, "systemd_service[#{name}]"
340 only_if "fgrep -q delayed_job #{rails_directory}/Gemfile.lock"
343 if details[:cgimap_repository]
344 git cgimap_directory do
346 repository details[:cgimap_repository]
347 revision details[:cgimap_revision]
352 execute "#{cgimap_directory}/autogen.sh" do
354 command "./autogen.sh"
358 subscribes :run, "git[#{cgimap_directory}]", :immediately
361 execute "#{cgimap_directory}/configure" do
363 command "./configure --with-fcgi=/usr --with-boost-libdir=/usr/lib/x86_64-linux-gnu --enable-yajl"
367 subscribes :run, "execute[#{cgimap_directory}/autogen.sh]", :immediately
370 execute "#{cgimap_directory}/Makefile" do
376 subscribes :run, "execute[#{cgimap_directory}/configure]", :immediately
377 notifies :restart, "service[cgimap@#{name}]"
380 template "/etc/default/cgimap-#{name}" do
381 source "cgimap.environment.erb"
385 variables :cgimap_port => cgimap_port,
386 :database_port => node[:postgresql][:clusters][:"14/main"][:port],
387 :database_name => database_name,
388 :log_directory => log_directory
389 notifies :restart, "service[cgimap@#{name}]"
392 service "cgimap@#{name}" do
393 action [:start, :enable]
397 ssl_certificate site_name do
398 domains [site_name] + site_aliases
399 notifies :reload, "service[apache2]"
402 apache_site site_name do
403 template "apache.rails.erb"
404 variables :application_name => name,
405 :aliases => site_aliases,
406 :secret_key_base => secret_key_base,
407 :cgimap_enabled => details.key?(:cgimap_repository),
408 :cgimap_port => cgimap_port
411 template "/etc/logrotate.d/apis-#{name}" do
412 source "logrotate.apis.erb"
416 variables :name => name,
417 :log_directory => log_directory,
418 :rails_directory => rails_directory
423 file "/etc/logrotate.d/apis-#{name}" do
427 apache_site site_name do
431 service "cgimap@#{name}" do
432 action [:stop, :disable]
435 file "/etc/default/cgimap-#{name}" do
439 service "rails-jobs@#{name}" do
440 action [:stop, :disable]
443 directory site_directory do
448 file "/etc/cron.daily/rails-#{site_name.tr('.', '-')}" do
452 postgresql_database database_name do
459 directory "/srv/apis.dev.openstreetmap.org" do
465 template "/srv/apis.dev.openstreetmap.org/index.html" do
466 source "apis.html.erb"
472 ssl_certificate "apis.dev.openstreetmap.org" do
473 domains "apis.dev.openstreetmap.org"
474 notifies :reload, "service[apache2]"
477 apache_site "apis.dev.openstreetmap.org" do
478 template "apache.apis.erb"
481 node[:postgresql][:clusters].each_key do |name|
482 postgresql_munin name do
489 directory "/srv/ooc.openstreetmap.org" do
495 remote_directory "/srv/ooc.openstreetmap.org/html" do
505 ssl_certificate "ooc.openstreetmap.org" do
506 domains ["ooc.openstreetmap.org",
507 "a.ooc.openstreetmap.org",
508 "b.ooc.openstreetmap.org",
509 "c.ooc.openstreetmap.org"]
510 notifies :reload, "service[apache2]"
513 apache_site "ooc.openstreetmap.org" do
514 template "apache.ooc.erb"