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"
247 if details[:repository]
248 site_aliases = details[:aliases] || []
249 secret_key_base = details[:secret_key_base] || SecureRandom.base64(96)
251 node.normal[:dev][:rails][name][:secret_key_base] = secret_key_base
253 postgresql_database database_name do
258 postgresql_extension "#{database_name}_btree_gist" do
260 database database_name
261 extension "btree_gist"
264 directory site_directory do
270 directory log_directory do
276 rails_port site_name do
278 directory rails_directory
281 repository details[:repository]
282 revision details[:revision]
283 database_port node[:postgresql][:clusters][:"9.5/main"][:port]
284 database_name database_name
285 database_username "apis"
286 log_path "#{log_directory}/rails.log"
287 memcache_servers ["127.0.0.1"]
292 template "#{rails_directory}/config/initializers/setup.rb" do
293 source "rails.setup.rb.erb"
297 variables :site => site_name
298 notifies :restart, "rails_port[#{site_name}]"
301 service "rails-jobs@#{name}" do
302 action [:enable, :start]
303 supports :restart => true
304 subscribes :restart, "rails_port[#{site_name}]"
305 subscribes :restart, "systemd_service[#{name}]"
306 only_if "fgrep -q delayed_job #{rails_directory}/Gemfile.lock"
309 if details[:cgimap_repository]
310 git cgimap_directory do
312 repository details[:cgimap_repository]
313 revision details[:cgimap_revision]
318 execute "#{cgimap_directory}/autogen.sh" do
320 command "./autogen.sh"
324 subscribes :run, "git[#{cgimap_directory}]", :immediate
327 execute "#{cgimap_directory}/configure" do
329 command "./configure --with-fcgi=/usr --with-boost-libdir=/usr/lib/x86_64-linux-gnu --enable-yajl"
333 subscribes :run, "execute[#{cgimap_directory}/autogen.sh]", :immediate
336 execute "#{cgimap_directory}/Makefile" do
342 subscribes :run, "execute[#{cgimap_directory}/configure]", :immediate
343 notifies :restart, "service[cgimap@#{name}]"
346 template "/etc/default/cgimap-#{name}" do
347 source "cgimap.environment.erb"
351 variables :cgimap_port => cgimap_port,
352 :database_port => node[:postgresql][:clusters][:"9.5/main"][:port],
353 :database_name => database_name,
354 :log_directory => log_directory
355 notifies :restart, "service[cgimap@#{name}]"
358 service "cgimap@#{name}" do
359 action [:start, :enable]
363 ssl_certificate site_name do
364 domains [site_name] + site_aliases
365 notifies :reload, "service[apache2]"
368 apache_site site_name do
369 template "apache.rails.erb"
370 variables :application_name => name,
371 :aliases => site_aliases,
372 :secret_key_base => secret_key_base,
373 :cgimap_enabled => details.key?(:cgimap_repository),
374 :cgimap_port => cgimap_port
377 template "/etc/logrotate.d/apis-#{name}" do
378 source "logrotate.apis.erb"
382 variables :name => name,
383 :log_directory => log_directory,
384 :rails_directory => rails_directory
389 file "/etc/logrotate.d/apis-#{name}" do
393 apache_site site_name do
397 service "cgimap@#{name}" do
398 action [:stop, :disable]
401 file "/etc/default/cgimap-#{name}" do
405 directory site_directory do
410 file "/etc/cron.daily/rails-#{site_name.tr('.', '-')}" do
414 postgresql_database database_name do
419 node.normal[:dev][:rails].delete(name)
423 directory "/srv/apis.dev.openstreetmap.org" do
429 template "/srv/apis.dev.openstreetmap.org/index.html" do
430 source "apis.html.erb"
436 ssl_certificate "apis.dev.openstreetmap.org" do
437 domains "apis.dev.openstreetmap.org"
438 notifies :reload, "service[apache2]"
441 apache_site "apis.dev.openstreetmap.org" do
442 template "apache.apis.erb"
445 node[:postgresql][:clusters].each_key do |name|
446 postgresql_munin name do
453 directory "/srv/ooc.openstreetmap.org" do
459 remote_directory "/srv/ooc.openstreetmap.org/html" do
469 ssl_certificate "ooc.openstreetmap.org" do
470 domains ["ooc.openstreetmap.org",
471 "a.ooc.openstreetmap.org",
472 "b.ooc.openstreetmap.org",
473 "c.ooc.openstreetmap.org"]
474 notifies :reload, "service[apache2]"
477 apache_site "ooc.openstreetmap.org" do
478 template "apache.ooc.erb"