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"
66 libboost-program-options-dev
67 libboost-date-time-dev
68 libboost-filesystem-dev
78 python_package "geojson" do
83 apache_module "expires"
84 apache_module "headers"
86 apache_module "proxy_fcgi"
87 apache_module "rewrite"
88 apache_module "suexec"
89 apache_module "userdir"
91 apache_module "wsgi" do
92 package "libapache2-mod-wsgi-py3"
95 package "apache2-suexec-pristine"
100 pm_min_spare_servers 2
101 pm_max_spare_servers 6
108 directory "/srv/dev.openstreetmap.org" do
114 template "/srv/dev.openstreetmap.org/index.html" do
115 source "dev.html.erb"
121 ssl_certificate "dev.openstreetmap.org" do
122 domains "dev.openstreetmap.org"
123 notifies :reload, "service[apache2]"
126 apache_site "dev.openstreetmap.org" do
127 template "apache.dev.erb"
132 template "/etc/phppgadmin/config.inc.php" do
133 source "phppgadmin.conf.erb"
139 file "/etc/apache2/conf.d/phppgadmin" do
143 ssl_certificate "phppgadmin.dev.openstreetmap.org" do
144 domains "phppgadmin.dev.openstreetmap.org"
145 notifies :reload, "service[apache2]"
148 apache_site "phppgadmin.dev.openstreetmap.org" do
149 template "apache.phppgadmin.erb"
152 search(:accounts, "*:*").each do |account|
154 details = node[:accounts][:users][name] || {}
156 next unless %w[user administrator].include?(details[:status])
158 user_home = details[:home] || account["home"] || "#{node[:accounts][:home]}/#{name}"
160 next unless File.directory?("#{user_home}/public_html")
167 pm_min_spare_servers 2
168 pm_max_spare_servers 6
169 pm_max_requests 10000
170 request_terminate_timeout 1800
171 environment "HOSTNAME" => "$HOSTNAME",
172 "PATH" => "/usr/local/bin:/usr/bin:/bin",
176 php_values "max_execution_time" => "300",
177 "memory_limit" => "128M",
178 "post_max_size" => "32M",
179 "upload_max_filesize" => "32M"
180 php_admin_values "sendmail_path" => "/usr/sbin/sendmail -t -i -f #{name}@errol.openstreetmap.org",
181 "open_basedir" => "/home/#{name}/:/tmp/:/usr/share/php/"
182 php_flags "display_errors" => "on"
185 ssl_certificate "#{name}.dev.openstreetmap.org" do
186 domains ["#{name}.dev.openstreetmap.org", "#{name}.dev.osm.org"]
187 notifies :reload, "service[apache2]"
190 apache_site "#{name}.dev.openstreetmap.org" do
191 template "apache.user.erb"
192 directory "#{user_home}/public_html"
193 variables :user => name
196 template "/etc/sudoers.d/#{name}" do
197 source "sudoers.user.erb"
201 variables :user => name
205 if node[:postgresql][:clusters][:"14/main"]
206 postgresql_user "apis" do
210 template "/usr/local/bin/cleanup-rails-assets" do
212 source "cleanup-assets.erb"
218 ruby_version = node[:passenger][:ruby_version]
220 systemd_service "rails-jobs@" do
221 description "Rails job queue runner"
224 working_directory "/srv/%i.apis.dev.openstreetmap.org/rails"
225 exec_start "/usr/local/bin/bundle#{ruby_version} exec rake jobs:work"
229 protect_system "full"
231 no_new_privileges true
234 systemd_service "cgimap@" do
235 description "OpenStreetMap API Server"
237 environment_file "/etc/default/cgimap-%i"
239 exec_start "/srv/%i.apis.dev.openstreetmap.org/cgimap/openstreetmap-cgimap --daemon --port $CGIMAP_PORT --instances 5"
240 exec_reload "/bin/kill -HUP $MAINPID"
243 protect_system "full"
245 no_new_privileges true
251 node[:dev][:rails].each do |name, details|
252 database_name = details[:database] || "apis_#{name}"
253 site_name = "#{name}.apis.dev.openstreetmap.org"
254 site_directory = "/srv/#{name}.apis.dev.openstreetmap.org"
255 log_directory = "#{site_directory}/logs"
256 rails_directory = "#{site_directory}/rails"
257 cgimap_directory = "#{site_directory}/cgimap"
258 gpx_directory = "#{site_directory}/gpx"
260 if details[:repository]
261 site_aliases = details[:aliases] || []
262 secret_key_base = persistent_token("dev", "rails", name, "secret_key_base")
264 postgresql_database database_name do
269 postgresql_extension "#{database_name}_btree_gist" do
271 database database_name
272 extension "btree_gist"
275 directory site_directory do
281 directory log_directory do
287 directory gpx_directory do
293 directory "#{gpx_directory}/traces" do
299 directory "#{gpx_directory}/images" do
305 rails_port site_name do
307 directory rails_directory
310 repository details[:repository]
311 revision details[:revision]
312 database_port node[:postgresql][:clusters][:"14/main"][:port]
313 database_name database_name
314 database_username "apis"
315 email_from "OpenStreetMap <web@noreply.openstreetmap.org>"
316 gpx_dir gpx_directory
317 log_path "#{log_directory}/rails.log"
318 memcache_servers ["127.0.0.1"]
321 trace_use_job_queue true
324 template "#{rails_directory}/config/initializers/setup.rb" do
325 source "rails.setup.rb.erb"
329 variables :site => site_name
330 notifies :restart, "rails_port[#{site_name}]"
333 service "rails-jobs@#{name}" do
334 action [:enable, :start]
335 supports :restart => true
336 subscribes :restart, "rails_port[#{site_name}]"
337 subscribes :restart, "systemd_service[#{name}]"
338 only_if "fgrep -q delayed_job #{rails_directory}/Gemfile.lock"
341 if details[:cgimap_repository]
342 git cgimap_directory do
344 repository details[:cgimap_repository]
345 revision details[:cgimap_revision]
350 execute "#{cgimap_directory}/autogen.sh" do
352 command "./autogen.sh"
356 subscribes :run, "git[#{cgimap_directory}]", :immediately
359 execute "#{cgimap_directory}/configure" do
361 command "./configure --with-fcgi=/usr --with-boost-libdir=/usr/lib/x86_64-linux-gnu --enable-yajl"
365 subscribes :run, "execute[#{cgimap_directory}/autogen.sh]", :immediately
368 execute "#{cgimap_directory}/Makefile" do
374 subscribes :run, "execute[#{cgimap_directory}/configure]", :immediately
375 notifies :restart, "service[cgimap@#{name}]"
378 template "/etc/default/cgimap-#{name}" do
379 source "cgimap.environment.erb"
383 variables :cgimap_port => cgimap_port,
384 :database_port => node[:postgresql][:clusters][:"14/main"][:port],
385 :database_name => database_name,
386 :log_directory => log_directory
387 notifies :restart, "service[cgimap@#{name}]"
390 service "cgimap@#{name}" do
391 action [:start, :enable]
395 ssl_certificate site_name do
396 domains [site_name] + site_aliases
397 notifies :reload, "service[apache2]"
400 apache_site site_name do
401 template "apache.rails.erb"
402 variables :application_name => name,
403 :aliases => site_aliases,
404 :secret_key_base => secret_key_base,
405 :cgimap_enabled => details.key?(:cgimap_repository),
406 :cgimap_port => cgimap_port
409 template "/etc/logrotate.d/apis-#{name}" do
410 source "logrotate.apis.erb"
414 variables :name => name,
415 :log_directory => log_directory,
416 :rails_directory => rails_directory
421 file "/etc/logrotate.d/apis-#{name}" do
425 apache_site site_name do
429 service "cgimap@#{name}" do
430 action [:stop, :disable]
433 file "/etc/default/cgimap-#{name}" do
437 directory site_directory do
442 file "/etc/cron.daily/rails-#{site_name.tr('.', '-')}" do
446 postgresql_database database_name do
453 directory "/srv/apis.dev.openstreetmap.org" do
459 template "/srv/apis.dev.openstreetmap.org/index.html" do
460 source "apis.html.erb"
466 ssl_certificate "apis.dev.openstreetmap.org" do
467 domains "apis.dev.openstreetmap.org"
468 notifies :reload, "service[apache2]"
471 apache_site "apis.dev.openstreetmap.org" do
472 template "apache.apis.erb"
475 node[:postgresql][:clusters].each_key do |name|
476 postgresql_munin name do
483 directory "/srv/ooc.openstreetmap.org" do
489 remote_directory "/srv/ooc.openstreetmap.org/html" do
499 ssl_certificate "ooc.openstreetmap.org" do
500 domains ["ooc.openstreetmap.org",
501 "a.ooc.openstreetmap.org",
502 "b.ooc.openstreetmap.org",
503 "c.ooc.openstreetmap.org"]
504 notifies :reload, "service[apache2]"
507 apache_site "ooc.openstreetmap.org" do
508 template "apache.ooc.erb"