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"
81 apache_module "expires"
82 apache_module "headers"
84 apache_module "proxy_fcgi"
85 apache_module "rewrite"
86 apache_module "suexec"
87 apache_module "userdir"
90 package "apache2-suexec-pristine"
93 template "fpm-default.conf.erb"
100 directory "/srv/dev.openstreetmap.org" do
106 template "/srv/dev.openstreetmap.org/index.html" do
107 source "dev.html.erb"
113 ssl_certificate "dev.openstreetmap.org" do
114 domains "dev.openstreetmap.org"
115 notifies :reload, "service[apache2]"
118 apache_site "dev.openstreetmap.org" do
119 template "apache.dev.erb"
124 template "/etc/phppgadmin/config.inc.php" do
125 source "phppgadmin.conf.erb"
131 file "/etc/apache2/conf.d/phppgadmin" do
135 ssl_certificate "phppgadmin.dev.openstreetmap.org" do
136 domains "phppgadmin.dev.openstreetmap.org"
137 notifies :reload, "service[apache2]"
140 apache_site "phppgadmin.dev.openstreetmap.org" do
141 template "apache.phppgadmin.erb"
144 search(:accounts, "*:*").each do |account|
146 details = node[:accounts][:users][name] || {}
148 next unless %w[user administrator].include?(details[:status])
150 user_home = details[:home] || account["home"] || "#{node[:accounts][:home]}/#{name}"
152 next unless File.directory?("#{user_home}/public_html")
154 port = 7000 + account["uid"].to_i
157 template "fpm.conf.erb"
158 variables :user => name, :port => port
161 ssl_certificate "#{name}.dev.openstreetmap.org" do
162 domains ["#{name}.dev.openstreetmap.org", "#{name}.dev.osm.org"]
163 notifies :reload, "service[apache2]"
166 apache_site "#{name}.dev.openstreetmap.org" do
167 template "apache.user.erb"
168 directory "#{user_home}/public_html"
169 variables :user => name, :port => port
172 template "/etc/sudoers.d/#{name}" do
173 source "sudoers.user.erb"
177 variables :user => name
181 if node[:postgresql][:clusters][:"9.5/main"]
182 postgresql_user "apis" do
186 template "/usr/local/bin/cleanup-rails-assets" do
188 source "cleanup-assets.erb"
194 ruby_version = node[:passenger][:ruby_version]
196 systemd_service "rails-jobs@" do
197 description "Rails job queue runner"
200 working_directory "/srv/%i.apis.dev.openstreetmap.org/rails"
201 exec_start "/usr/local/bin/bundle#{ruby_version} exec rake jobs:work"
205 protect_system "full"
207 no_new_privileges true
210 systemd_service "cgimap@" do
211 description "OpenStreetMap API Server"
213 environment_file "/etc/default/cgimap-%i"
215 exec_start "/srv/%i.apis.dev.openstreetmap.org/cgimap/openstreetmap-cgimap --daemon --port $CGIMAP_PORT --instances 5"
216 exec_reload "/bin/kill -HUP $MAINPID"
219 protect_system "full"
221 no_new_privileges true
227 node[:dev][:rails].each do |name, details|
228 database_name = details[:database] || "apis_#{name}"
229 site_name = "#{name}.apis.dev.openstreetmap.org"
230 site_directory = "/srv/#{name}.apis.dev.openstreetmap.org"
231 log_directory = "#{site_directory}/logs"
232 rails_directory = "#{site_directory}/rails"
233 cgimap_directory = "#{site_directory}/cgimap"
234 gpx_directory = "#{site_directory}/gpx"
236 if details[:repository]
237 site_aliases = details[:aliases] || []
238 secret_key_base = details[:secret_key_base] || SecureRandom.base64(96)
240 node.normal[:dev][:rails][name][:secret_key_base] = secret_key_base
242 postgresql_database database_name do
247 postgresql_extension "#{database_name}_btree_gist" do
249 database database_name
250 extension "btree_gist"
253 directory site_directory do
259 directory log_directory do
265 directory gpx_directory do
271 directory "#{gpx_directory}/traces" do
277 directory "#{gpx_directory}/images" do
283 rails_port site_name do
285 directory rails_directory
288 repository details[:repository]
289 revision details[:revision]
290 database_port node[:postgresql][:clusters][:"9.5/main"][:port]
291 database_name database_name
292 database_username "apis"
293 gpx_dir gpx_directory
294 log_path "#{log_directory}/rails.log"
295 memcache_servers ["127.0.0.1"]
298 trace_use_job_queue true
301 template "#{rails_directory}/config/initializers/setup.rb" do
302 source "rails.setup.rb.erb"
306 variables :site => site_name
307 notifies :restart, "rails_port[#{site_name}]"
310 service "rails-jobs@#{name}" do
311 action [:enable, :start]
312 supports :restart => true
313 subscribes :restart, "rails_port[#{site_name}]"
314 subscribes :restart, "systemd_service[#{name}]"
315 only_if "fgrep -q delayed_job #{rails_directory}/Gemfile.lock"
318 if details[:cgimap_repository]
319 git cgimap_directory do
321 repository details[:cgimap_repository]
322 revision details[:cgimap_revision]
327 execute "#{cgimap_directory}/autogen.sh" do
329 command "./autogen.sh"
333 subscribes :run, "git[#{cgimap_directory}]", :immediate
336 execute "#{cgimap_directory}/configure" do
338 command "./configure --with-fcgi=/usr --with-boost-libdir=/usr/lib/x86_64-linux-gnu --enable-yajl"
342 subscribes :run, "execute[#{cgimap_directory}/autogen.sh]", :immediate
345 execute "#{cgimap_directory}/Makefile" do
351 subscribes :run, "execute[#{cgimap_directory}/configure]", :immediate
352 notifies :restart, "service[cgimap@#{name}]"
355 template "/etc/default/cgimap-#{name}" do
356 source "cgimap.environment.erb"
360 variables :cgimap_port => cgimap_port,
361 :database_port => node[:postgresql][:clusters][:"9.5/main"][:port],
362 :database_name => database_name,
363 :log_directory => log_directory
364 notifies :restart, "service[cgimap@#{name}]"
367 service "cgimap@#{name}" do
368 action [:start, :enable]
372 ssl_certificate site_name do
373 domains [site_name] + site_aliases
374 notifies :reload, "service[apache2]"
377 apache_site site_name do
378 template "apache.rails.erb"
379 variables :application_name => name,
380 :aliases => site_aliases,
381 :secret_key_base => secret_key_base,
382 :cgimap_enabled => details.key?(:cgimap_repository),
383 :cgimap_port => cgimap_port
386 template "/etc/logrotate.d/apis-#{name}" do
387 source "logrotate.apis.erb"
391 variables :name => name,
392 :log_directory => log_directory,
393 :rails_directory => rails_directory
398 file "/etc/logrotate.d/apis-#{name}" do
402 apache_site site_name do
406 service "cgimap@#{name}" do
407 action [:stop, :disable]
410 file "/etc/default/cgimap-#{name}" do
414 directory site_directory do
419 file "/etc/cron.daily/rails-#{site_name.tr('.', '-')}" do
423 postgresql_database database_name do
428 node.normal[:dev][:rails].delete(name)
432 directory "/srv/apis.dev.openstreetmap.org" do
438 template "/srv/apis.dev.openstreetmap.org/index.html" do
439 source "apis.html.erb"
445 ssl_certificate "apis.dev.openstreetmap.org" do
446 domains "apis.dev.openstreetmap.org"
447 notifies :reload, "service[apache2]"
450 apache_site "apis.dev.openstreetmap.org" do
451 template "apache.apis.erb"
454 node[:postgresql][:clusters].each_key do |name|
455 postgresql_munin name do
462 directory "/srv/ooc.openstreetmap.org" do
468 remote_directory "/srv/ooc.openstreetmap.org/html" do
478 ssl_certificate "ooc.openstreetmap.org" do
479 domains ["ooc.openstreetmap.org",
480 "a.ooc.openstreetmap.org",
481 "b.ooc.openstreetmap.org",
482 "c.ooc.openstreetmap.org"]
483 notifies :reload, "service[apache2]"
486 apache_site "ooc.openstreetmap.org" do
487 template "apache.ooc.erb"