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"
26 include_recipe "memcached"
27 include_recipe "mysql"
28 include_recipe "nodejs"
29 include_recipe "postgresql"
30 include_recipe "python"
65 libboost-program-options-dev
66 libboost-date-time-dev
67 libboost-filesystem-dev
77 python_package "geojson"
80 apache_module "expires"
81 apache_module "headers"
83 apache_module "proxy_fcgi"
84 apache_module "rewrite"
85 apache_module "suexec"
86 apache_module "userdir"
89 package "apache2-suexec-pristine"
91 service "php7.2-fpm" do
92 action [:enable, :start]
95 template "/etc/php/7.2/fpm/pool.d/default.conf" do
96 source "fpm-default.conf.erb"
100 notifies :reload, "service[php7.2-fpm]"
103 file "/etc/php/7.2/fpm/pool.d/www.conf" do
105 notifies :reload, "service[php7.2-fpm]"
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")
162 port = 7000 + account["uid"].to_i
164 template "/etc/php/7.2/fpm/pool.d/#{name}.conf" do
165 source "fpm.conf.erb"
169 variables :user => name, :port => port
170 notifies :reload, "service[php7.2-fpm]"
173 ssl_certificate "#{name}.dev.openstreetmap.org" do
174 domains ["#{name}.dev.openstreetmap.org", "#{name}.dev.osm.org"]
175 notifies :reload, "service[apache2]"
178 apache_site "#{name}.dev.openstreetmap.org" do
179 template "apache.user.erb"
180 directory "#{user_home}/public_html"
181 variables :user => name, :port => port
184 template "/etc/sudoers.d/#{name}" do
185 source "sudoers.user.erb"
189 variables :user => name
193 if node[:postgresql][:clusters][:"9.5/main"]
194 postgresql_user "apis" do
198 template "/usr/local/bin/cleanup-rails-assets" do
200 source "cleanup-assets.erb"
206 ruby_version = node[:passenger][:ruby_version]
208 systemd_service "rails-jobs@" do
209 description "Rails job queue runner"
212 working_directory "/srv/%i.apis.dev.openstreetmap.org/rails"
213 exec_start "/usr/local/bin/bundle#{ruby_version} exec rake jobs:work"
217 protect_system "full"
219 no_new_privileges true
222 systemd_service "cgimap@" do
223 description "OpenStreetMap API Server"
225 environment_file "/etc/default/cgimap-%i"
227 exec_start "/srv/%i.apis.dev.openstreetmap.org/cgimap/openstreetmap-cgimap --daemon --port $CGIMAP_PORT --instances 5"
228 exec_reload "/bin/kill -HUP $MAINPID"
231 protect_system "full"
233 no_new_privileges true
239 node[:dev][:rails].each do |name, details|
240 database_name = details[:database] || "apis_#{name}"
241 site_name = "#{name}.apis.dev.openstreetmap.org"
242 site_directory = "/srv/#{name}.apis.dev.openstreetmap.org"
243 log_directory = "#{site_directory}/logs"
244 rails_directory = "#{site_directory}/rails"
245 cgimap_directory = "#{site_directory}/cgimap"
246 gpx_directory = "#{site_directory}/gpx"
248 if details[:repository]
249 site_aliases = details[:aliases] || []
250 secret_key_base = details[:secret_key_base] || SecureRandom.base64(96)
252 node.normal[:dev][:rails][name][:secret_key_base] = secret_key_base
254 postgresql_database database_name do
259 postgresql_extension "#{database_name}_btree_gist" do
261 database database_name
262 extension "btree_gist"
265 directory site_directory do
271 directory log_directory do
277 directory gpx_directory do
283 directory "#{gpx_directory}/traces" do
289 directory "#{gpx_directory}/images" do
295 rails_port site_name do
297 directory rails_directory
300 repository details[:repository]
301 revision details[:revision]
302 database_port node[:postgresql][:clusters][:"9.5/main"][:port]
303 database_name database_name
304 database_username "apis"
305 gpx_dir gpx_directory
306 log_path "#{log_directory}/rails.log"
307 memcache_servers ["127.0.0.1"]
310 trace_use_job_queue true
313 template "#{rails_directory}/config/initializers/setup.rb" do
314 source "rails.setup.rb.erb"
318 variables :site => site_name
319 notifies :restart, "rails_port[#{site_name}]"
322 service "rails-jobs@#{name}" do
323 action [:enable, :start]
324 supports :restart => true
325 subscribes :restart, "rails_port[#{site_name}]"
326 subscribes :restart, "systemd_service[#{name}]"
327 only_if "fgrep -q delayed_job #{rails_directory}/Gemfile.lock"
330 if details[:cgimap_repository]
331 git cgimap_directory do
333 repository details[:cgimap_repository]
334 revision details[:cgimap_revision]
339 execute "#{cgimap_directory}/autogen.sh" do
341 command "./autogen.sh"
345 subscribes :run, "git[#{cgimap_directory}]", :immediate
348 execute "#{cgimap_directory}/configure" do
350 command "./configure --with-fcgi=/usr --with-boost-libdir=/usr/lib/x86_64-linux-gnu --enable-yajl"
354 subscribes :run, "execute[#{cgimap_directory}/autogen.sh]", :immediate
357 execute "#{cgimap_directory}/Makefile" do
363 subscribes :run, "execute[#{cgimap_directory}/configure]", :immediate
364 notifies :restart, "service[cgimap@#{name}]"
367 template "/etc/default/cgimap-#{name}" do
368 source "cgimap.environment.erb"
372 variables :cgimap_port => cgimap_port,
373 :database_port => node[:postgresql][:clusters][:"9.5/main"][:port],
374 :database_name => database_name,
375 :log_directory => log_directory
376 notifies :restart, "service[cgimap@#{name}]"
379 service "cgimap@#{name}" do
380 action [:start, :enable]
384 ssl_certificate site_name do
385 domains [site_name] + site_aliases
386 notifies :reload, "service[apache2]"
389 apache_site site_name do
390 template "apache.rails.erb"
391 variables :application_name => name,
392 :aliases => site_aliases,
393 :secret_key_base => secret_key_base,
394 :cgimap_enabled => details.key?(:cgimap_repository),
395 :cgimap_port => cgimap_port
398 template "/etc/logrotate.d/apis-#{name}" do
399 source "logrotate.apis.erb"
403 variables :name => name,
404 :log_directory => log_directory,
405 :rails_directory => rails_directory
410 file "/etc/logrotate.d/apis-#{name}" do
414 apache_site site_name do
418 service "cgimap@#{name}" do
419 action [:stop, :disable]
422 file "/etc/default/cgimap-#{name}" do
426 directory site_directory do
431 file "/etc/cron.daily/rails-#{site_name.tr('.', '-')}" do
435 postgresql_database database_name do
440 node.normal[:dev][:rails].delete(name)
444 directory "/srv/apis.dev.openstreetmap.org" do
450 template "/srv/apis.dev.openstreetmap.org/index.html" do
451 source "apis.html.erb"
457 ssl_certificate "apis.dev.openstreetmap.org" do
458 domains "apis.dev.openstreetmap.org"
459 notifies :reload, "service[apache2]"
462 apache_site "apis.dev.openstreetmap.org" do
463 template "apache.apis.erb"
466 node[:postgresql][:clusters].each_key do |name|
467 postgresql_munin name do
474 directory "/srv/ooc.openstreetmap.org" do
480 remote_directory "/srv/ooc.openstreetmap.org/html" do
490 ssl_certificate "ooc.openstreetmap.org" do
491 domains ["ooc.openstreetmap.org",
492 "a.ooc.openstreetmap.org",
493 "b.ooc.openstreetmap.org",
494 "c.ooc.openstreetmap.org"]
495 notifies :reload, "service[apache2]"
498 apache_site "ooc.openstreetmap.org" do
499 template "apache.ooc.erb"