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 # http://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 "mysql"
27 include_recipe "nodejs"
28 include_recipe "postgresql"
29 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"
80 gem_package "rails" do
84 service "php7.0-fpm" do
85 action [:enable, :start]
88 template "/etc/php/7.0/fpm/pool.d/default.conf" do
89 source "fpm-default.conf.erb"
93 notifies :reload, "service[php7.0-fpm]"
96 file "/etc/php/7.0/fpm/pool.d/www.conf" do
98 notifies :reload, "service[php7.0-fpm]"
103 template "/etc/phppgadmin/config.inc.php" do
104 source "phppgadmin.conf.erb"
110 file "/etc/apache2/conf.d/phppgadmin" do
114 apache_site "phppgadmin.dev.openstreetmap.org" do
115 template "apache.phppgadmin.erb"
118 search(:accounts, "*:*").each do |account|
120 details = node[:accounts][:users][name] || {}
122 next unless %w[user administrator].include?(details[:status])
124 user_home = details[:home] || account["home"] || "#{node[:accounts][:home]}/#{name}"
126 next unless File.directory?("#{user_home}/public_html")
128 port = 7000 + account["uid"].to_i
130 template "/etc/php/7.0/fpm/pool.d/#{name}.conf" do
131 source "fpm.conf.erb"
135 variables :user => name, :port => port
136 notifies :reload, "service[php7.0-fpm]"
139 apache_site "#{name}.dev.openstreetmap.org" do
140 template "apache.user.erb"
141 directory "#{user_home}/public_html"
142 variables :user => name, :port => port
145 template "/etc/sudoers.d/#{name}" do
146 source "sudoers.user.erb"
150 variables :user => name
154 if node[:postgresql][:clusters][:"9.5/main"]
155 postgresql_user "apis" do
159 template "/usr/local/bin/cleanup-rails-assets" do
161 source "cleanup-assets.erb"
167 node[:dev][:rails].each do |name, details|
168 database_name = details[:database] || "apis_#{name}"
169 site_name = "#{name}.apis.dev.openstreetmap.org"
170 rails_directory = "/srv/#{name}.apis.dev.openstreetmap.org"
172 if details[:repository]
173 site_aliases = details[:aliases] || []
174 secret_key_base = details[:secret_key_base] || SecureRandom.base64(96)
176 node.normal[:dev][:rails][name][:secret_key_base] = secret_key_base
178 postgresql_database database_name do
183 postgresql_extension "#{database_name}_btree_gist" do
185 database database_name
186 extension "btree_gist"
189 rails_port site_name do
190 ruby node[:passenger][:ruby_version]
191 directory rails_directory
194 repository details[:repository]
195 revision details[:revision]
196 database_port node[:postgresql][:clusters][:"9.5/main"][:port]
197 database_name database_name
198 database_username "apis"
202 template "#{rails_directory}/config/initializers/setup.rb" do
203 source "rails.setup.rb.erb"
207 variables :site => site_name
208 notifies :run, "execute[#{rails_directory}]"
211 ssl_certificate site_name do
212 domains [site_name] + site_aliases
213 notifies :reload, "service[apache2]"
216 apache_site site_name do
217 template "apache.rails.erb"
218 variables :name => site_name, :aliases => site_aliases, :secret_key_base => secret_key_base
221 apache_site site_name do
225 directory rails_directory do
230 file "/etc/cron.daily/rails-#{site_name.tr('.', '-')}" do
234 postgresql_database database_name do
239 node.normal[:dev][:rails].delete(name)
243 directory "/srv/apis.dev.openstreetmap.org" do
249 template "/srv/apis.dev.openstreetmap.org/index.html" do
250 source "apis.html.erb"
256 ssl_certificate "apis.dev.openstreetmap.org" do
257 domains "apis.dev.openstreetmap.org"
258 notifies :reload, "service[apache2]"
261 apache_site "apis.dev.openstreetmap.org" do
262 template "apache.apis.erb"
265 node[:postgresql][:clusters].each_key do |name|
266 postgresql_munin name do