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"
65 libboost-program-options-dev
66 libboost-date-time-dev
67 libboost-filesystem-dev
77 python_package "geojson" do
82 apache_module "expires"
83 apache_module "headers"
85 apache_module "proxy_fcgi"
86 apache_module "rewrite"
87 apache_module "suexec"
88 apache_module "userdir"
90 apache_module "wsgi" do
91 package "libapache2-mod-wsgi-py3"
94 package "apache2-suexec-pristine"
99 pm_min_spare_servers 2
100 pm_max_spare_servers 6
107 directory "/srv/dev.openstreetmap.org" do
113 template "/srv/dev.openstreetmap.org/index.html" do
114 source "dev.html.erb"
120 ssl_certificate "dev.openstreetmap.org" do
121 domains "dev.openstreetmap.org"
122 notifies :reload, "service[apache2]"
125 apache_site "dev.openstreetmap.org" do
126 template "apache.dev.erb"
131 template "/etc/phppgadmin/config.inc.php" do
132 source "phppgadmin.conf.erb"
138 file "/etc/apache2/conf.d/phppgadmin" do
142 ssl_certificate "phppgadmin.dev.openstreetmap.org" do
143 domains "phppgadmin.dev.openstreetmap.org"
144 notifies :reload, "service[apache2]"
147 apache_site "phppgadmin.dev.openstreetmap.org" do
148 template "apache.phppgadmin.erb"
151 search(:accounts, "*:*").each do |account|
153 details = node[:accounts][:users][name] || {}
155 next unless %w[user administrator].include?(details[:status])
157 user_home = details[:home] || account["home"] || "#{node[:accounts][:home]}/#{name}"
159 next unless File.directory?("#{user_home}/public_html")
166 pm_min_spare_servers 2
167 pm_max_spare_servers 6
168 pm_max_requests 10000
169 request_terminate_timeout 1800
170 environment "HOSTNAME" => "$HOSTNAME",
171 "PATH" => "/usr/local/bin:/usr/bin:/bin",
175 php_values "max_execution_time" => "300",
176 "memory_limit" => "128M",
177 "post_max_size" => "32M",
178 "upload_max_filesize" => "32M"
179 php_admin_values "sendmail_path" => "/usr/sbin/sendmail -t -i -f #{name}@errol.openstreetmap.org",
180 "open_basedir" => "/home/#{name}/:/tmp/:/usr/share/php/"
181 php_flags "display_errors" => "on"
184 ssl_certificate "#{name}.dev.openstreetmap.org" do
185 domains ["#{name}.dev.openstreetmap.org", "#{name}.dev.osm.org"]
186 notifies :reload, "service[apache2]"
189 apache_site "#{name}.dev.openstreetmap.org" do
190 template "apache.user.erb"
191 directory "#{user_home}/public_html"
192 variables :user => name
195 template "/etc/sudoers.d/#{name}" do
196 source "sudoers.user.erb"
200 variables :user => name
204 if node[:postgresql][:clusters][:"13/main"]
205 postgresql_user "apis" do
209 template "/usr/local/bin/cleanup-rails-assets" do
211 source "cleanup-assets.erb"
217 ruby_version = node[:passenger][:ruby_version]
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 "/usr/local/bin/bundle#{ruby_version} 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 node[:dev][:rails].each do |name, details|
251 database_name = details[:database] || "apis_#{name}"
252 site_name = "#{name}.apis.dev.openstreetmap.org"
253 site_directory = "/srv/#{name}.apis.dev.openstreetmap.org"
254 log_directory = "#{site_directory}/logs"
255 rails_directory = "#{site_directory}/rails"
256 cgimap_directory = "#{site_directory}/cgimap"
257 gpx_directory = "#{site_directory}/gpx"
259 if details[:repository]
260 site_aliases = details[:aliases] || []
261 secret_key_base = persistent_token("dev", "rails", name, "secret_key_base")
263 postgresql_database database_name do
268 postgresql_extension "#{database_name}_btree_gist" do
270 database database_name
271 extension "btree_gist"
274 directory site_directory do
280 directory log_directory do
286 directory gpx_directory do
292 directory "#{gpx_directory}/traces" do
298 directory "#{gpx_directory}/images" do
304 rails_port site_name do
306 directory rails_directory
309 repository details[:repository]
310 revision details[:revision]
311 database_port node[:postgresql][:clusters][:"13/main"][:port]
312 database_name database_name
313 database_username "apis"
314 email_from "OpenStreetMap <web@noreply.openstreetmap.org>"
315 gpx_dir gpx_directory
316 log_path "#{log_directory}/rails.log"
317 memcache_servers ["127.0.0.1"]
320 trace_use_job_queue true
323 template "#{rails_directory}/config/initializers/setup.rb" do
324 source "rails.setup.rb.erb"
328 variables :site => site_name
329 notifies :restart, "rails_port[#{site_name}]"
332 service "rails-jobs@#{name}" do
333 action [:enable, :start]
334 supports :restart => true
335 subscribes :restart, "rails_port[#{site_name}]"
336 subscribes :restart, "systemd_service[#{name}]"
337 only_if "fgrep -q delayed_job #{rails_directory}/Gemfile.lock"
340 if details[:cgimap_repository]
341 git cgimap_directory do
343 repository details[:cgimap_repository]
344 revision details[:cgimap_revision]
349 execute "#{cgimap_directory}/autogen.sh" do
351 command "./autogen.sh"
355 subscribes :run, "git[#{cgimap_directory}]", :immediate
358 execute "#{cgimap_directory}/configure" do
360 command "./configure --with-fcgi=/usr --with-boost-libdir=/usr/lib/x86_64-linux-gnu --enable-yajl"
364 subscribes :run, "execute[#{cgimap_directory}/autogen.sh]", :immediate
367 execute "#{cgimap_directory}/Makefile" do
373 subscribes :run, "execute[#{cgimap_directory}/configure]", :immediate
374 notifies :restart, "service[cgimap@#{name}]"
377 template "/etc/default/cgimap-#{name}" do
378 source "cgimap.environment.erb"
382 variables :cgimap_port => cgimap_port,
383 :database_port => node[:postgresql][:clusters][:"13/main"][:port],
384 :database_name => database_name,
385 :log_directory => log_directory
386 notifies :restart, "service[cgimap@#{name}]"
389 service "cgimap@#{name}" do
390 action [:start, :enable]
394 ssl_certificate site_name do
395 domains [site_name] + site_aliases
396 notifies :reload, "service[apache2]"
399 apache_site site_name do
400 template "apache.rails.erb"
401 variables :application_name => name,
402 :aliases => site_aliases,
403 :secret_key_base => secret_key_base,
404 :cgimap_enabled => details.key?(:cgimap_repository),
405 :cgimap_port => cgimap_port
408 template "/etc/logrotate.d/apis-#{name}" do
409 source "logrotate.apis.erb"
413 variables :name => name,
414 :log_directory => log_directory,
415 :rails_directory => rails_directory
420 file "/etc/logrotate.d/apis-#{name}" do
424 apache_site site_name do
428 service "cgimap@#{name}" do
429 action [:stop, :disable]
432 file "/etc/default/cgimap-#{name}" do
436 directory site_directory do
441 file "/etc/cron.daily/rails-#{site_name.tr('.', '-')}" do
445 postgresql_database database_name do
452 directory "/srv/apis.dev.openstreetmap.org" do
458 template "/srv/apis.dev.openstreetmap.org/index.html" do
459 source "apis.html.erb"
465 ssl_certificate "apis.dev.openstreetmap.org" do
466 domains "apis.dev.openstreetmap.org"
467 notifies :reload, "service[apache2]"
470 apache_site "apis.dev.openstreetmap.org" do
471 template "apache.apis.erb"
474 node[:postgresql][:clusters].each_key do |name|
475 postgresql_munin name do
482 directory "/srv/ooc.openstreetmap.org" do
488 remote_directory "/srv/ooc.openstreetmap.org/html" do
498 ssl_certificate "ooc.openstreetmap.org" do
499 domains ["ooc.openstreetmap.org",
500 "a.ooc.openstreetmap.org",
501 "b.ooc.openstreetmap.org",
502 "c.ooc.openstreetmap.org"]
503 notifies :reload, "service[apache2]"
506 apache_site "ooc.openstreetmap.org" do
507 template "apache.ooc.erb"