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"
97 template "fpm-default.conf.erb"
104 directory "/srv/dev.openstreetmap.org" do
110 template "/srv/dev.openstreetmap.org/index.html" do
111 source "dev.html.erb"
117 ssl_certificate "dev.openstreetmap.org" do
118 domains "dev.openstreetmap.org"
119 notifies :reload, "service[apache2]"
122 apache_site "dev.openstreetmap.org" do
123 template "apache.dev.erb"
128 template "/etc/phppgadmin/config.inc.php" do
129 source "phppgadmin.conf.erb"
135 file "/etc/apache2/conf.d/phppgadmin" do
139 ssl_certificate "phppgadmin.dev.openstreetmap.org" do
140 domains "phppgadmin.dev.openstreetmap.org"
141 notifies :reload, "service[apache2]"
144 apache_site "phppgadmin.dev.openstreetmap.org" do
145 template "apache.phppgadmin.erb"
148 search(:accounts, "*:*").each do |account|
150 details = node[:accounts][:users][name] || {}
152 next unless %w[user administrator].include?(details[:status])
154 user_home = details[:home] || account["home"] || "#{node[:accounts][:home]}/#{name}"
156 next unless File.directory?("#{user_home}/public_html")
158 port = 7000 + account["uid"].to_i
161 template "fpm.conf.erb"
162 variables :user => name, :port => port
165 ssl_certificate "#{name}.dev.openstreetmap.org" do
166 domains ["#{name}.dev.openstreetmap.org", "#{name}.dev.osm.org"]
167 notifies :reload, "service[apache2]"
170 apache_site "#{name}.dev.openstreetmap.org" do
171 template "apache.user.erb"
172 directory "#{user_home}/public_html"
173 variables :user => name, :port => port
176 template "/etc/sudoers.d/#{name}" do
177 source "sudoers.user.erb"
181 variables :user => name
185 if node[:postgresql][:clusters][:"12/main"]
186 postgresql_user "apis" do
190 template "/usr/local/bin/cleanup-rails-assets" do
192 source "cleanup-assets.erb"
198 ruby_version = node[:passenger][:ruby_version]
200 systemd_service "rails-jobs@" do
201 description "Rails job queue runner"
204 working_directory "/srv/%i.apis.dev.openstreetmap.org/rails"
205 exec_start "/usr/local/bin/bundle#{ruby_version} exec rake jobs:work"
209 protect_system "full"
211 no_new_privileges true
214 systemd_service "cgimap@" do
215 description "OpenStreetMap API Server"
217 environment_file "/etc/default/cgimap-%i"
219 exec_start "/srv/%i.apis.dev.openstreetmap.org/cgimap/openstreetmap-cgimap --daemon --port $CGIMAP_PORT --instances 5"
220 exec_reload "/bin/kill -HUP $MAINPID"
223 protect_system "full"
225 no_new_privileges true
231 node[:dev][:rails].each do |name, details|
232 database_name = details[:database] || "apis_#{name}"
233 site_name = "#{name}.apis.dev.openstreetmap.org"
234 site_directory = "/srv/#{name}.apis.dev.openstreetmap.org"
235 log_directory = "#{site_directory}/logs"
236 rails_directory = "#{site_directory}/rails"
237 cgimap_directory = "#{site_directory}/cgimap"
238 gpx_directory = "#{site_directory}/gpx"
240 if details[:repository]
241 site_aliases = details[:aliases] || []
242 secret_key_base = details[:secret_key_base] || SecureRandom.base64(96)
244 node.normal[:dev][:rails][name][:secret_key_base] = secret_key_base
246 postgresql_database database_name do
251 postgresql_extension "#{database_name}_btree_gist" do
253 database database_name
254 extension "btree_gist"
257 directory site_directory do
263 directory log_directory do
269 directory gpx_directory do
275 directory "#{gpx_directory}/traces" do
281 directory "#{gpx_directory}/images" do
287 rails_port site_name do
289 directory rails_directory
292 repository details[:repository]
293 revision details[:revision]
294 database_port node[:postgresql][:clusters][:"12/main"][:port]
295 database_name database_name
296 database_username "apis"
297 gpx_dir gpx_directory
298 log_path "#{log_directory}/rails.log"
299 memcache_servers ["127.0.0.1"]
302 trace_use_job_queue true
305 template "#{rails_directory}/config/initializers/setup.rb" do
306 source "rails.setup.rb.erb"
310 variables :site => site_name
311 notifies :restart, "rails_port[#{site_name}]"
314 service "rails-jobs@#{name}" do
315 action [:enable, :start]
316 supports :restart => true
317 subscribes :restart, "rails_port[#{site_name}]"
318 subscribes :restart, "systemd_service[#{name}]"
319 only_if "fgrep -q delayed_job #{rails_directory}/Gemfile.lock"
322 if details[:cgimap_repository]
323 git cgimap_directory do
325 repository details[:cgimap_repository]
326 revision details[:cgimap_revision]
331 execute "#{cgimap_directory}/autogen.sh" do
333 command "./autogen.sh"
337 subscribes :run, "git[#{cgimap_directory}]", :immediate
340 execute "#{cgimap_directory}/configure" do
342 command "./configure --with-fcgi=/usr --with-boost-libdir=/usr/lib/x86_64-linux-gnu --enable-yajl"
346 subscribes :run, "execute[#{cgimap_directory}/autogen.sh]", :immediate
349 execute "#{cgimap_directory}/Makefile" do
355 subscribes :run, "execute[#{cgimap_directory}/configure]", :immediate
356 notifies :restart, "service[cgimap@#{name}]"
359 template "/etc/default/cgimap-#{name}" do
360 source "cgimap.environment.erb"
364 variables :cgimap_port => cgimap_port,
365 :database_port => node[:postgresql][:clusters][:"12/main"][:port],
366 :database_name => database_name,
367 :log_directory => log_directory
368 notifies :restart, "service[cgimap@#{name}]"
371 service "cgimap@#{name}" do
372 action [:start, :enable]
376 ssl_certificate site_name do
377 domains [site_name] + site_aliases
378 notifies :reload, "service[apache2]"
381 apache_site site_name do
382 template "apache.rails.erb"
383 variables :application_name => name,
384 :aliases => site_aliases,
385 :secret_key_base => secret_key_base,
386 :cgimap_enabled => details.key?(:cgimap_repository),
387 :cgimap_port => cgimap_port
390 template "/etc/logrotate.d/apis-#{name}" do
391 source "logrotate.apis.erb"
395 variables :name => name,
396 :log_directory => log_directory,
397 :rails_directory => rails_directory
402 file "/etc/logrotate.d/apis-#{name}" do
406 apache_site site_name do
410 service "cgimap@#{name}" do
411 action [:stop, :disable]
414 file "/etc/default/cgimap-#{name}" do
418 directory site_directory do
423 file "/etc/cron.daily/rails-#{site_name.tr('.', '-')}" do
427 postgresql_database database_name do
432 node.normal[:dev][:rails].delete(name)
436 directory "/srv/apis.dev.openstreetmap.org" do
442 template "/srv/apis.dev.openstreetmap.org/index.html" do
443 source "apis.html.erb"
449 ssl_certificate "apis.dev.openstreetmap.org" do
450 domains "apis.dev.openstreetmap.org"
451 notifies :reload, "service[apache2]"
454 apache_site "apis.dev.openstreetmap.org" do
455 template "apache.apis.erb"
458 node[:postgresql][:clusters].each_key do |name|
459 postgresql_munin name do
466 directory "/srv/ooc.openstreetmap.org" do
472 remote_directory "/srv/ooc.openstreetmap.org/html" do
482 ssl_certificate "ooc.openstreetmap.org" do
483 domains ["ooc.openstreetmap.org",
484 "a.ooc.openstreetmap.org",
485 "b.ooc.openstreetmap.org",
486 "c.ooc.openstreetmap.org"]
487 notifies :reload, "service[apache2]"
490 apache_site "ooc.openstreetmap.org" do
491 template "apache.ooc.erb"