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"
57 apache_module "proxy_fcgi"
58 apache_module "rewrite"
63 gem_package "rails" do
68 provider Chef::Provider::Service::Upstart
69 action [ :enable, :start ]
70 supports :status => true, :restart => true, :reload => true
73 template "/etc/php5/fpm/pool.d/default.conf" do
74 source "fpm-default.conf.erb"
78 notifies :reload, "service[php5-fpm]"
81 file "/etc/php5/fpm/pool.d/www.conf" do
83 notifies :reload, "service[php5-fpm]"
88 template "/etc/phppgadmin/config.inc.php" do
89 source "phppgadmin.conf.erb"
95 file "/etc/apache2/conf.d/phppgadmin" do
99 apache_site "phppgadmin.dev.openstreetmap.org" do
100 template "apache.phppgadmin.erb"
103 search(:accounts, "*:*").each do |account|
105 details = node[:accounts][:users][name] || {}
106 port = 7000 + account["uid"].to_i
108 if ["user","administrator"].include?(details[:status])
109 user_home = details[:home] || account["home"] || "#{node[:accounts][:home]}/#{name.to_s}"
111 if File.directory?("#{user_home}/public_html")
112 template "/etc/php5/fpm/pool.d/#{name}.conf" do
113 source "fpm.conf.erb"
117 variables :user => name, :port => port
118 notifies :reload, "service[php5-fpm]"
121 apache_site "#{name}.dev.openstreetmap.org" do
122 template "apache.user.erb"
123 directory "#{user_home}/public_html"
124 variables :user => name, :port => port
130 if node[:postgresql][:clusters][:"9.1/main"]
131 postgresql_user "apis" do
135 node[:dev][:rails].each do |name,details|
136 database_name = details[:database] || "apis_#{name}"
137 site_name = "#{name}.apis.dev.openstreetmap.org"
138 site_aliases = details[:aliases] || []
139 rails_directory = "/srv/#{name}.apis.dev.openstreetmap.org"
140 secret_key_base = details[:secret_key_base] || SecureRandom.base64(96)
142 node.set[:dev][:rails][name][:secret_key_base] = secret_key_base
144 postgresql_database database_name do
149 postgresql_extension "#{database_name}_btree_gist" do
151 database database_name
152 extension "btree_gist"
155 rails_port site_name do
156 ruby node[:passenger][:ruby_version]
157 directory rails_directory
160 repository details[:repository]
161 revision details[:revision]
162 database_port node[:postgresql][:clusters][:"9.3/main"][:port]
163 database_name database_name
164 database_username "apis"
168 template "#{rails_directory}/config/initializers/setup.rb" do
169 source "rails.setup.rb.erb"
173 variables :site => site_name
174 notifies :touch, "file[#{rails_directory}/tmp/restart.txt]"
177 apache_site site_name do
178 template "apache.rails.erb"
179 variables :name => site_name, :aliases => site_aliases, :secret_key_base => secret_key_base
183 Dir.glob("/srv/*.apis.dev.openstreetmap.org").each do |rails_directory|
184 name = File.basename(rails_directory, ".apis.dev.openstreetmap.org")
186 unless node[:dev][:rails].include?(name) and node[:dev][:rails][name].include?(:repository)
187 database_config = YAML.load_file("#{rails_directory}/config/database.yml")
188 database_name = database_config["production"]["database"]
189 site_name = "#{name}.apis.dev.openstreetmap.org"
191 apache_site site_name do
195 directory rails_directory do
200 file "/etc/cron.daily/rails-#{name}" do
204 postgresql_database database_name do
209 node[:dev][:rails][name].delete(:secret_key_base)
213 directory "/srv/apis.dev.openstreetmap.org" do
219 template "/srv/apis.dev.openstreetmap.org/index.html" do
220 source "apis.html.erb"
226 apache_site "apis.dev.openstreetmap.org" do
227 template "apache.apis.erb"
230 node[:postgresql][:clusters].each do |name,details|
231 postgresql_munin name do