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"
47 package "python-argparse"
48 package "python-beautifulsoup"
49 package "python-cheetah"
50 package "python-dateutil"
51 package "python-magic"
52 package "python-psycopg2"
57 easy_install_package "geojson"
60 apache_module "expires"
61 apache_module "headers"
63 apache_module "proxy_fcgi"
64 apache_module "rewrite"
65 apache_module "suexec"
66 apache_module "userdir"
69 package "apache2-suexec-pristine"
73 gem_package "rails" do
77 service "php7.0-fpm" do
78 action [:enable, :start]
81 template "/etc/php/7.0/fpm/pool.d/default.conf" do
82 source "fpm-default.conf.erb"
86 notifies :reload, "service[php7.0-fpm]"
89 file "/etc/php/7.0/fpm/pool.d/www.conf" do
91 notifies :reload, "service[php7.0-fpm]"
96 template "/etc/phppgadmin/config.inc.php" do
97 source "phppgadmin.conf.erb"
103 file "/etc/apache2/conf.d/phppgadmin" do
107 apache_site "phppgadmin.dev.openstreetmap.org" do
108 template "apache.phppgadmin.erb"
111 search(:accounts, "*:*").each do |account|
113 details = node[:accounts][:users][name] || {}
115 next unless %w(user administrator).include?(details[:status])
117 user_home = details[:home] || account["home"] || "#{node[:accounts][:home]}/#{name}"
119 next unless File.directory?("#{user_home}/public_html")
121 port = 7000 + account["uid"].to_i
123 template "/etc/php/7.0/fpm/pool.d/#{name}.conf" do
124 source "fpm.conf.erb"
128 variables :user => name, :port => port
129 notifies :reload, "service[php7.0-fpm]"
132 apache_site "#{name}.dev.openstreetmap.org" do
133 template "apache.user.erb"
134 directory "#{user_home}/public_html"
135 variables :user => name, :port => port
138 template "/etc/sudoers.d/#{name}" do
139 source "sudoers.user.erb"
143 variables :user => name
147 if node[:postgresql][:clusters][:"9.5/main"]
148 postgresql_user "apis" do
152 template "/usr/local/bin/cleanup-rails-assets" do
154 source "cleanup-assets.erb"
160 node[:dev][:rails].each do |name, details|
161 database_name = details[:database] || "apis_#{name}"
162 site_name = "#{name}.apis.dev.openstreetmap.org"
163 rails_directory = "/srv/#{name}.apis.dev.openstreetmap.org"
165 if details[:repository]
166 site_aliases = details[:aliases] || []
167 secret_key_base = details[:secret_key_base] || SecureRandom.base64(96)
169 node.normal[:dev][:rails][name][:secret_key_base] = secret_key_base
171 postgresql_database database_name do
176 postgresql_extension "#{database_name}_btree_gist" do
178 database database_name
179 extension "btree_gist"
182 rails_port site_name do
183 ruby node[:passenger][:ruby_version]
184 directory rails_directory
187 repository details[:repository]
188 revision details[:revision]
189 database_port node[:postgresql][:clusters][:"9.5/main"][:port]
190 database_name database_name
191 database_username "apis"
195 template "#{rails_directory}/config/initializers/setup.rb" do
196 source "rails.setup.rb.erb"
200 variables :site => site_name
201 notifies :run, "execute[#{rails_directory}]"
204 ssl_certificate site_name do
205 domains [site_name] + site_aliases
206 notifies :reload, "service[apache2]"
209 apache_site site_name do
210 template "apache.rails.erb"
211 variables :name => site_name, :aliases => site_aliases, :secret_key_base => secret_key_base
214 apache_site site_name do
218 directory rails_directory do
223 file "/etc/cron.daily/rails-#{site_name.tr('.', '-')}" do
227 postgresql_database database_name do
232 node.normal[:dev][:rails].delete(name)
236 directory "/srv/apis.dev.openstreetmap.org" do
242 template "/srv/apis.dev.openstreetmap.org/index.html" do
243 source "apis.html.erb"
249 ssl_certificate "apis.dev.openstreetmap.org" do
250 domains "apis.dev.openstreetmap.org"
251 notifies :reload, "service[apache2]"
254 apache_site "apis.dev.openstreetmap.org" do
255 template "apache.apis.erb"
258 node[:postgresql][:clusters].each_key do |name|
259 postgresql_munin name do