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"
45 package "python-argparse"
46 package "python-beautifulsoup"
47 package "python-cheetah"
48 package "python-dateutil"
49 package "python-magic"
50 package "python-psycopg2"
52 easy_install_package "geojson"
55 apache_module "expires"
56 apache_module "fastcgi-handler"
57 apache_module "rewrite"
62 gem_package "rails" do
67 action [ :enable, :start ]
68 supports :status => true, :restart => true, :reload => true
71 template "/etc/php5/fpm/pool.d/default.conf" do
72 source "fpm-default.conf.erb"
76 notifies :reload, "service[php5-fpm]"
79 file "/etc/php5/fpm/pool.d/www.conf" do
81 notifies :reload, "service[php5-fpm]"
86 template "/etc/phppgadmin/config.inc.php" do
87 source "phppgadmin.conf.erb"
93 link "/etc/apache2/conf.d/phppgadmin" do
97 apache_site "phppgadmin.dev.openstreetmap.org" do
98 template "apache.phppgadmin.erb"
101 search(:accounts, "*:*").each do |account|
103 details = node[:accounts][:users][name] || {}
105 if ["user","administrator"].include?(details[:status])
106 user_home = details[:home] || account["home"] || "#{node[:accounts][:home]}/#{name.to_s}"
108 if File.directory?("#{user_home}/public_html")
109 template "/etc/php5/fpm/pool.d/#{name}.conf" do
110 source "fpm.conf.erb"
114 variables :user => name
115 notifies :reload, "service[php5-fpm]"
118 apache_site "#{name}.dev.openstreetmap.org" do
119 template "apache.user.erb"
120 directory "#{user_home}/public_html"
121 variables :user => name
127 if node[:postgresql][:clusters][:"9.1/main"]
128 postgresql_user "apis" do
132 node[:dev][:rails].each do |name,details|
133 database_name = details[:database] || "apis_#{name}"
134 site_name = "#{name}.apis.dev.openstreetmap.org"
135 site_aliases = details[:aliases] || []
136 rails_directory = "/srv/#{name}.apis.dev.openstreetmap.org"
137 secret_key_base = details[:secret_key_base] || SecureRandom.base64(96)
139 node.set[:dev][:rails][name][:secret_key_base] = secret_key_base
141 postgresql_database database_name do
146 postgresql_extension "#{database_name}_btree_gist" do
148 database database_name
149 extension "btree_gist"
152 rails_port site_name do
153 ruby node[:passenger][:ruby_version]
154 directory rails_directory
157 repository details[:repository]
158 revision details[:revision]
159 database_port node[:postgresql][:clusters][:"9.1/main"][:port]
160 database_name database_name
161 database_username "apis"
165 template "#{rails_directory}/config/initializers/setup.rb" do
166 source "rails.setup.rb.erb"
170 variables :site => site_name
171 notifies :touch, "file[#{rails_directory}/tmp/restart.txt]"
174 apache_site site_name do
175 template "apache.rails.erb"
176 variables :name => site_name, :aliases => site_aliases, :secret_key_base => secret_key_base
180 Dir.glob("/srv/*.apis.dev.openstreetmap.org").each do |rails_directory|
181 name = File.basename(rails_directory, ".apis.dev.openstreetmap.org")
183 unless node[:dev][:rails].include?(name) and node[:dev][:rails][name].include?(:repository)
184 database_config = YAML.load_file("#{rails_directory}/config/database.yml")
185 database_name = database_config["production"]["database"]
186 site_name = "#{name}.apis.dev.openstreetmap.org"
188 apache_site site_name do
192 directory rails_directory do
197 file "/etc/cron.daily/rails-#{name}" do
201 postgresql_database database_name do
208 directory "/srv/apis.dev.openstreetmap.org" do
214 template "/srv/apis.dev.openstreetmap.org/index.html" do
215 source "apis.html.erb"
221 apache_site "apis.dev.openstreetmap.org" do
222 template "apache.apis.erb"
225 node[:postgresql][:clusters].each do |name,details|
226 postgresql_munin name do