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
220 action :create_if_missing
228 notifies :run, "execute[#{file}]", :immediately
229 notifies :restart, "service[renderd]"
233 nodejs_package "carto"
234 nodejs_package "millstone"
236 directory "/srv/tile.openstreetmap.org/styles" do
242 node[:tile][:styles].each do |name, details|
243 style_directory = "/srv/tile.openstreetmap.org/styles/#{name}"
244 tile_directory = "/srv/tile.openstreetmap.org/tiles/#{name}"
246 template "/usr/local/bin/update-lowzoom-#{name}" do
247 source "update-lowzoom.erb"
251 variables :style => name
254 template "/etc/init.d/update-lowzoom-#{name}" do
255 source "update-lowzoom.init.erb"
259 variables :style => name
262 service "update-lowzoom-#{name}" do
264 supports :restart => true
267 directory tile_directory do
273 details[:tile_directories].each do |directory|
274 directory directory[:name] do
280 directory[:min_zoom].upto(directory[:max_zoom]) do |zoom|
281 directory "#{directory[:name]}/#{zoom}" do
287 link "#{tile_directory}/#{zoom}" do
288 to "#{directory[:name]}/#{zoom}"
295 file "#{tile_directory}/planet-import-complete" do
296 action :create_if_missing
302 git style_directory do
304 repository details[:repository]
305 revision details[:revision]
310 link "#{style_directory}/data" do
311 to "/srv/tile.openstreetmap.org/data"
316 execute "#{style_directory}/project.mml" do
318 command "carto project.mml > project.xml"
322 subscribes :run, "git[#{style_directory}]"
323 notifies :restart, "service[renderd]", :immediately
324 notifies :restart, "service[update-lowzoom-#{name}]"
330 postgresql_user "jburgess" do
331 cluster node[:tile][:database][:cluster]
335 postgresql_user "tomh" do
336 cluster node[:tile][:database][:cluster]
340 postgresql_user "tile" do
341 cluster node[:tile][:database][:cluster]
344 postgresql_user "www-data" do
345 cluster node[:tile][:database][:cluster]
348 postgresql_database "gis" do
349 cluster node[:tile][:database][:cluster]
353 postgresql_extension "postgis" do
354 cluster node[:tile][:database][:cluster]
358 %w(geography_columns planet_osm_nodes planet_osm_rels planet_osm_ways raster_columns raster_overviews spatial_ref_sys).each do |table|
359 postgresql_table table do
360 cluster node[:tile][:database][:cluster]
363 permissions "tile" => :all
367 %w(geometry_columns planet_osm_line planet_osm_point planet_osm_polygon planet_osm_roads).each do |table|
368 postgresql_table table do
369 cluster node[:tile][:database][:cluster]
372 permissions "tile" => :all, "www-data" => :select
376 postgresql_munin "gis" do
377 cluster node[:tile][:database][:cluster]
381 file node[:tile][:node_file] do
387 directory "/var/log/tile" do
399 if node[:lsb][:release].to_f < 14.04
403 package "libproj-dev"
404 package "libxml2-dev"
406 gem_package "proj4rb"
407 gem_package "libxml-ruby"
409 remote_directory "/usr/local/lib/site_ruby" do
419 template "/usr/local/bin/expire-tiles" do
420 source "expire-tiles.erb"
426 template "/etc/sudoers.d/tile" do
433 directory "/var/lib/replicate" do
439 template "/var/lib/replicate/configuration.txt" do
440 source "replicate.configuration.erb"
446 template "/usr/local/bin/replicate" do
447 source "replicate.erb"
453 template "/etc/init.d/replicate" do
454 source "replicate.init.erb"
460 service "replicate" do
461 action [:enable, :start]
462 supports :restart => true
463 subscribes :restart, "template[/usr/local/bin/replicate]"
464 subscribes :restart, "template[/etc/init.d/replicate]"
467 template "/etc/logrotate.d/replicate" do
468 source "replicate.logrotate.erb"
474 template "/usr/local/bin/render-lowzoom" do
475 source "render-lowzoom.erb"
481 template "/etc/cron.d/render-lowzoom" do
482 source "render-lowzoom.cron.erb"
488 template "/etc/rsyslog.d/20-renderd.conf" do
489 source "renderd.rsyslog.erb"
493 notifies :restart, "service[rsyslog]"
496 template "/etc/logrotate.d/renderd" do
497 source "renderd.logrotate.erb"
503 package "liblockfile-simple-perl"
504 package "libfilesys-df-perl"
506 template "/usr/local/bin/cleanup-tiles" do
507 source "cleanup-tiles.erb"
513 tile_directories = node[:tile][:styles].collect do |_, style|
514 style[:tile_directories].collect { |directory| directory[:name] }
515 end.flatten.sort.uniq
517 template "/etc/cron.d/cleanup-tiles" do
518 source "cleanup-tiles.cron.erb"
522 variables :directories => tile_directories
525 munin_plugin "mod_tile_fresh"
526 munin_plugin "mod_tile_latency"
527 munin_plugin "mod_tile_response"
528 munin_plugin "mod_tile_zoom"
530 munin_plugin "renderd_processed"
531 munin_plugin "renderd_queue"
532 munin_plugin "renderd_queue_time"
533 munin_plugin "renderd_zoom"
534 munin_plugin "renderd_zoom_time"
536 munin_plugin "replication_delay" do