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.
22 include_recipe "apache"
24 include_recipe "mysql"
25 include_recipe "postgresql"
36 package "php5-imagick"
43 package "python-argparse"
44 package "python-beautifulsoup"
45 package "python-cheetah"
46 package "python-dateutil"
47 package "python-magic"
48 package "python-psycopg2"
50 apache_module "expires"
51 apache_module "fastcgi-handler"
52 apache_module "rewrite"
53 apache_module "expires"
56 apache_module "passenger" do
57 conf "passenger.conf.erb"
60 munin_plugin "passenger_memory"
61 munin_plugin "passenger_processes"
62 munin_plugin "passenger_queues"
63 munin_plugin "passenger_requests"
67 gem_package "rails" do
72 action [ :enable, :start ]
73 supports :status => true, :restart => true, :reload => true
76 template "/etc/php5/fpm/pool.d/default.conf" do
77 source "fpm-default.conf.erb"
81 notifies :reload, resources(:service => "php5-fpm")
84 file "/etc/php5/fpm/pool.d/www.conf" do
86 notifies :reload, resources(:service => "php5-fpm")
91 template "/etc/phppgadmin/config.inc.php" do
92 source "phppgadmin.conf.erb"
98 link "/etc/apache2/conf.d/phppgadmin" do
102 apache_site "phppgadmin.dev.openstreetmap.org" do
103 template "apache.phppgadmin.erb"
106 search(:accounts, "*:*").each do |account|
108 details = node[:accounts][:users][name] || {}
110 if ["user","administrator"].include?(details[:status])
111 user_home = details[:home] || account["home"] || "#{node[:accounts][:home]}/#{name.to_s}"
113 if File.directory?("#{user_home}/public_html")
114 template "/etc/php5/fpm/pool.d/#{name}.conf" do
115 source "fpm.conf.erb"
119 variables :user => name
120 notifies :reload, resources(:service => "php5-fpm")
123 apache_site "#{name}.dev.openstreetmap.org" do
124 template "apache.user.erb"
125 directory "#{user_home}/public_html"
126 variables :user => name
132 if node[:postgresql][:clusters]["9.1/main"]
133 postgresql_user "apis" do
137 node[:dev][:rails].each do |name,details|
138 database_name = details[:database] || "apis_#{name}"
139 site_name = "#{name}.apis.dev.openstreetmap.org"
140 site_aliases = details[:aliases] || []
141 rails_directory = "/srv/#{name}.apis.dev.openstreetmap.org"
143 postgresql_database database_name do
148 postgresql_extension "#{database_name}_btree_gist" do
150 database database_name
151 extension "btree_gist"
154 rails_port site_name do
155 ruby node[:dev][:ruby]
156 directory rails_directory
159 repository details[:repository]
160 revision details[:revision]
161 database_port node[:postgresql][:clusters]["9.1/main"][:port]
162 database_name database_name
163 database_username "apis"
167 template "#{rails_directory}/config/initializers/setup.rb" do
168 source "rails.setup.rb.erb"
172 variables :site => site_name
173 notifies :touch, resources(:file => "#{rails_directory}/tmp/restart.txt")
176 apache_site site_name do
177 template "apache.rails.erb"
178 variables :name => site_name, :aliases => site_aliases
182 Dir.glob("/srv/*.apis.dev.openstreetmap.org").each do |rails_directory|
183 name = File.basename(rails_directory, ".apis.dev.openstreetmap.org")
185 unless node[:dev][:rails].include?(name)
186 database_config = YAML.load_file("#{rails_directory}/config/database.yml")
187 database_name = database_config["production"]["database"]
188 site_name = "#{name}.apis.dev.openstreetmap.org"
190 apache_site site_name do
194 directory rails_directory do
199 file "/etc/cron.daily/rails-#{name}" do
203 postgresql_database database_name do
210 directory "/srv/apis.dev.openstreetmap.org" do
216 template "/srv/apis.dev.openstreetmap.org/index.html" do
217 source "apis.html.erb"
223 apache_site "apis.dev.openstreetmap.org" do
224 template "apache.apis.erb"
227 node[:postgresql][:clusters].each do |name,details|
228 postgresql_munin name do