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 python_package "geojson"
68 apache_module "expires"
69 apache_module "headers"
71 apache_module "proxy_fcgi"
72 apache_module "rewrite"
73 apache_module "suexec"
74 apache_module "userdir"
77 package "apache2-suexec-pristine"
81 gem_package "rails" do
85 service "php7.0-fpm" do
86 action [:enable, :start]
89 template "/etc/php/7.0/fpm/pool.d/default.conf" do
90 source "fpm-default.conf.erb"
94 notifies :reload, "service[php7.0-fpm]"
97 file "/etc/php/7.0/fpm/pool.d/www.conf" do
99 notifies :reload, "service[php7.0-fpm]"
102 directory "/srv/dev.openstreetmap.org" do
108 template "/srv/dev.openstreetmap.org/index.html" do
109 source "dev.html.erb"
115 ssl_certificate "dev.openstreetmap.org" do
116 domains "dev.openstreetmap.org"
117 notifies :reload, "service[apache2]"
120 apache_site "dev.openstreetmap.org" do
121 template "apache.dev.erb"
126 template "/etc/phppgadmin/config.inc.php" do
127 source "phppgadmin.conf.erb"
133 file "/etc/apache2/conf.d/phppgadmin" do
137 ssl_certificate "phppgadmin.dev.openstreetmap.org" do
138 domains "phppgadmin.dev.openstreetmap.org"
139 notifies :reload, "service[apache2]"
142 apache_site "phppgadmin.dev.openstreetmap.org" do
143 template "apache.phppgadmin.erb"
146 search(:accounts, "*:*").each do |account|
148 details = node[:accounts][:users][name] || {}
150 next unless %w[user administrator].include?(details[:status])
152 user_home = details[:home] || account["home"] || "#{node[:accounts][:home]}/#{name}"
154 next unless File.directory?("#{user_home}/public_html")
156 port = 7000 + account["uid"].to_i
158 template "/etc/php/7.0/fpm/pool.d/#{name}.conf" do
159 source "fpm.conf.erb"
163 variables :user => name, :port => port
164 notifies :reload, "service[php7.0-fpm]"
167 ssl_certificate "#{name}.dev.openstreetmap.org" do
168 domains ["#{name}.dev.openstreetmap.org", "#{name}.dev.osm.org"]
169 notifies :reload, "service[apache2]"
172 apache_site "#{name}.dev.openstreetmap.org" do
173 template "apache.user.erb"
174 directory "#{user_home}/public_html"
175 variables :user => name, :port => port
178 template "/etc/sudoers.d/#{name}" do
179 source "sudoers.user.erb"
183 variables :user => name
187 if node[:postgresql][:clusters][:"9.5/main"]
188 postgresql_user "apis" do
192 template "/usr/local/bin/cleanup-rails-assets" do
194 source "cleanup-assets.erb"
200 node[:dev][:rails].each do |name, details|
201 database_name = details[:database] || "apis_#{name}"
202 site_name = "#{name}.apis.dev.openstreetmap.org"
203 rails_directory = "/srv/#{name}.apis.dev.openstreetmap.org"
205 if details[:repository]
206 site_aliases = details[:aliases] || []
207 secret_key_base = details[:secret_key_base] || SecureRandom.base64(96)
209 node.normal[:dev][:rails][name][:secret_key_base] = secret_key_base
211 postgresql_database database_name do
216 postgresql_extension "#{database_name}_btree_gist" do
218 database database_name
219 extension "btree_gist"
222 rails_port site_name do
223 ruby node[:passenger][:ruby_version]
224 directory rails_directory
227 repository details[:repository]
228 revision details[:revision]
229 database_port node[:postgresql][:clusters][:"9.5/main"][:port]
230 database_name database_name
231 database_username "apis"
232 memcache_servers ["127.0.0.1"]
236 template "#{rails_directory}/config/initializers/setup.rb" do
237 source "rails.setup.rb.erb"
241 variables :site => site_name
242 notifies :restart, "rails_port[#{site_name}]"
245 ssl_certificate site_name do
246 domains [site_name] + site_aliases
247 notifies :reload, "service[apache2]"
250 apache_site site_name do
251 template "apache.rails.erb"
252 variables :name => site_name, :aliases => site_aliases, :secret_key_base => secret_key_base
255 apache_site site_name do
259 directory rails_directory do
264 file "/etc/cron.daily/rails-#{site_name.tr('.', '-')}" do
268 postgresql_database database_name do
273 node.normal[:dev][:rails].delete(name)
277 directory "/srv/apis.dev.openstreetmap.org" do
283 template "/srv/apis.dev.openstreetmap.org/index.html" do
284 source "apis.html.erb"
290 ssl_certificate "apis.dev.openstreetmap.org" do
291 domains "apis.dev.openstreetmap.org"
292 notifies :reload, "service[apache2]"
295 apache_site "apis.dev.openstreetmap.org" do
296 template "apache.apis.erb"
299 node[:postgresql][:clusters].each_key do |name|
300 postgresql_munin name do
307 directory "/srv/ooc.openstreetmap.org" do
313 remote_directory "/srv/ooc.openstreetmap.org/html" do
323 ssl_certificate "ooc.openstreetmap.org" do
324 domains ["ooc.openstreetmap.org",
325 "a.ooc.openstreetmap.org",
326 "b.ooc.openstreetmap.org",
327 "c.ooc.openstreetmap.org"]
328 notifies :reload, "service[apache2]"
331 apache_site "ooc.openstreetmap.org" do
332 template "apache.ooc.erb"