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 node[:tile][:data].each_value do |data|
150 file = "/srv/tile.openstreetmap.org/data/#{File.basename(url)}"
151 directory = "/srv/tile.openstreetmap.org/data/#{data[:directory]}"
153 directory directory do
164 command "tar -zxf #{file} -C #{directory}"
168 elsif file =~ /\.tar\.bz2$/
173 command "tar -jxf #{file} -C #{directory}"
177 elsif file =~ /\.zip$/
182 command "unzip -qq -o #{file} -d #{directory}"
189 original = "#{directory}/#{data[:original]}"
190 processed = "#{directory}/#{data[:processed]}"
196 command "ogr2ogr #{processed} #{original}"
199 subscribes :run, "execute[#{file}]", :immediately
203 execute "#{file}_shapeindex" do
205 command "find #{directory} -type f -iname '*.shp' -print0 | xargs -0 --no-run-if-empty shapeindex --shape_files"
208 subscribes :run, "execute[#{file}]", :immediately
214 use_conditional_get true
216 action :create_if_missing
224 notifies :run, "execute[#{file}]", :immediately
225 notifies :restart, "service[renderd]"
229 nodejs_package "carto"
230 nodejs_package "millstone"
232 directory "/srv/tile.openstreetmap.org/styles" do
238 node[:tile][:styles].each do |name, details|
239 style_directory = "/srv/tile.openstreetmap.org/styles/#{name}"
240 tile_directory = "/srv/tile.openstreetmap.org/tiles/#{name}"
242 template "/usr/local/bin/update-lowzoom-#{name}" do
243 source "update-lowzoom.erb"
247 variables :style => name
250 template "/etc/init.d/update-lowzoom-#{name}" do
251 source "update-lowzoom.init.erb"
255 variables :style => name
258 service "update-lowzoom-#{name}" do
260 supports :restart => true
263 directory tile_directory do
269 details[:tile_directories].each do |directory|
270 directory directory[:name] do
276 directory[:min_zoom].upto(directory[:max_zoom]) do |zoom|
277 directory "#{directory[:name]}/#{zoom}" do
283 link "#{tile_directory}/#{zoom}" do
284 to "#{directory[:name]}/#{zoom}"
291 file "#{tile_directory}/planet-import-complete" do
292 action :create_if_missing
298 git style_directory do
300 repository details[:repository]
301 revision details[:revision]
306 link "#{style_directory}/data" do
307 to "/srv/tile.openstreetmap.org/data"
312 execute "#{style_directory}/project.mml" do
314 command "carto project.mml > project.xml"
318 subscribes :run, "git[#{style_directory}]"
319 notifies :restart, "service[renderd]", :immediately
320 notifies :restart, "service[update-lowzoom-#{name}]"
326 postgresql_user "jburgess" do
327 cluster node[:tile][:database][:cluster]
331 postgresql_user "tomh" do
332 cluster node[:tile][:database][:cluster]
336 postgresql_user "tile" do
337 cluster node[:tile][:database][:cluster]
340 postgresql_user "www-data" do
341 cluster node[:tile][:database][:cluster]
344 postgresql_database "gis" do
345 cluster node[:tile][:database][:cluster]
349 postgresql_extension "postgis" do
350 cluster node[:tile][:database][:cluster]
354 %w(geography_columns planet_osm_nodes planet_osm_rels planet_osm_ways raster_columns raster_overviews spatial_ref_sys).each do |table|
355 postgresql_table table do
356 cluster node[:tile][:database][:cluster]
359 permissions "tile" => :all
363 %w(geometry_columns planet_osm_line planet_osm_point planet_osm_polygon planet_osm_roads).each do |table|
364 postgresql_table table do
365 cluster node[:tile][:database][:cluster]
368 permissions "tile" => :all, "www-data" => :select
372 postgresql_munin "gis" do
373 cluster node[:tile][:database][:cluster]
377 file node[:tile][:node_file] do
383 directory "/var/log/tile" do
395 package "libproj-dev"
396 package "libxml2-dev"
398 gem_package "proj4rb"
399 gem_package "libxml-ruby"
402 remote_directory "/usr/local/lib/site_ruby" do
412 template "/usr/local/bin/expire-tiles" do
413 source "expire-tiles.erb"
419 template "/etc/sudoers.d/tile" do
426 directory "/var/lib/replicate" do
432 template "/var/lib/replicate/configuration.txt" do
433 source "replicate.configuration.erb"
439 template "/usr/local/bin/replicate" do
440 source "replicate.erb"
446 template "/etc/init.d/replicate" do
447 source "replicate.init.erb"
453 service "replicate" do
454 action [:enable, :start]
455 supports :restart => true
456 subscribes :restart, "template[/usr/local/bin/replicate]"
457 subscribes :restart, "template[/etc/init.d/replicate]"
460 template "/etc/logrotate.d/replicate" do
461 source "replicate.logrotate.erb"
467 template "/usr/local/bin/render-lowzoom" do
468 source "render-lowzoom.erb"
474 template "/etc/cron.d/render-lowzoom" do
475 source "render-lowzoom.cron.erb"
481 template "/etc/rsyslog.d/20-renderd.conf" do
482 source "renderd.rsyslog.erb"
486 notifies :restart, "service[rsyslog]"
489 template "/etc/logrotate.d/renderd" do
490 source "renderd.logrotate.erb"
496 package "liblockfile-simple-perl"
497 package "libfilesys-df-perl"
499 template "/usr/local/bin/cleanup-tiles" do
500 source "cleanup-tiles.erb"
506 tile_directories = node[:tile][:styles].collect do |_, style|
507 style[:tile_directories].collect { |directory| directory[:name] }
508 end.flatten.sort.uniq
510 template "/etc/cron.d/cleanup-tiles" do
511 source "cleanup-tiles.cron.erb"
515 variables :directories => tile_directories
518 munin_plugin "mod_tile_fresh"
519 munin_plugin "mod_tile_latency"
520 munin_plugin "mod_tile_response"
521 munin_plugin "mod_tile_zoom"
523 munin_plugin "renderd_processed"
524 munin_plugin "renderd_queue"
525 munin_plugin "renderd_queue_time"
526 munin_plugin "renderd_zoom"
527 munin_plugin "renderd_zoom_time"
529 munin_plugin "replication_delay" do