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 "postgresql"
32 include_recipe "python"
67 libboost-program-options-dev
68 libboost-date-time-dev
69 libboost-filesystem-dev
79 python_package "geojson"
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"
91 package "apache2-suexec-pristine"
93 service "php7.2-fpm" do
94 action [:enable, :start]
97 template "/etc/php/7.2/fpm/pool.d/default.conf" do
98 source "fpm-default.conf.erb"
102 notifies :reload, "service[php7.2-fpm]"
105 file "/etc/php/7.2/fpm/pool.d/www.conf" do
107 notifies :reload, "service[php7.2-fpm]"
110 directory "/srv/dev.openstreetmap.org" do
116 template "/srv/dev.openstreetmap.org/index.html" do
117 source "dev.html.erb"
123 ssl_certificate "dev.openstreetmap.org" do
124 domains "dev.openstreetmap.org"
125 notifies :reload, "service[apache2]"
128 apache_site "dev.openstreetmap.org" do
129 template "apache.dev.erb"
134 template "/etc/phppgadmin/config.inc.php" do
135 source "phppgadmin.conf.erb"
141 file "/etc/apache2/conf.d/phppgadmin" do
145 ssl_certificate "phppgadmin.dev.openstreetmap.org" do
146 domains "phppgadmin.dev.openstreetmap.org"
147 notifies :reload, "service[apache2]"
150 apache_site "phppgadmin.dev.openstreetmap.org" do
151 template "apache.phppgadmin.erb"
154 search(:accounts, "*:*").each do |account|
156 details = node[:accounts][:users][name] || {}
158 next unless %w[user administrator].include?(details[:status])
160 user_home = details[:home] || account["home"] || "#{node[:accounts][:home]}/#{name}"
162 next unless File.directory?("#{user_home}/public_html")
164 port = 7000 + account["uid"].to_i
166 template "/etc/php/7.2/fpm/pool.d/#{name}.conf" do
167 source "fpm.conf.erb"
171 variables :user => name, :port => port
172 notifies :reload, "service[php7.2-fpm]"
175 ssl_certificate "#{name}.dev.openstreetmap.org" do
176 domains ["#{name}.dev.openstreetmap.org", "#{name}.dev.osm.org"]
177 notifies :reload, "service[apache2]"
180 apache_site "#{name}.dev.openstreetmap.org" do
181 template "apache.user.erb"
182 directory "#{user_home}/public_html"
183 variables :user => name, :port => port
186 template "/etc/sudoers.d/#{name}" do
187 source "sudoers.user.erb"
191 variables :user => name
195 if node[:postgresql][:clusters][:"9.5/main"]
196 postgresql_user "apis" do
200 template "/usr/local/bin/cleanup-rails-assets" do
202 source "cleanup-assets.erb"
208 ruby_version = node[:passenger][:ruby_version]
210 systemd_service "rails-jobs@" do
211 description "Rails job queue runner"
214 working_directory "/srv/%i.apis.dev.openstreetmap.org/rails"
215 exec_start "/usr/local/bin/bundle#{ruby_version} exec rake jobs:work"
219 protect_system "full"
221 no_new_privileges true
224 systemd_service "cgimap@" do
225 description "OpenStreetMap API Server"
227 environment_file "/etc/default/cgimap-%i"
229 exec_start "/srv/%i.apis.dev.openstreetmap.org/cgimap/openstreetmap-cgimap --daemon --port $CGIMAP_PORT --instances 5"
230 exec_reload "/bin/kill -HUP $MAINPID"
233 protect_system "full"
235 no_new_privileges true
241 node[:dev][:rails].each do |name, details|
242 database_name = details[:database] || "apis_#{name}"
243 site_name = "#{name}.apis.dev.openstreetmap.org"
244 site_directory = "/srv/#{name}.apis.dev.openstreetmap.org"
245 log_directory = "#{site_directory}/logs"
246 rails_directory = "#{site_directory}/rails"
247 cgimap_directory = "#{site_directory}/cgimap"
248 gpx_directory = "#{site_directory}/gpx"
250 if details[:repository]
251 site_aliases = details[:aliases] || []
252 secret_key_base = details[:secret_key_base] || SecureRandom.base64(96)
254 node.normal[:dev][:rails][name][:secret_key_base] = secret_key_base
256 postgresql_database database_name do
261 postgresql_extension "#{database_name}_btree_gist" do
263 database database_name
264 extension "btree_gist"
267 directory site_directory do
273 directory log_directory do
279 directory gpx_directory do
285 directory "#{gpx_directory}/traces" do
291 directory "#{gpx_directory}/images" do
297 rails_port site_name do
299 directory rails_directory
302 repository details[:repository]
303 revision details[:revision]
304 database_port node[:postgresql][:clusters][:"9.5/main"][:port]
305 database_name database_name
306 database_username "apis"
307 gpx_dir gpx_directory
308 log_path "#{log_directory}/rails.log"
309 memcache_servers ["127.0.0.1"]
312 trace_use_job_queue true
315 template "#{rails_directory}/config/initializers/setup.rb" do
316 source "rails.setup.rb.erb"
320 variables :site => site_name
321 notifies :restart, "rails_port[#{site_name}]"
324 service "rails-jobs@#{name}" do
325 action [:enable, :start]
326 supports :restart => true
327 subscribes :restart, "rails_port[#{site_name}]"
328 subscribes :restart, "systemd_service[#{name}]"
329 only_if "fgrep -q delayed_job #{rails_directory}/Gemfile.lock"
332 if details[:cgimap_repository]
333 git cgimap_directory do
335 repository details[:cgimap_repository]
336 revision details[:cgimap_revision]
341 execute "#{cgimap_directory}/autogen.sh" do
343 command "./autogen.sh"
347 subscribes :run, "git[#{cgimap_directory}]", :immediate
350 execute "#{cgimap_directory}/configure" do
352 command "./configure --with-fcgi=/usr --with-boost-libdir=/usr/lib/x86_64-linux-gnu --enable-yajl"
356 subscribes :run, "execute[#{cgimap_directory}/autogen.sh]", :immediate
359 execute "#{cgimap_directory}/Makefile" do
365 subscribes :run, "execute[#{cgimap_directory}/configure]", :immediate
366 notifies :restart, "service[cgimap@#{name}]"
369 template "/etc/default/cgimap-#{name}" do
370 source "cgimap.environment.erb"
374 variables :cgimap_port => cgimap_port,
375 :database_port => node[:postgresql][:clusters][:"9.5/main"][:port],
376 :database_name => database_name,
377 :log_directory => log_directory
378 notifies :restart, "service[cgimap@#{name}]"
381 service "cgimap@#{name}" do
382 action [:start, :enable]
386 ssl_certificate site_name do
387 domains [site_name] + site_aliases
388 notifies :reload, "service[apache2]"
391 apache_site site_name do
392 template "apache.rails.erb"
393 variables :application_name => name,
394 :aliases => site_aliases,
395 :secret_key_base => secret_key_base,
396 :cgimap_enabled => details.key?(:cgimap_repository),
397 :cgimap_port => cgimap_port
400 template "/etc/logrotate.d/apis-#{name}" do
401 source "logrotate.apis.erb"
405 variables :name => name,
406 :log_directory => log_directory,
407 :rails_directory => rails_directory
412 file "/etc/logrotate.d/apis-#{name}" do
416 apache_site site_name do
420 service "cgimap@#{name}" do
421 action [:stop, :disable]
424 file "/etc/default/cgimap-#{name}" do
428 directory site_directory do
433 file "/etc/cron.daily/rails-#{site_name.tr('.', '-')}" do
437 postgresql_database database_name do
442 node.normal[:dev][:rails].delete(name)
446 directory "/srv/apis.dev.openstreetmap.org" do
452 template "/srv/apis.dev.openstreetmap.org/index.html" do
453 source "apis.html.erb"
459 ssl_certificate "apis.dev.openstreetmap.org" do
460 domains "apis.dev.openstreetmap.org"
461 notifies :reload, "service[apache2]"
464 apache_site "apis.dev.openstreetmap.org" do
465 template "apache.apis.erb"
468 node[:postgresql][:clusters].each_key do |name|
469 postgresql_munin name do
476 directory "/srv/ooc.openstreetmap.org" do
482 remote_directory "/srv/ooc.openstreetmap.org/html" do
492 ssl_certificate "ooc.openstreetmap.org" do
493 domains ["ooc.openstreetmap.org",
494 "a.ooc.openstreetmap.org",
495 "b.ooc.openstreetmap.org",
496 "c.ooc.openstreetmap.org"]
497 notifies :reload, "service[apache2]"
500 apache_site "ooc.openstreetmap.org" do
501 template "apache.ooc.erb"