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"
48 package "python-argparse"
49 package "python-beautifulsoup"
50 package "python-cheetah"
51 package "python-dateutil"
52 package "python-magic"
53 package "python-psycopg2"
58 python_package "geojson"
61 apache_module "expires"
62 apache_module "headers"
64 apache_module "proxy_fcgi"
65 apache_module "rewrite"
66 apache_module "suexec"
67 apache_module "userdir"
70 package "apache2-suexec-pristine"
74 gem_package "rails" do
78 service "php7.0-fpm" do
79 action [:enable, :start]
82 template "/etc/php/7.0/fpm/pool.d/default.conf" do
83 source "fpm-default.conf.erb"
87 notifies :reload, "service[php7.0-fpm]"
90 file "/etc/php/7.0/fpm/pool.d/www.conf" do
92 notifies :reload, "service[php7.0-fpm]"
97 template "/etc/phppgadmin/config.inc.php" do
98 source "phppgadmin.conf.erb"
104 file "/etc/apache2/conf.d/phppgadmin" do
108 apache_site "phppgadmin.dev.openstreetmap.org" do
109 template "apache.phppgadmin.erb"
112 search(:accounts, "*:*").each do |account|
114 details = node[:accounts][:users][name] || {}
116 next unless %w[user administrator].include?(details[:status])
118 user_home = details[:home] || account["home"] || "#{node[:accounts][:home]}/#{name}"
120 next unless File.directory?("#{user_home}/public_html")
122 port = 7000 + account["uid"].to_i
124 template "/etc/php/7.0/fpm/pool.d/#{name}.conf" do
125 source "fpm.conf.erb"
129 variables :user => name, :port => port
130 notifies :reload, "service[php7.0-fpm]"
133 apache_site "#{name}.dev.openstreetmap.org" do
134 template "apache.user.erb"
135 directory "#{user_home}/public_html"
136 variables :user => name, :port => port
139 template "/etc/sudoers.d/#{name}" do
140 source "sudoers.user.erb"
144 variables :user => name
148 if node[:postgresql][:clusters][:"9.5/main"]
149 postgresql_user "apis" do
153 template "/usr/local/bin/cleanup-rails-assets" do
155 source "cleanup-assets.erb"
161 node[:dev][:rails].each do |name, details|
162 database_name = details[:database] || "apis_#{name}"
163 site_name = "#{name}.apis.dev.openstreetmap.org"
164 rails_directory = "/srv/#{name}.apis.dev.openstreetmap.org"
166 if details[:repository]
167 site_aliases = details[:aliases] || []
168 secret_key_base = details[:secret_key_base] || SecureRandom.base64(96)
170 node.normal[:dev][:rails][name][:secret_key_base] = secret_key_base
172 postgresql_database database_name do
177 postgresql_extension "#{database_name}_btree_gist" do
179 database database_name
180 extension "btree_gist"
183 rails_port site_name do
184 ruby node[:passenger][:ruby_version]
185 directory rails_directory
188 repository details[:repository]
189 revision details[:revision]
190 database_port node[:postgresql][:clusters][:"9.5/main"][:port]
191 database_name database_name
192 database_username "apis"
196 template "#{rails_directory}/config/initializers/setup.rb" do
197 source "rails.setup.rb.erb"
201 variables :site => site_name
202 notifies :run, "execute[#{rails_directory}]"
205 ssl_certificate site_name do
206 domains [site_name] + site_aliases
207 notifies :reload, "service[apache2]"
210 apache_site site_name do
211 template "apache.rails.erb"
212 variables :name => site_name, :aliases => site_aliases, :secret_key_base => secret_key_base
215 apache_site site_name do
219 directory rails_directory do
224 file "/etc/cron.daily/rails-#{site_name.tr('.', '-')}" do
228 postgresql_database database_name do
233 node.normal[:dev][:rails].delete(name)
237 directory "/srv/apis.dev.openstreetmap.org" do
243 template "/srv/apis.dev.openstreetmap.org/index.html" do
244 source "apis.html.erb"
250 ssl_certificate "apis.dev.openstreetmap.org" do
251 domains "apis.dev.openstreetmap.org"
252 notifies :reload, "service[apache2]"
255 apache_site "apis.dev.openstreetmap.org" do
256 template "apache.apis.erb"
259 node[:postgresql][:clusters].each_key do |name|
260 postgresql_munin name do