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"]
237 template "#{rails_directory}/config/initializers/setup.rb" do
238 source "rails.setup.rb.erb"
242 variables :site => site_name
243 notifies :restart, "rails_port[#{site_name}]"
246 ssl_certificate site_name do
247 domains [site_name] + site_aliases
248 notifies :reload, "service[apache2]"
251 apache_site site_name do
252 template "apache.rails.erb"
253 variables :name => site_name, :aliases => site_aliases, :secret_key_base => secret_key_base
256 apache_site site_name do
260 directory rails_directory do
265 file "/etc/cron.daily/rails-#{site_name.tr('.', '-')}" do
269 postgresql_database database_name do
274 node.normal[:dev][:rails].delete(name)
278 directory "/srv/apis.dev.openstreetmap.org" do
284 template "/srv/apis.dev.openstreetmap.org/index.html" do
285 source "apis.html.erb"
291 ssl_certificate "apis.dev.openstreetmap.org" do
292 domains "apis.dev.openstreetmap.org"
293 notifies :reload, "service[apache2]"
296 apache_site "apis.dev.openstreetmap.org" do
297 template "apache.apis.erb"
300 node[:postgresql][:clusters].each_key do |name|
301 postgresql_munin name do
308 directory "/srv/ooc.openstreetmap.org" do
314 remote_directory "/srv/ooc.openstreetmap.org/html" do
324 ssl_certificate "ooc.openstreetmap.org" do
325 domains ["ooc.openstreetmap.org",
326 "a.ooc.openstreetmap.org",
327 "b.ooc.openstreetmap.org",
328 "c.ooc.openstreetmap.org"]
329 notifies :reload, "service[apache2]"
332 apache_site "ooc.openstreetmap.org" do
333 template "apache.ooc.erb"