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"
39 package "php5-imagick"
49 package "python-argparse"
50 package "python-beautifulsoup"
51 package "python-cheetah"
52 package "python-dateutil"
53 package "python-magic"
54 package "python-psycopg2"
59 easy_install_package "geojson"
62 apache_module "expires"
64 apache_module "proxy_fcgi"
65 apache_module "rewrite"
70 gem_package "rails" do
75 provider Chef::Provider::Service::Upstart
76 action [:enable, :start]
77 supports :status => true, :restart => true, :reload => true
80 template "/etc/php5/fpm/pool.d/default.conf" do
81 source "fpm-default.conf.erb"
85 notifies :reload, "service[php5-fpm]"
88 file "/etc/php5/fpm/pool.d/www.conf" do
90 notifies :reload, "service[php5-fpm]"
95 template "/etc/phppgadmin/config.inc.php" do
96 source "phppgadmin.conf.erb"
102 file "/etc/apache2/conf.d/phppgadmin" do
106 apache_site "phppgadmin.dev.openstreetmap.org" do
107 template "apache.phppgadmin.erb"
110 search(:accounts, "*:*").each do |account|
112 details = node[:accounts][:users][name] || {}
114 next unless %w(user administrator).include?(details[:status])
116 user_home = details[:home] || account["home"] || "#{node[:accounts][:home]}/#{name}"
118 next unless File.directory?("#{user_home}/public_html")
120 port = 7000 + account["uid"].to_i
122 template "/etc/php5/fpm/pool.d/#{name}.conf" do
123 source "fpm.conf.erb"
127 variables :user => name, :port => port
128 notifies :reload, "service[php5-fpm]"
131 apache_site "#{name}.dev.openstreetmap.org" do
132 template "apache.user.erb"
133 directory "#{user_home}/public_html"
134 variables :user => name, :port => port
138 if node[:postgresql][:clusters][:"9.3/main"]
139 postgresql_user "apis" do
143 template "/usr/local/bin/cleanup-rails-assets" do
145 source "cleanup-assets.erb"
151 node[:dev][:rails].each do |name, details|
152 database_name = details[:database] || "apis_#{name}"
153 site_name = "#{name}.apis.dev.openstreetmap.org"
154 rails_directory = "/srv/#{name}.apis.dev.openstreetmap.org"
156 if details[:repository]
157 site_aliases = details[:aliases] || []
158 secret_key_base = details[:secret_key_base] || SecureRandom.base64(96)
160 node.normal[:dev][:rails][name][:secret_key_base] = secret_key_base
162 postgresql_database database_name do
167 postgresql_extension "#{database_name}_btree_gist" do
169 database database_name
170 extension "btree_gist"
173 rails_port site_name do
174 ruby node[:passenger][:ruby_version]
175 directory rails_directory
178 repository details[:repository]
179 revision details[:revision]
180 database_port node[:postgresql][:clusters][:"9.3/main"][:port]
181 database_name database_name
182 database_username "apis"
186 template "#{rails_directory}/config/initializers/setup.rb" do
187 source "rails.setup.rb.erb"
191 variables :site => site_name
192 notifies :run, "execute[#{rails_directory}]"
195 apache_site site_name do
196 template "apache.rails.erb"
197 variables :name => site_name, :aliases => site_aliases, :secret_key_base => secret_key_base
200 apache_site site_name do
204 directory rails_directory do
209 file "/etc/cron.daily/rails-#{site_name.tr('.', '-')}" do
213 postgresql_database database_name do
218 node.normal[:dev][:rails].delete(name)
222 directory "/srv/apis.dev.openstreetmap.org" do
228 template "/srv/apis.dev.openstreetmap.org/index.html" do
229 source "apis.html.erb"
235 apache_site "apis.dev.openstreetmap.org" do
236 template "apache.apis.erb"
239 node[:postgresql][:clusters].each_key do |name|
240 postgresql_munin name do