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}"
191 execute "#{file}_shapeindex" do
193 command "find #{directory} -type f -iname '*.shp' -print0 | xargs -0 --no-run-if-empty shapeindex --shape_files"
196 subscribes :run, "execute[#{file}]", :immediately
202 use_conditional_get true
205 action :create_if_missing
213 notifies :run, "execute[#{file}]", :immediately
214 notifies :restart, "service[renderd]"
218 nodejs_package "carto"
219 nodejs_package "millstone"
221 directory "/srv/tile.openstreetmap.org/styles" do
227 node[:tile][:styles].each do |name, details|
228 style_directory = "/srv/tile.openstreetmap.org/styles/#{name}"
229 tile_directory = "/srv/tile.openstreetmap.org/tiles/#{name}"
231 template "/usr/local/bin/update-lowzoom-#{name}" do
232 source "update-lowzoom.erb"
236 variables :style => name
239 template "/etc/init.d/update-lowzoom-#{name}" do
240 source "update-lowzoom.init.erb"
244 variables :style => name
247 service "update-lowzoom-#{name}" do
249 supports :restart => true
252 directory tile_directory do
258 details[:tile_directories].each do |directory|
259 directory directory[:name] do
265 directory[:min_zoom].upto(directory[:max_zoom]) do |zoom|
266 directory "#{directory[:name]}/#{zoom}" do
272 link "#{tile_directory}/#{zoom}" do
273 to "#{directory[:name]}/#{zoom}"
280 file "#{tile_directory}/planet-import-complete" do
281 action :create_if_missing
287 git style_directory do
289 repository details[:repository]
290 revision details[:revision]
295 link "#{style_directory}/data" do
296 to "/srv/tile.openstreetmap.org/data"
301 execute "#{style_directory}/project.mml" do
303 command "carto project.mml > project.xml"
307 subscribes :run, "git[#{style_directory}]"
308 notifies :restart, "service[renderd]", :immediately
309 notifies :restart, "service[update-lowzoom-#{name}]"
315 postgresql_user "jburgess" do
316 cluster node[:tile][:database][:cluster]
320 postgresql_user "tomh" do
321 cluster node[:tile][:database][:cluster]
325 postgresql_user "tile" do
326 cluster node[:tile][:database][:cluster]
329 postgresql_user "www-data" do
330 cluster node[:tile][:database][:cluster]
333 postgresql_database "gis" do
334 cluster node[:tile][:database][:cluster]
338 postgresql_extension "postgis" do
339 cluster node[:tile][:database][:cluster]
343 %w(geography_columns planet_osm_nodes planet_osm_rels planet_osm_ways raster_columns raster_overviews spatial_ref_sys).each do |table|
344 postgresql_table table do
345 cluster node[:tile][:database][:cluster]
348 permissions "tile" => :all
352 %w(geometry_columns planet_osm_line planet_osm_point planet_osm_polygon planet_osm_roads).each do |table|
353 postgresql_table table do
354 cluster node[:tile][:database][:cluster]
357 permissions "tile" => :all, "www-data" => :select
361 postgresql_munin "gis" do
362 cluster node[:tile][:database][:cluster]
366 file node[:tile][:node_file] do
372 directory "/var/log/tile" do
384 if node[:lsb][:release].to_f < 14.04
388 package "libproj-dev"
389 package "libxml2-dev"
391 gem_package "proj4rb"
392 gem_package "libxml-ruby"
394 remote_directory "/usr/local/lib/site_ruby" do
404 template "/usr/local/bin/expire-tiles" do
405 source "expire-tiles.erb"
411 template "/etc/sudoers.d/tile" do
418 directory "/var/lib/replicate" do
424 template "/var/lib/replicate/configuration.txt" do
425 source "replicate.configuration.erb"
431 template "/usr/local/bin/replicate" do
432 source "replicate.erb"
438 template "/etc/init.d/replicate" do
439 source "replicate.init.erb"
445 service "replicate" do
446 action [:enable, :start]
447 supports :restart => true
448 subscribes :restart, "template[/usr/local/bin/replicate]"
449 subscribes :restart, "template[/etc/init.d/replicate]"
452 template "/etc/logrotate.d/replicate" do
453 source "replicate.logrotate.erb"
459 template "/usr/local/bin/render-lowzoom" do
460 source "render-lowzoom.erb"
466 template "/etc/cron.d/render-lowzoom" do
467 source "render-lowzoom.cron.erb"
473 template "/etc/rsyslog.d/20-renderd.conf" do
474 source "renderd.rsyslog.erb"
478 notifies :restart, "service[rsyslog]"
481 template "/etc/logrotate.d/renderd" do
482 source "renderd.logrotate.erb"
488 package "liblockfile-simple-perl"
489 package "libfilesys-df-perl"
491 template "/usr/local/bin/cleanup-tiles" do
492 source "cleanup-tiles.erb"
498 tile_directories = node[:tile][:styles].collect do |_, style|
499 style[:tile_directories].collect { |directory| directory[:name] }
500 end.flatten.sort.uniq
502 template "/etc/cron.d/cleanup-tiles" do
503 source "cleanup-tiles.cron.erb"
507 variables :directories => tile_directories
510 munin_plugin "mod_tile_fresh"
511 munin_plugin "mod_tile_latency"
512 munin_plugin "mod_tile_response"
513 munin_plugin "mod_tile_zoom"
515 munin_plugin "renderd_processed"
516 munin_plugin "renderd_queue"
517 munin_plugin "renderd_queue_time"
518 munin_plugin "renderd_zoom"
519 munin_plugin "renderd_zoom_time"
521 munin_plugin "replication_delay" do