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 # https://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"
25 include_recipe "geoipupdate"
27 include_recipe "memcached"
28 include_recipe "munin"
29 include_recipe "mysql"
30 include_recipe "nodejs"
31 include_recipe "php::fpm"
32 include_recipe "postgresql"
33 include_recipe "python"
67 libboost-program-options-dev
68 libboost-date-time-dev
69 libboost-filesystem-dev
80 python_package "geojson" do
85 apache_module "expires"
86 apache_module "headers"
88 apache_module "proxy_fcgi"
89 apache_module "rewrite"
90 apache_module "suexec"
91 apache_module "userdir"
93 apache_module "wsgi" do
94 package "libapache2-mod-wsgi-py3"
97 package "apache2-suexec-pristine"
102 pm_min_spare_servers 2
103 pm_max_spare_servers 6
110 directory "/srv/dev.openstreetmap.org" do
116 template "/srv/dev.openstreetmap.org/index.html" do
117 source "dev.html.erb"
123 ssl_certificate "dev.openstreetmap.org" do
124 domains "dev.openstreetmap.org"
125 notifies :reload, "service[apache2]"
128 apache_site "dev.openstreetmap.org" do
129 template "apache.dev.erb"
134 template "/etc/phppgadmin/config.inc.php" do
135 source "phppgadmin.conf.erb"
141 file "/etc/apache2/conf.d/phppgadmin" do
145 ssl_certificate "phppgadmin.dev.openstreetmap.org" do
146 domains "phppgadmin.dev.openstreetmap.org"
147 notifies :reload, "service[apache2]"
150 apache_site "phppgadmin.dev.openstreetmap.org" do
151 template "apache.phppgadmin.erb"
154 search(:accounts, "*:*").each do |account|
156 details = node[:accounts][:users][name] || {}
158 next unless %w[user administrator].include?(details[:status])
160 user_home = details[:home] || account["home"] || "#{node[:accounts][:home]}/#{name}"
162 next unless File.directory?("#{user_home}/public_html")
169 pm_min_spare_servers 2
170 pm_max_spare_servers 6
171 pm_max_requests 10000
172 request_terminate_timeout 1800
173 environment "HOSTNAME" => "$HOSTNAME",
174 "PATH" => "/usr/local/bin:/usr/bin:/bin",
178 php_values "max_execution_time" => "300",
179 "memory_limit" => "128M",
180 "post_max_size" => "32M",
181 "upload_max_filesize" => "32M"
182 php_admin_values "sendmail_path" => "/usr/sbin/sendmail -t -i -f #{name}@errol.openstreetmap.org",
183 "open_basedir" => "/home/#{name}/:/tmp/:/usr/share/php/"
184 php_flags "display_errors" => "on"
187 ssl_certificate "#{name}.dev.openstreetmap.org" do
188 domains ["#{name}.dev.openstreetmap.org", "#{name}.dev.osm.org"]
189 notifies :reload, "service[apache2]"
192 apache_site "#{name}.dev.openstreetmap.org" do
193 template "apache.user.erb"
194 directory "#{user_home}/public_html"
195 variables :user => name
198 template "/etc/sudoers.d/#{name}" do
199 source "sudoers.user.erb"
203 variables :user => name
207 if node[:postgresql][:clusters][:"14/main"]
208 postgresql_user "apis" do
212 template "/usr/local/bin/cleanup-rails-assets" do
214 source "cleanup-assets.erb"
220 systemd_service "rails-jobs@" do
221 description "Rails job queue runner"
224 working_directory "/srv/%i.apis.dev.openstreetmap.org/rails"
225 exec_start "#{node[:ruby][:bundle]} exec rails jobs:work"
229 protect_system "full"
231 no_new_privileges true
234 systemd_service "cgimap@" do
235 description "OpenStreetMap API Server"
237 environment_file "/etc/default/cgimap-%i"
239 exec_start "/srv/%i.apis.dev.openstreetmap.org/cgimap/openstreetmap-cgimap --daemon --port $CGIMAP_PORT --instances 5"
240 exec_reload "/bin/kill -HUP $MAINPID"
243 protect_system "full"
245 no_new_privileges true
251 Dir.glob("/srv/*.apis.dev.openstreetmap.org").each do |dir|
252 node.default_unless[:dev][:rails][File.basename(dir).split(".").first] = {}
255 node[:dev][:rails].each do |name, details|
256 database_name = details[:database] || "apis_#{name}"
257 site_name = "#{name}.apis.dev.openstreetmap.org"
258 site_directory = "/srv/#{name}.apis.dev.openstreetmap.org"
259 log_directory = "#{site_directory}/logs"
260 rails_directory = "#{site_directory}/rails"
261 cgimap_directory = "#{site_directory}/cgimap"
262 gpx_directory = "#{site_directory}/gpx"
264 if details[:repository]
265 site_aliases = details[:aliases] || []
266 secret_key_base = persistent_token("dev", "rails", name, "secret_key_base")
268 postgresql_database database_name do
273 postgresql_extension "#{database_name}_btree_gist" do
275 database database_name
276 extension "btree_gist"
279 directory site_directory do
285 directory log_directory do
291 directory gpx_directory do
297 directory "#{gpx_directory}/traces" do
303 directory "#{gpx_directory}/images" do
309 rails_port site_name do
310 directory rails_directory
313 repository details[:repository]
314 revision details[:revision]
315 database_port node[:postgresql][:clusters][:"14/main"][:port]
316 database_name database_name
317 database_username "apis"
318 email_from "OpenStreetMap <web@noreply.openstreetmap.org>"
319 gpx_dir gpx_directory
320 log_path "#{log_directory}/rails.log"
321 memcache_servers ["127.0.0.1"]
324 trace_use_job_queue true
327 template "#{rails_directory}/config/initializers/setup.rb" do
328 source "rails.setup.rb.erb"
332 variables :site => site_name
333 notifies :restart, "rails_port[#{site_name}]"
336 service "rails-jobs@#{name}" do
337 action [:enable, :start]
338 supports :restart => true
339 subscribes :restart, "rails_port[#{site_name}]"
340 subscribes :restart, "systemd_service[#{name}]"
341 only_if "fgrep -q delayed_job #{rails_directory}/Gemfile.lock"
344 if details[:cgimap_repository]
345 git cgimap_directory do
347 repository details[:cgimap_repository]
348 revision details[:cgimap_revision]
353 execute "#{cgimap_directory}/autogen.sh" do
355 command "./autogen.sh"
359 subscribes :run, "git[#{cgimap_directory}]", :immediately
362 execute "#{cgimap_directory}/configure" do
364 command "./configure --with-fcgi=/usr --with-boost-libdir=/usr/lib/x86_64-linux-gnu --enable-yajl"
368 subscribes :run, "execute[#{cgimap_directory}/autogen.sh]", :immediately
371 execute "#{cgimap_directory}/Makefile" do
377 subscribes :run, "execute[#{cgimap_directory}/configure]", :immediately
378 notifies :restart, "service[cgimap@#{name}]"
381 template "/etc/default/cgimap-#{name}" do
382 source "cgimap.environment.erb"
386 variables :cgimap_port => cgimap_port,
387 :database_port => node[:postgresql][:clusters][:"14/main"][:port],
388 :database_name => database_name,
389 :log_directory => log_directory
390 notifies :restart, "service[cgimap@#{name}]"
393 service "cgimap@#{name}" do
394 action [:start, :enable]
398 ssl_certificate site_name do
399 domains [site_name] + site_aliases
400 notifies :reload, "service[apache2]"
403 apache_site site_name do
404 template "apache.rails.erb"
405 variables :application_name => name,
406 :aliases => site_aliases,
407 :secret_key_base => secret_key_base,
408 :cgimap_enabled => details.key?(:cgimap_repository),
409 :cgimap_port => cgimap_port
412 template "/etc/logrotate.d/apis-#{name}" do
413 source "logrotate.apis.erb"
417 variables :name => name,
418 :log_directory => log_directory,
419 :rails_directory => rails_directory
424 file "/etc/logrotate.d/apis-#{name}" do
428 apache_site site_name do
432 service "cgimap@#{name}" do
433 action [:stop, :disable]
436 file "/etc/default/cgimap-#{name}" do
440 service "rails-jobs@#{name}" do
441 action [:stop, :disable]
444 directory site_directory do
449 file "/etc/cron.daily/rails-#{site_name.tr('.', '-')}" do
453 postgresql_database database_name do
460 directory "/srv/apis.dev.openstreetmap.org" do
466 template "/srv/apis.dev.openstreetmap.org/index.html" do
467 source "apis.html.erb"
473 ssl_certificate "apis.dev.openstreetmap.org" do
474 domains "apis.dev.openstreetmap.org"
475 notifies :reload, "service[apache2]"
478 apache_site "apis.dev.openstreetmap.org" do
479 template "apache.apis.erb"
482 node[:postgresql][:clusters].each_key do |name|
483 postgresql_munin name do
490 directory "/srv/ooc.openstreetmap.org" do
496 remote_directory "/srv/ooc.openstreetmap.org/html" do
506 ssl_certificate "ooc.openstreetmap.org" do
507 domains ["ooc.openstreetmap.org",
508 "a.ooc.openstreetmap.org",
509 "b.ooc.openstreetmap.org",
510 "c.ooc.openstreetmap.org"]
511 notifies :reload, "service[apache2]"
514 apache_site "ooc.openstreetmap.org" do
515 template "apache.ooc.erb"