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")
29 apache_module "expires"
30 apache_module "headers"
31 apache_module "remoteip"
32 apache_module "rewrite"
34 apache_module "tile" do
38 tilecaches = search(:node, "roles:tilecache").sort_by { |n| n[:hostname] }
40 apache_site "default" do
44 apache_site "tile.openstreetmap.org" do
46 variables :caches => tilecaches
49 template "/etc/logrotate.d/apache2" do
50 source "logrotate.apache.erb"
56 directory "/srv/tile.openstreetmap.org" do
65 action [:enable, :start]
66 supports :status => false, :restart => true, :reload => false
69 directory "/srv/tile.openstreetmap.org/tiles" do
75 template "/etc/renderd.conf" do
76 source "renderd.conf.erb"
80 notifies :reload, "service[apache2]"
81 notifies :restart, "service[renderd]"
84 remote_directory "/srv/tile.openstreetmap.org/html" do
94 template "/srv/tile.openstreetmap.org/html/index.html" do
95 source "index.html.erb"
101 package "python-cairo"
102 package "python-mapnik"
105 package "fonts-droid"
106 package "ttf-unifont"
107 package "fonts-sipa-arundina"
108 package "fonts-sil-padauk"
109 package "fonts-khmeros"
110 package "ttf-indic-fonts-core"
111 package "ttf-tamil-fonts"
112 package "ttf-kannada-fonts"
114 directory "/srv/tile.openstreetmap.org/cgi-bin" do
120 template "/srv/tile.openstreetmap.org/cgi-bin/export" do
125 variables :blocks => blocks
128 template "/srv/tile.openstreetmap.org/cgi-bin/debug" do
135 template "/etc/cron.hourly/export" do
136 source "export.cron.erb"
142 directory "/srv/tile.openstreetmap.org/data" do
148 package "mapnik-utils"
150 node[:tile][:data].each_value do |data|
152 file = "/srv/tile.openstreetmap.org/data/#{File.basename(url)}"
153 directory = "/srv/tile.openstreetmap.org/data/#{data[:directory]}"
155 directory directory do
166 command "tar -zxf #{file} -C #{directory}"
170 elsif file =~ /\.tar\.bz2$/
175 command "tar -jxf #{file} -C #{directory}"
179 elsif file =~ /\.zip$/
184 command "unzip -qq -o #{file} -d #{directory}"
191 original = "#{directory}/#{data[:original]}"
192 processed = "#{directory}/#{data[:processed]}"
198 command "ogr2ogr #{processed} #{original}"
201 subscribes :run, "execute[#{file}]", :immediately
205 execute "#{file}_shapeindex" do
207 command "find #{directory} -type f -iname '*.shp' -print0 | xargs -0 --no-run-if-empty shapeindex --shape_files"
210 subscribes :run, "execute[#{file}]", :immediately
216 use_conditional_get true
218 action :create_if_missing
226 notifies :run, "execute[#{file}]", :immediately
227 notifies :restart, "service[renderd]"
231 nodejs_package "carto"
232 nodejs_package "millstone"
234 directory "/srv/tile.openstreetmap.org/styles" do
240 node[:tile][:styles].each do |name, details|
241 style_directory = "/srv/tile.openstreetmap.org/styles/#{name}"
242 tile_directory = "/srv/tile.openstreetmap.org/tiles/#{name}"
244 template "/usr/local/bin/update-lowzoom-#{name}" do
245 source "update-lowzoom.erb"
249 variables :style => name
252 template "/etc/init.d/update-lowzoom-#{name}" do
253 source "update-lowzoom.init.erb"
257 variables :style => name
260 service "update-lowzoom-#{name}" do
262 supports :restart => true
265 directory tile_directory do
271 details[:tile_directories].each do |directory|
272 directory directory[:name] do
278 directory[:min_zoom].upto(directory[:max_zoom]) do |zoom|
279 directory "#{directory[:name]}/#{zoom}" do
285 link "#{tile_directory}/#{zoom}" do
286 to "#{directory[:name]}/#{zoom}"
293 file "#{tile_directory}/planet-import-complete" do
294 action :create_if_missing
300 git style_directory do
302 repository details[:repository]
303 revision details[:revision]
308 link "#{style_directory}/data" do
309 to "/srv/tile.openstreetmap.org/data"
314 execute "#{style_directory}/project.mml" do
316 command "carto project.mml > project.xml"
320 subscribes :run, "git[#{style_directory}]"
321 notifies :restart, "service[renderd]", :immediately
322 notifies :restart, "service[update-lowzoom-#{name}]"
328 postgresql_user "jburgess" do
329 cluster node[:tile][:database][:cluster]
333 postgresql_user "tomh" do
334 cluster node[:tile][:database][:cluster]
338 postgresql_user "tile" do
339 cluster node[:tile][:database][:cluster]
342 postgresql_user "www-data" do
343 cluster node[:tile][:database][:cluster]
346 postgresql_database "gis" do
347 cluster node[:tile][:database][:cluster]
351 postgresql_extension "postgis" do
352 cluster node[:tile][:database][:cluster]
356 %w(geography_columns planet_osm_nodes planet_osm_rels planet_osm_ways raster_columns raster_overviews spatial_ref_sys).each do |table|
357 postgresql_table table do
358 cluster node[:tile][:database][:cluster]
361 permissions "tile" => :all
365 %w(geometry_columns planet_osm_line planet_osm_point planet_osm_polygon planet_osm_roads).each do |table|
366 postgresql_table table do
367 cluster node[:tile][:database][:cluster]
370 permissions "tile" => :all, "www-data" => :select
374 postgresql_munin "gis" do
375 cluster node[:tile][:database][:cluster]
379 file node[:tile][:node_file] do
385 directory "/var/log/tile" do
397 package "libproj-dev"
398 package "libxml2-dev"
400 gem_package "proj4rb"
401 gem_package "libxml-ruby"
404 remote_directory "/usr/local/lib/site_ruby" do
414 template "/usr/local/bin/expire-tiles" do
415 source "expire-tiles.erb"
421 template "/etc/sudoers.d/tile" do
428 directory "/var/lib/replicate" do
434 template "/var/lib/replicate/configuration.txt" do
435 source "replicate.configuration.erb"
441 template "/usr/local/bin/replicate" do
442 source "replicate.erb"
448 template "/etc/init.d/replicate" do
449 source "replicate.init.erb"
455 service "replicate" do
456 action [:enable, :start]
457 supports :restart => true
458 subscribes :restart, "template[/usr/local/bin/replicate]"
459 subscribes :restart, "template[/etc/init.d/replicate]"
462 template "/etc/logrotate.d/replicate" do
463 source "replicate.logrotate.erb"
469 template "/usr/local/bin/render-lowzoom" do
470 source "render-lowzoom.erb"
476 template "/etc/cron.d/render-lowzoom" do
477 source "render-lowzoom.cron.erb"
483 template "/etc/rsyslog.d/20-renderd.conf" do
484 source "renderd.rsyslog.erb"
488 notifies :restart, "service[rsyslog]"
491 template "/etc/logrotate.d/renderd" do
492 source "renderd.logrotate.erb"
498 package "liblockfile-simple-perl"
499 package "libfilesys-df-perl"
501 template "/usr/local/bin/cleanup-tiles" do
502 source "cleanup-tiles.erb"
508 tile_directories = node[:tile][:styles].collect do |_, style|
509 style[:tile_directories].collect { |directory| directory[:name] }
510 end.flatten.sort.uniq
512 template "/etc/cron.d/cleanup-tiles" do
513 source "cleanup-tiles.cron.erb"
517 variables :directories => tile_directories
520 munin_plugin "mod_tile_fresh"
521 munin_plugin "mod_tile_latency"
522 munin_plugin "mod_tile_response"
523 munin_plugin "mod_tile_zoom"
525 munin_plugin "renderd_processed"
526 munin_plugin "renderd_queue"
527 munin_plugin "renderd_queue_time"
528 munin_plugin "renderd_zoom"
529 munin_plugin "renderd_zoom_time"
531 munin_plugin "replication_delay" do