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"
23 include_recipe "passenger"
25 include_recipe "mysql"
26 include_recipe "postgresql"
37 package "php5-imagick"
44 package "python-argparse"
45 package "python-beautifulsoup"
46 package "python-cheetah"
47 package "python-dateutil"
48 package "python-magic"
49 package "python-psycopg2"
51 apache_module "expires"
52 apache_module "fastcgi-handler"
53 apache_module "rewrite"
54 apache_module "expires"
59 gem_package "rails" do
64 action [ :enable, :start ]
65 supports :status => true, :restart => true, :reload => true
68 template "/etc/php5/fpm/pool.d/default.conf" do
69 source "fpm-default.conf.erb"
73 notifies :reload, "service[php5-fpm]"
76 file "/etc/php5/fpm/pool.d/www.conf" do
78 notifies :reload, "service[php5-fpm]"
83 template "/etc/phppgadmin/config.inc.php" do
84 source "phppgadmin.conf.erb"
90 link "/etc/apache2/conf.d/phppgadmin" do
94 apache_site "phppgadmin.dev.openstreetmap.org" do
95 template "apache.phppgadmin.erb"
98 search(:accounts, "*:*").each do |account|
100 details = node[:accounts][:users][name] || {}
102 if ["user","administrator"].include?(details[:status])
103 user_home = details[:home] || account["home"] || "#{node[:accounts][:home]}/#{name.to_s}"
105 if File.directory?("#{user_home}/public_html")
106 template "/etc/php5/fpm/pool.d/#{name}.conf" do
107 source "fpm.conf.erb"
111 variables :user => name
112 notifies :reload, "service[php5-fpm]"
115 apache_site "#{name}.dev.openstreetmap.org" do
116 template "apache.user.erb"
117 directory "#{user_home}/public_html"
118 variables :user => name
124 if node[:postgresql][:clusters][:"9.1/main"]
125 postgresql_user "apis" do
129 node[:dev][:rails].each do |name,details|
130 database_name = details[:database] || "apis_#{name}"
131 site_name = "#{name}.apis.dev.openstreetmap.org"
132 site_aliases = details[:aliases] || []
133 rails_directory = "/srv/#{name}.apis.dev.openstreetmap.org"
135 postgresql_database database_name do
140 postgresql_extension "#{database_name}_btree_gist" do
142 database database_name
143 extension "btree_gist"
146 rails_port site_name do
147 ruby node[:passenger][:ruby_version]
148 directory rails_directory
151 repository details[:repository]
152 revision details[:revision]
153 database_port node[:postgresql][:clusters][:"9.1/main"][:port]
154 database_name database_name
155 database_username "apis"
159 template "#{rails_directory}/config/initializers/setup.rb" do
160 source "rails.setup.rb.erb"
164 variables :site => site_name
165 notifies :touch, "file[#{rails_directory}/tmp/restart.txt]"
168 apache_site site_name do
169 template "apache.rails.erb"
170 variables :name => site_name, :aliases => site_aliases
174 Dir.glob("/srv/*.apis.dev.openstreetmap.org").each do |rails_directory|
175 name = File.basename(rails_directory, ".apis.dev.openstreetmap.org")
177 unless node[:dev][:rails].include?(name)
178 database_config = YAML.load_file("#{rails_directory}/config/database.yml")
179 database_name = database_config["production"]["database"]
180 site_name = "#{name}.apis.dev.openstreetmap.org"
182 apache_site site_name do
186 directory rails_directory do
191 file "/etc/cron.daily/rails-#{name}" do
195 postgresql_database database_name do
202 directory "/srv/apis.dev.openstreetmap.org" do
208 template "/srv/apis.dev.openstreetmap.org/index.html" do
209 source "apis.html.erb"
215 apache_site "apis.dev.openstreetmap.org" do
216 template "apache.apis.erb"
219 node[:postgresql][:clusters].each do |name,details|
220 postgresql_munin name do