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 "postgresql"
38 package "php5-imagick"
48 package "python-argparse"
49 package "python-beautifulsoup"
50 package "python-cheetah"
51 package "python-dateutil"
52 package "python-magic"
53 package "python-psycopg2"
56 easy_install_package "geojson"
59 apache_module "expires"
61 apache_module "proxy_fcgi"
62 apache_module "rewrite"
67 gem_package "rails" do
72 provider Chef::Provider::Service::Upstart
73 action [:enable, :start]
74 supports :status => true, :restart => true, :reload => true
77 template "/etc/php5/fpm/pool.d/default.conf" do
78 source "fpm-default.conf.erb"
82 notifies :reload, "service[php5-fpm]"
85 file "/etc/php5/fpm/pool.d/www.conf" do
87 notifies :reload, "service[php5-fpm]"
92 template "/etc/phppgadmin/config.inc.php" do
93 source "phppgadmin.conf.erb"
99 file "/etc/apache2/conf.d/phppgadmin" do
103 apache_site "phppgadmin.dev.openstreetmap.org" do
104 template "apache.phppgadmin.erb"
107 search(:accounts, "*:*").each do |account|
109 details = node[:accounts][:users][name] || {}
111 next unless %w(user administrator).include?(details[:status])
113 user_home = details[:home] || account["home"] || "#{node[:accounts][:home]}/#{name}"
115 next unless File.directory?("#{user_home}/public_html")
117 port = 7000 + account["uid"].to_i
119 template "/etc/php5/fpm/pool.d/#{name}.conf" do
120 source "fpm.conf.erb"
124 variables :user => name, :port => port
125 notifies :reload, "service[php5-fpm]"
128 apache_site "#{name}.dev.openstreetmap.org" do
129 template "apache.user.erb"
130 directory "#{user_home}/public_html"
131 variables :user => name, :port => port
135 if node[:postgresql][:clusters][:"9.1/main"]
136 postgresql_user "apis" do
140 node[:dev][:rails].each do |name, details|
141 database_name = details[:database] || "apis_#{name}"
142 site_name = "#{name}.apis.dev.openstreetmap.org"
143 rails_directory = "/srv/#{name}.apis.dev.openstreetmap.org"
145 if details[:repository]
146 site_aliases = details[:aliases] || []
147 secret_key_base = details[:secret_key_base] || SecureRandom.base64(96)
149 node.normal[:dev][:rails][name][:secret_key_base] = secret_key_base
151 postgresql_database database_name do
156 postgresql_extension "#{database_name}_btree_gist" do
158 database database_name
159 extension "btree_gist"
162 rails_port site_name do
163 ruby node[:passenger][:ruby_version]
164 directory rails_directory
167 repository details[:repository]
168 revision details[:revision]
169 database_port node[:postgresql][:clusters][:"9.3/main"][:port]
170 database_name database_name
171 database_username "apis"
175 template "#{rails_directory}/config/initializers/setup.rb" do
176 source "rails.setup.rb.erb"
180 variables :site => site_name
181 notifies :run, "execute[#{rails_directory}]"
184 apache_site site_name do
185 template "apache.rails.erb"
186 variables :name => site_name, :aliases => site_aliases, :secret_key_base => secret_key_base
189 apache_site site_name do
193 directory rails_directory do
198 file "/etc/cron.daily/rails-#{name}" do
202 postgresql_database database_name do
207 node.normal[:dev][:rails].delete(name)
211 directory "/srv/apis.dev.openstreetmap.org" do
217 template "/srv/apis.dev.openstreetmap.org/index.html" do
218 source "apis.html.erb"
224 apache_site "apis.dev.openstreetmap.org" do
225 template "apache.apis.erb"
228 node[:postgresql][:clusters].each_key do |name|
229 postgresql_munin name do