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 "mysql"
29 include_recipe "nodejs"
30 include_recipe "postgresql"
31 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"
92 service "php7.2-fpm" do
93 action [:enable, :start]
96 template "/etc/php/7.2/fpm/pool.d/default.conf" do
97 source "fpm-default.conf.erb"
101 notifies :reload, "service[php7.2-fpm]"
104 file "/etc/php/7.2/fpm/pool.d/www.conf" do
106 notifies :reload, "service[php7.2-fpm]"
109 directory "/srv/dev.openstreetmap.org" do
115 template "/srv/dev.openstreetmap.org/index.html" do
116 source "dev.html.erb"
122 ssl_certificate "dev.openstreetmap.org" do
123 domains "dev.openstreetmap.org"
124 notifies :reload, "service[apache2]"
127 apache_site "dev.openstreetmap.org" do
128 template "apache.dev.erb"
133 template "/etc/phppgadmin/config.inc.php" do
134 source "phppgadmin.conf.erb"
140 file "/etc/apache2/conf.d/phppgadmin" do
144 ssl_certificate "phppgadmin.dev.openstreetmap.org" do
145 domains "phppgadmin.dev.openstreetmap.org"
146 notifies :reload, "service[apache2]"
149 apache_site "phppgadmin.dev.openstreetmap.org" do
150 template "apache.phppgadmin.erb"
153 search(:accounts, "*:*").each do |account|
155 details = node[:accounts][:users][name] || {}
157 next unless %w[user administrator].include?(details[:status])
159 user_home = details[:home] || account["home"] || "#{node[:accounts][:home]}/#{name}"
161 next unless File.directory?("#{user_home}/public_html")
163 port = 7000 + account["uid"].to_i
165 template "/etc/php/7.2/fpm/pool.d/#{name}.conf" do
166 source "fpm.conf.erb"
170 variables :user => name, :port => port
171 notifies :reload, "service[php7.2-fpm]"
174 ssl_certificate "#{name}.dev.openstreetmap.org" do
175 domains ["#{name}.dev.openstreetmap.org", "#{name}.dev.osm.org"]
176 notifies :reload, "service[apache2]"
179 apache_site "#{name}.dev.openstreetmap.org" do
180 template "apache.user.erb"
181 directory "#{user_home}/public_html"
182 variables :user => name, :port => port
185 template "/etc/sudoers.d/#{name}" do
186 source "sudoers.user.erb"
190 variables :user => name
194 if node[:postgresql][:clusters][:"9.5/main"]
195 postgresql_user "apis" do
199 template "/usr/local/bin/cleanup-rails-assets" do
201 source "cleanup-assets.erb"
207 ruby_version = node[:passenger][:ruby_version]
209 systemd_service "rails-jobs@" do
210 description "Rails job queue runner"
213 working_directory "/srv/%i.apis.dev.openstreetmap.org/rails"
214 exec_start "/usr/local/bin/bundle#{ruby_version} exec rake jobs:work"
218 protect_system "full"
220 no_new_privileges true
223 systemd_service "cgimap@" do
224 description "OpenStreetMap API Server"
226 environment_file "/etc/default/cgimap-%i"
228 exec_start "/srv/%i.apis.dev.openstreetmap.org/cgimap/openstreetmap-cgimap --daemon --port $CGIMAP_PORT --instances 5"
229 exec_reload "/bin/kill -HUP $MAINPID"
232 protect_system "full"
234 no_new_privileges true
240 node[:dev][:rails].each do |name, details|
241 database_name = details[:database] || "apis_#{name}"
242 site_name = "#{name}.apis.dev.openstreetmap.org"
243 site_directory = "/srv/#{name}.apis.dev.openstreetmap.org"
244 log_directory = "#{site_directory}/logs"
245 rails_directory = "#{site_directory}/rails"
246 cgimap_directory = "#{site_directory}/cgimap"
247 gpx_directory = "#{site_directory}/gpx"
249 if details[:repository]
250 site_aliases = details[:aliases] || []
251 secret_key_base = details[:secret_key_base] || SecureRandom.base64(96)
253 node.normal[:dev][:rails][name][:secret_key_base] = secret_key_base
255 postgresql_database database_name do
260 postgresql_extension "#{database_name}_btree_gist" do
262 database database_name
263 extension "btree_gist"
266 directory site_directory do
272 directory log_directory do
278 directory gpx_directory do
284 directory "#{gpx_directory}/traces" do
290 directory "#{gpx_directory}/images" do
296 rails_port site_name do
298 directory rails_directory
301 repository details[:repository]
302 revision details[:revision]
303 database_port node[:postgresql][:clusters][:"9.5/main"][:port]
304 database_name database_name
305 database_username "apis"
306 gpx_dir gpx_directory
307 log_path "#{log_directory}/rails.log"
308 memcache_servers ["127.0.0.1"]
311 trace_use_job_queue true
314 template "#{rails_directory}/config/initializers/setup.rb" do
315 source "rails.setup.rb.erb"
319 variables :site => site_name
320 notifies :restart, "rails_port[#{site_name}]"
323 service "rails-jobs@#{name}" do
324 action [:enable, :start]
325 supports :restart => true
326 subscribes :restart, "rails_port[#{site_name}]"
327 subscribes :restart, "systemd_service[#{name}]"
328 only_if "fgrep -q delayed_job #{rails_directory}/Gemfile.lock"
331 if details[:cgimap_repository]
332 git cgimap_directory do
334 repository details[:cgimap_repository]
335 revision details[:cgimap_revision]
340 execute "#{cgimap_directory}/autogen.sh" do
342 command "./autogen.sh"
346 subscribes :run, "git[#{cgimap_directory}]", :immediate
349 execute "#{cgimap_directory}/configure" do
351 command "./configure --with-fcgi=/usr --with-boost-libdir=/usr/lib/x86_64-linux-gnu --enable-yajl"
355 subscribes :run, "execute[#{cgimap_directory}/autogen.sh]", :immediate
358 execute "#{cgimap_directory}/Makefile" do
364 subscribes :run, "execute[#{cgimap_directory}/configure]", :immediate
365 notifies :restart, "service[cgimap@#{name}]"
368 template "/etc/default/cgimap-#{name}" do
369 source "cgimap.environment.erb"
373 variables :cgimap_port => cgimap_port,
374 :database_port => node[:postgresql][:clusters][:"9.5/main"][:port],
375 :database_name => database_name,
376 :log_directory => log_directory
377 notifies :restart, "service[cgimap@#{name}]"
380 service "cgimap@#{name}" do
381 action [:start, :enable]
385 ssl_certificate site_name do
386 domains [site_name] + site_aliases
387 notifies :reload, "service[apache2]"
390 apache_site site_name do
391 template "apache.rails.erb"
392 variables :application_name => name,
393 :aliases => site_aliases,
394 :secret_key_base => secret_key_base,
395 :cgimap_enabled => details.key?(:cgimap_repository),
396 :cgimap_port => cgimap_port
399 template "/etc/logrotate.d/apis-#{name}" do
400 source "logrotate.apis.erb"
404 variables :name => name,
405 :log_directory => log_directory,
406 :rails_directory => rails_directory
411 file "/etc/logrotate.d/apis-#{name}" do
415 apache_site site_name do
419 service "cgimap@#{name}" do
420 action [:stop, :disable]
423 file "/etc/default/cgimap-#{name}" do
427 directory site_directory do
432 file "/etc/cron.daily/rails-#{site_name.tr('.', '-')}" do
436 postgresql_database database_name do
441 node.normal[:dev][:rails].delete(name)
445 directory "/srv/apis.dev.openstreetmap.org" do
451 template "/srv/apis.dev.openstreetmap.org/index.html" do
452 source "apis.html.erb"
458 ssl_certificate "apis.dev.openstreetmap.org" do
459 domains "apis.dev.openstreetmap.org"
460 notifies :reload, "service[apache2]"
463 apache_site "apis.dev.openstreetmap.org" do
464 template "apache.apis.erb"
467 node[:postgresql][:clusters].each_key do |name|
468 postgresql_munin name do
475 directory "/srv/ooc.openstreetmap.org" do
481 remote_directory "/srv/ooc.openstreetmap.org/html" do
491 ssl_certificate "ooc.openstreetmap.org" do
492 domains ["ooc.openstreetmap.org",
493 "a.ooc.openstreetmap.org",
494 "b.ooc.openstreetmap.org",
495 "c.ooc.openstreetmap.org"]
496 notifies :reload, "service[apache2]"
499 apache_site "ooc.openstreetmap.org" do
500 template "apache.ooc.erb"