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"
26 include_recipe "memcached"
27 include_recipe "mysql"
28 include_recipe "nodejs"
29 include_recipe "postgresql"
30 include_recipe "python"
65 libboost-program-options-dev
66 libboost-date-time-dev
67 libboost-filesystem-dev
77 python_package "geojson"
80 apache_module "expires"
81 apache_module "headers"
83 apache_module "proxy_fcgi"
84 apache_module "rewrite"
85 apache_module "suexec"
86 apache_module "userdir"
89 package "apache2-suexec-pristine"
91 service "php7.2-fpm" do
92 action [:enable, :start]
95 template "/etc/php/7.2/fpm/pool.d/default.conf" do
96 source "fpm-default.conf.erb"
100 notifies :reload, "service[php7.2-fpm]"
103 file "/etc/php/7.2/fpm/pool.d/www.conf" do
105 notifies :reload, "service[php7.2-fpm]"
108 directory "/srv/dev.openstreetmap.org" do
114 template "/srv/dev.openstreetmap.org/index.html" do
115 source "dev.html.erb"
121 ssl_certificate "dev.openstreetmap.org" do
122 domains "dev.openstreetmap.org"
123 notifies :reload, "service[apache2]"
126 apache_site "dev.openstreetmap.org" do
127 template "apache.dev.erb"
132 template "/etc/phppgadmin/config.inc.php" do
133 source "phppgadmin.conf.erb"
139 file "/etc/apache2/conf.d/phppgadmin" do
143 ssl_certificate "phppgadmin.dev.openstreetmap.org" do
144 domains "phppgadmin.dev.openstreetmap.org"
145 notifies :reload, "service[apache2]"
148 apache_site "phppgadmin.dev.openstreetmap.org" do
149 template "apache.phppgadmin.erb"
152 search(:accounts, "*:*").each do |account|
154 details = node[:accounts][:users][name] || {}
156 next unless %w[user administrator].include?(details[:status])
158 user_home = details[:home] || account["home"] || "#{node[:accounts][:home]}/#{name}"
160 next unless File.directory?("#{user_home}/public_html")
162 port = 7000 + account["uid"].to_i
164 template "/etc/php/7.2/fpm/pool.d/#{name}.conf" do
165 source "fpm.conf.erb"
169 variables :user => name, :port => port
170 notifies :reload, "service[php7.2-fpm]"
173 ssl_certificate "#{name}.dev.openstreetmap.org" do
174 domains ["#{name}.dev.openstreetmap.org", "#{name}.dev.osm.org"]
175 notifies :reload, "service[apache2]"
178 apache_site "#{name}.dev.openstreetmap.org" do
179 template "apache.user.erb"
180 directory "#{user_home}/public_html"
181 variables :user => name, :port => port
184 template "/etc/sudoers.d/#{name}" do
185 source "sudoers.user.erb"
189 variables :user => name
193 if node[:postgresql][:clusters][:"9.5/main"]
194 postgresql_user "apis" do
198 template "/usr/local/bin/cleanup-rails-assets" do
200 source "cleanup-assets.erb"
206 systemd_service "cgimap@" do
207 description "OpenStreetMap API Server"
209 environment_file "/etc/default/cgimap-%i"
211 exec_start "/srv/%i.apis.dev.openstreetmap.org/cgimap/openstreetmap-cgimap --daemon --port $CGIMAP_PORT --instances 5"
212 exec_reload "/bin/kill -HUP $MAINPID"
215 protect_system "full"
217 no_new_privileges true
223 node[:dev][:rails].each do |name, details|
224 database_name = details[:database] || "apis_#{name}"
225 site_name = "#{name}.apis.dev.openstreetmap.org"
226 site_directory = "/srv/#{name}.apis.dev.openstreetmap.org"
227 log_directory = "#{site_directory}/logs"
228 rails_directory = "#{site_directory}/rails"
229 cgimap_directory = "#{site_directory}/cgimap"
231 if details[:repository]
232 site_aliases = details[:aliases] || []
233 secret_key_base = details[:secret_key_base] || SecureRandom.base64(96)
235 node.normal[:dev][:rails][name][:secret_key_base] = secret_key_base
237 postgresql_database database_name do
242 postgresql_extension "#{database_name}_btree_gist" do
244 database database_name
245 extension "btree_gist"
248 directory site_directory do
254 directory log_directory do
260 rails_port site_name do
261 ruby node[:passenger][:ruby_version]
262 directory rails_directory
265 repository details[:repository]
266 revision details[:revision]
267 database_port node[:postgresql][:clusters][:"9.5/main"][:port]
268 database_name database_name
269 database_username "apis"
270 log_path "#{log_directory}/rails.log"
271 memcache_servers ["127.0.0.1"]
276 template "#{rails_directory}/config/initializers/setup.rb" do
277 source "rails.setup.rb.erb"
281 variables :site => site_name
282 notifies :restart, "rails_port[#{site_name}]"
285 if details[:cgimap_repository]
286 git cgimap_directory do
288 repository details[:cgimap_repository]
289 revision details[:cgimap_revision]
294 execute "#{cgimap_directory}/autogen.sh" do
296 command "./autogen.sh"
300 subscribes :run, "git[#{cgimap_directory}]", :immediate
303 execute "#{cgimap_directory}/configure" do
305 command "./configure --with-fcgi=/usr --with-boost-libdir=/usr/lib/x86_64-linux-gnu"
309 subscribes :run, "execute[#{cgimap_directory}/autogen.sh]", :immediate
312 execute "#{cgimap_directory}/Makefile" do
318 subscribes :run, "execute[#{cgimap_directory}/configure]", :immediate
319 notifies :restart, "service[cgimap@#{name}]"
322 template "/etc/default/cgimap-#{name}" do
323 source "cgimap.environment.erb"
327 variables :cgimap_port => cgimap_port,
328 :database_port => node[:postgresql][:clusters][:"9.5/main"][:port],
329 :database_name => database_name,
330 :log_directory => log_directory
331 notifies :restart, "service[cgimap@#{name}]"
334 service "cgimap@#{name}" do
335 action [:start, :enable]
339 ssl_certificate site_name do
340 domains [site_name] + site_aliases
341 notifies :reload, "service[apache2]"
344 apache_site site_name do
345 template "apache.rails.erb"
346 variables :application_name => name,
347 :aliases => site_aliases,
348 :secret_key_base => secret_key_base,
349 :cgimap_enabled => details.key?(:cgimap_repository),
350 :cgimap_port => cgimap_port
353 template "/etc/logrotate.d/apis-#{name}" do
354 source "logrotate.apis.erb"
358 variables :name => name,
359 :log_directory => log_directory,
360 :rails_directory => rails_directory
365 file "/etc/logrotate.d/apis-#{name}" do
369 apache_site site_name do
373 service "cgimap@#{name}" do
374 action [:stop, :disable]
377 file "/etc/default/cgimap-#{name}" do
381 directory site_directory do
386 file "/etc/cron.daily/rails-#{site_name.tr('.', '-')}" do
390 postgresql_database database_name do
395 node.normal[:dev][:rails].delete(name)
399 directory "/srv/apis.dev.openstreetmap.org" do
405 template "/srv/apis.dev.openstreetmap.org/index.html" do
406 source "apis.html.erb"
412 ssl_certificate "apis.dev.openstreetmap.org" do
413 domains "apis.dev.openstreetmap.org"
414 notifies :reload, "service[apache2]"
417 apache_site "apis.dev.openstreetmap.org" do
418 template "apache.apis.erb"
421 node[:postgresql][:clusters].each_key do |name|
422 postgresql_munin name do
429 directory "/srv/ooc.openstreetmap.org" do
435 remote_directory "/srv/ooc.openstreetmap.org/html" do
445 ssl_certificate "ooc.openstreetmap.org" do
446 domains ["ooc.openstreetmap.org",
447 "a.ooc.openstreetmap.org",
448 "b.ooc.openstreetmap.org",
449 "c.ooc.openstreetmap.org"]
450 notifies :reload, "service[apache2]"
453 apache_site "ooc.openstreetmap.org" do
454 template "apache.ooc.erb"