5 # Copyright 2013, 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.
20 include_recipe "apache"
22 include_recipe "nodejs"
23 include_recipe "postgresql"
24 include_recipe "tools"
26 blocks = data_bag_item("tile", "blocks")
30 apache_module "expires"
31 apache_module "headers"
32 apache_module "remoteip"
33 apache_module "rewrite"
35 apache_module "tile" do
39 tilecaches = search(:node, "roles:tilecache").sort_by { |n| n[:hostname] }
41 apache_site "default" do
45 apache_site "tile.openstreetmap.org" do
47 variables :caches => tilecaches
50 template "/etc/logrotate.d/apache2" do
51 source "logrotate.apache.erb"
57 directory "/srv/tile.openstreetmap.org" do
66 action [:enable, :start]
67 supports :status => false, :restart => true, :reload => false
70 directory "/srv/tile.openstreetmap.org/tiles" do
76 template "/etc/renderd.conf" do
77 source "renderd.conf.erb"
81 notifies :reload, "service[apache2]"
82 notifies :restart, "service[renderd]"
85 remote_directory "/srv/tile.openstreetmap.org/html" do
95 template "/srv/tile.openstreetmap.org/html/index.html" do
96 source "index.html.erb"
102 package "python-cairo"
103 package "python-mapnik"
106 package "fonts-droid"
107 package "ttf-unifont"
108 package "fonts-sipa-arundina"
109 package "fonts-sil-padauk"
110 package "fonts-khmeros"
111 package "ttf-indic-fonts-core"
112 package "ttf-tamil-fonts"
113 package "ttf-kannada-fonts"
115 directory "/srv/tile.openstreetmap.org/cgi-bin" do
121 template "/srv/tile.openstreetmap.org/cgi-bin/export" do
126 variables :blocks => blocks
129 template "/srv/tile.openstreetmap.org/cgi-bin/debug" do
136 template "/etc/cron.hourly/export" do
137 source "export.cron.erb"
143 directory "/srv/tile.openstreetmap.org/data" do
149 package "mapnik-utils"
151 node[:tile][:data].each_value do |data|
153 file = "/srv/tile.openstreetmap.org/data/#{File.basename(url)}"
154 directory = "/srv/tile.openstreetmap.org/data/#{data[:directory]}"
156 directory directory do
167 command "tar -zxf #{file} -C #{directory}"
171 elsif file =~ /\.tar\.bz2$/
176 command "tar -jxf #{file} -C #{directory}"
180 elsif file =~ /\.zip$/
185 command "unzip -qq -o #{file} -d #{directory}"
192 original = "#{directory}/#{data[:original]}"
193 processed = "#{directory}/#{data[:processed]}"
199 command "ogr2ogr #{processed} #{original}"
202 subscribes :run, "execute[#{file}]", :immediately
206 execute "#{file}_shapeindex" do
208 command "find #{directory} -type f -iname '*.shp' -print0 | xargs -0 --no-run-if-empty shapeindex --shape_files"
211 subscribes :run, "execute[#{file}]", :immediately
217 use_conditional_get true
219 action :create_if_missing
227 notifies :run, "execute[#{file}]", :immediately
228 notifies :restart, "service[renderd]"
232 nodejs_package "carto"
233 nodejs_package "millstone"
235 directory "/srv/tile.openstreetmap.org/styles" do
241 node[:tile][:styles].each do |name, details|
242 style_directory = "/srv/tile.openstreetmap.org/styles/#{name}"
243 tile_directory = "/srv/tile.openstreetmap.org/tiles/#{name}"
245 template "/usr/local/bin/update-lowzoom-#{name}" do
246 source "update-lowzoom.erb"
250 variables :style => name
253 template "/etc/init.d/update-lowzoom-#{name}" do
254 source "update-lowzoom.init.erb"
258 variables :style => name
261 service "update-lowzoom-#{name}" do
263 supports :restart => true
266 directory tile_directory do
272 details[:tile_directories].each do |directory|
273 directory directory[:name] do
279 directory[:min_zoom].upto(directory[:max_zoom]) do |zoom|
280 directory "#{directory[:name]}/#{zoom}" do
286 link "#{tile_directory}/#{zoom}" do
287 to "#{directory[:name]}/#{zoom}"
294 file "#{tile_directory}/planet-import-complete" do
295 action :create_if_missing
301 git style_directory do
303 repository details[:repository]
304 revision details[:revision]
309 link "#{style_directory}/data" do
310 to "/srv/tile.openstreetmap.org/data"
315 execute "#{style_directory}/project.mml" do
317 command "carto project.mml > project.xml"
321 subscribes :run, "git[#{style_directory}]"
322 notifies :restart, "service[renderd]", :immediately
323 notifies :restart, "service[update-lowzoom-#{name}]"
329 postgresql_user "jburgess" do
330 cluster node[:tile][:database][:cluster]
334 postgresql_user "tomh" do
335 cluster node[:tile][:database][:cluster]
339 postgresql_user "tile" do
340 cluster node[:tile][:database][:cluster]
343 postgresql_user "www-data" do
344 cluster node[:tile][:database][:cluster]
347 postgresql_database "gis" do
348 cluster node[:tile][:database][:cluster]
352 postgresql_extension "postgis" do
353 cluster node[:tile][:database][:cluster]
357 %w(geography_columns planet_osm_nodes planet_osm_rels planet_osm_ways raster_columns raster_overviews spatial_ref_sys).each do |table|
358 postgresql_table table do
359 cluster node[:tile][:database][:cluster]
362 permissions "tile" => :all
366 %w(geometry_columns planet_osm_line planet_osm_point planet_osm_polygon planet_osm_roads).each do |table|
367 postgresql_table table do
368 cluster node[:tile][:database][:cluster]
371 permissions "tile" => :all, "www-data" => :select
375 postgresql_munin "gis" do
376 cluster node[:tile][:database][:cluster]
380 file node[:tile][:node_file] do
386 directory "/var/log/tile" do
398 if node[:lsb][:release].to_f < 14.04
402 package "libproj-dev"
403 package "libxml2-dev"
405 gem_package "proj4rb"
406 gem_package "libxml-ruby"
408 remote_directory "/usr/local/lib/site_ruby" do
418 template "/usr/local/bin/expire-tiles" do
419 source "expire-tiles.erb"
425 template "/etc/sudoers.d/tile" do
432 directory "/var/lib/replicate" do
438 template "/var/lib/replicate/configuration.txt" do
439 source "replicate.configuration.erb"
445 template "/usr/local/bin/replicate" do
446 source "replicate.erb"
452 template "/etc/init.d/replicate" do
453 source "replicate.init.erb"
459 service "replicate" do
460 action [:enable, :start]
461 supports :restart => true
462 subscribes :restart, "template[/usr/local/bin/replicate]"
463 subscribes :restart, "template[/etc/init.d/replicate]"
466 template "/etc/logrotate.d/replicate" do
467 source "replicate.logrotate.erb"
473 template "/usr/local/bin/render-lowzoom" do
474 source "render-lowzoom.erb"
480 template "/etc/cron.d/render-lowzoom" do
481 source "render-lowzoom.cron.erb"
487 template "/etc/rsyslog.d/20-renderd.conf" do
488 source "renderd.rsyslog.erb"
492 notifies :restart, "service[rsyslog]"
495 template "/etc/logrotate.d/renderd" do
496 source "renderd.logrotate.erb"
502 package "liblockfile-simple-perl"
503 package "libfilesys-df-perl"
505 template "/usr/local/bin/cleanup-tiles" do
506 source "cleanup-tiles.erb"
512 tile_directories = node[:tile][:styles].collect do |_, style|
513 style[:tile_directories].collect { |directory| directory[:name] }
514 end.flatten.sort.uniq
516 template "/etc/cron.d/cleanup-tiles" do
517 source "cleanup-tiles.cron.erb"
521 variables :directories => tile_directories
524 munin_plugin "mod_tile_fresh"
525 munin_plugin "mod_tile_latency"
526 munin_plugin "mod_tile_response"
527 munin_plugin "mod_tile_zoom"
529 munin_plugin "renderd_processed"
530 munin_plugin "renderd_queue"
531 munin_plugin "renderd_queue_time"
532 munin_plugin "renderd_zoom"
533 munin_plugin "renderd_zoom_time"
535 munin_plugin "replication_delay" do