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"
64 python_package "geojson"
67 apache_module "expires"
68 apache_module "headers"
70 apache_module "proxy_fcgi"
71 apache_module "rewrite"
72 apache_module "suexec"
73 apache_module "userdir"
76 package "apache2-suexec-pristine"
78 service "php7.2-fpm" do
79 action [:enable, :start]
82 template "/etc/php/7.2/fpm/pool.d/default.conf" do
83 source "fpm-default.conf.erb"
87 notifies :reload, "service[php7.2-fpm]"
90 file "/etc/php/7.2/fpm/pool.d/www.conf" do
92 notifies :reload, "service[php7.2-fpm]"
95 directory "/srv/dev.openstreetmap.org" do
101 template "/srv/dev.openstreetmap.org/index.html" do
102 source "dev.html.erb"
108 ssl_certificate "dev.openstreetmap.org" do
109 domains "dev.openstreetmap.org"
110 notifies :reload, "service[apache2]"
113 apache_site "dev.openstreetmap.org" do
114 template "apache.dev.erb"
119 template "/etc/phppgadmin/config.inc.php" do
120 source "phppgadmin.conf.erb"
126 file "/etc/apache2/conf.d/phppgadmin" do
130 ssl_certificate "phppgadmin.dev.openstreetmap.org" do
131 domains "phppgadmin.dev.openstreetmap.org"
132 notifies :reload, "service[apache2]"
135 apache_site "phppgadmin.dev.openstreetmap.org" do
136 template "apache.phppgadmin.erb"
139 search(:accounts, "*:*").each do |account|
141 details = node[:accounts][:users][name] || {}
143 next unless %w[user administrator].include?(details[:status])
145 user_home = details[:home] || account["home"] || "#{node[:accounts][:home]}/#{name}"
147 next unless File.directory?("#{user_home}/public_html")
149 port = 7000 + account["uid"].to_i
151 template "/etc/php/7.2/fpm/pool.d/#{name}.conf" do
152 source "fpm.conf.erb"
156 variables :user => name, :port => port
157 notifies :reload, "service[php7.2-fpm]"
160 ssl_certificate "#{name}.dev.openstreetmap.org" do
161 domains ["#{name}.dev.openstreetmap.org", "#{name}.dev.osm.org"]
162 notifies :reload, "service[apache2]"
165 apache_site "#{name}.dev.openstreetmap.org" do
166 template "apache.user.erb"
167 directory "#{user_home}/public_html"
168 variables :user => name, :port => port
171 template "/etc/sudoers.d/#{name}" do
172 source "sudoers.user.erb"
176 variables :user => name
180 if node[:postgresql][:clusters][:"9.5/main"]
181 postgresql_user "apis" do
185 template "/usr/local/bin/cleanup-rails-assets" do
187 source "cleanup-assets.erb"
193 node[:dev][:rails].each do |name, details|
194 database_name = details[:database] || "apis_#{name}"
195 site_name = "#{name}.apis.dev.openstreetmap.org"
196 rails_directory = "/srv/#{name}.apis.dev.openstreetmap.org"
198 if details[:repository]
199 site_aliases = details[:aliases] || []
200 secret_key_base = details[:secret_key_base] || SecureRandom.base64(96)
202 node.normal[:dev][:rails][name][:secret_key_base] = secret_key_base
204 postgresql_database database_name do
209 postgresql_extension "#{database_name}_btree_gist" do
211 database database_name
212 extension "btree_gist"
215 rails_port site_name do
216 ruby node[:passenger][:ruby_version]
217 directory rails_directory
220 repository details[:repository]
221 revision details[:revision]
222 database_port node[:postgresql][:clusters][:"9.5/main"][:port]
223 database_name database_name
224 database_username "apis"
225 memcache_servers ["127.0.0.1"]
230 template "#{rails_directory}/config/initializers/setup.rb" do
231 source "rails.setup.rb.erb"
235 variables :site => site_name
236 notifies :restart, "rails_port[#{site_name}]"
239 ssl_certificate site_name do
240 domains [site_name] + site_aliases
241 notifies :reload, "service[apache2]"
244 apache_site site_name do
245 template "apache.rails.erb"
246 variables :application_name => name, :aliases => site_aliases, :secret_key_base => secret_key_base
249 apache_site site_name do
253 directory rails_directory do
258 file "/etc/cron.daily/rails-#{site_name.tr('.', '-')}" do
262 postgresql_database database_name do
267 node.normal[:dev][:rails].delete(name)
271 directory "/srv/apis.dev.openstreetmap.org" do
277 template "/srv/apis.dev.openstreetmap.org/index.html" do
278 source "apis.html.erb"
284 ssl_certificate "apis.dev.openstreetmap.org" do
285 domains "apis.dev.openstreetmap.org"
286 notifies :reload, "service[apache2]"
289 apache_site "apis.dev.openstreetmap.org" do
290 template "apache.apis.erb"
293 node[:postgresql][:clusters].each_key do |name|
294 postgresql_munin name do
301 directory "/srv/ooc.openstreetmap.org" do
307 remote_directory "/srv/ooc.openstreetmap.org/html" do
317 ssl_certificate "ooc.openstreetmap.org" do
318 domains ["ooc.openstreetmap.org",
319 "a.ooc.openstreetmap.org",
320 "b.ooc.openstreetmap.org",
321 "c.ooc.openstreetmap.org"]
322 notifies :reload, "service[apache2]"
325 apache_site "ooc.openstreetmap.org" do
326 template "apache.ooc.erb"