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
65 systemd_service "renderd" do
66 description "Mapnik rendering daemon"
67 after "postgresql.service"
68 wants "postgresql.service"
70 exec_start "/usr/bin/renderd -f"
81 action [:enable, :start]
84 directory "/srv/tile.openstreetmap.org/tiles" do
90 template "/etc/renderd.conf" do
91 source "renderd.conf.erb"
95 notifies :reload, "service[apache2]"
96 notifies :restart, "service[renderd]"
99 remote_directory "/srv/tile.openstreetmap.org/html" do
109 template "/srv/tile.openstreetmap.org/html/index.html" do
110 source "index.html.erb"
116 package "python-cairo"
117 package "python-mapnik"
120 package "ttf-unifont"
121 package "fonts-droid-fallback"
122 package "fonts-sipa-arundina"
123 package "fonts-sil-padauk"
124 package "fonts-khmeros"
125 package "fonts-beng-extra"
126 package "fonts-gargi"
127 package "fonts-taml-tscu"
128 package "fonts-tibetan-machine"
130 directory "/srv/tile.openstreetmap.org/cgi-bin" do
136 template "/srv/tile.openstreetmap.org/cgi-bin/export" do
141 variables :blocks => blocks
144 template "/srv/tile.openstreetmap.org/cgi-bin/debug" do
151 template "/etc/cron.hourly/export" do
152 source "export.cron.erb"
158 directory "/srv/tile.openstreetmap.org/data" do
164 package "mapnik-utils"
166 node[:tile][:data].each_value do |data|
168 file = "/srv/tile.openstreetmap.org/data/#{File.basename(url)}"
171 directory = "/srv/tile.openstreetmap.org/data/#{data[:directory]}"
173 directory directory do
179 directory = "/srv/tile.openstreetmap.org/data"
187 command "tar -zxf #{file} -C #{directory}"
191 elsif file =~ /\.tar\.bz2$/
196 command "tar -jxf #{file} -C #{directory}"
200 elsif file =~ /\.zip$/
205 command "unzip -qq -o #{file} -d #{directory}"
211 execute "#{file}_shapeindex" do
213 command "find #{directory} -type f -iname '*.shp' -print0 | xargs -0 --no-run-if-empty shapeindex --shape_files"
216 subscribes :run, "execute[#{file}]", :immediately
222 use_conditional_get true
225 action :create_if_missing
233 notifies :run, "execute[#{file}]", :immediately
234 notifies :restart, "service[renderd]"
238 nodejs_package "carto"
239 nodejs_package "millstone"
241 directory "/srv/tile.openstreetmap.org/styles" do
247 node[:tile][:styles].each do |name, details|
248 style_directory = "/srv/tile.openstreetmap.org/styles/#{name}"
249 tile_directory = "/srv/tile.openstreetmap.org/tiles/#{name}"
251 template "/usr/local/bin/update-lowzoom-#{name}" do
252 source "update-lowzoom.erb"
256 variables :style => name
259 template "/etc/init.d/update-lowzoom-#{name}" do
260 source "update-lowzoom.init.erb"
264 variables :style => name
267 service "update-lowzoom-#{name}" do
269 supports :restart => true
272 directory tile_directory do
278 details[:tile_directories].each do |directory|
279 directory directory[:name] do
285 directory[:min_zoom].upto(directory[:max_zoom]) do |zoom|
286 directory "#{directory[:name]}/#{zoom}" do
292 link "#{tile_directory}/#{zoom}" do
293 to "#{directory[:name]}/#{zoom}"
300 file "#{tile_directory}/planet-import-complete" do
301 action :create_if_missing
307 git style_directory do
309 repository details[:repository]
310 revision details[:revision]
315 link "#{style_directory}/data" do
316 to "/srv/tile.openstreetmap.org/data"
321 execute "#{style_directory}/project.mml" do
323 command "carto project.mml > project.xml"
327 subscribes :run, "git[#{style_directory}]"
328 notifies :restart, "service[renderd]", :immediately
329 notifies :restart, "service[update-lowzoom-#{name}]"
335 postgresql_user "jburgess" do
336 cluster node[:tile][:database][:cluster]
340 postgresql_user "tomh" do
341 cluster node[:tile][:database][:cluster]
345 postgresql_user "tile" do
346 cluster node[:tile][:database][:cluster]
349 postgresql_user "www-data" do
350 cluster node[:tile][:database][:cluster]
353 postgresql_database "gis" do
354 cluster node[:tile][:database][:cluster]
358 postgresql_extension "postgis" do
359 cluster node[:tile][:database][:cluster]
363 %w(geography_columns planet_osm_nodes planet_osm_rels planet_osm_ways raster_columns raster_overviews spatial_ref_sys).each do |table|
364 postgresql_table table do
365 cluster node[:tile][:database][:cluster]
368 permissions "tile" => :all
372 %w(geometry_columns planet_osm_line planet_osm_point planet_osm_polygon planet_osm_roads).each do |table|
373 postgresql_table table do
374 cluster node[:tile][:database][:cluster]
377 permissions "tile" => :all, "www-data" => :select
381 postgresql_munin "gis" do
382 cluster node[:tile][:database][:cluster]
386 file node[:tile][:node_file] do
392 directory "/var/log/tile" do
404 package "libproj-dev"
405 package "libxml2-dev"
407 gem_package "proj4rb"
408 gem_package "libxml-ruby"
410 remote_directory "/usr/local/lib/site_ruby" do
420 template "/usr/local/bin/expire-tiles" do
421 source "expire-tiles.erb"
427 template "/etc/sudoers.d/tile" do
434 directory "/var/lib/replicate" do
440 template "/var/lib/replicate/configuration.txt" do
441 source "replicate.configuration.erb"
447 template "/usr/local/bin/replicate" do
448 source "replicate.erb"
454 systemd_service "replicate" do
455 description "Rendering database replication service"
456 after "postgresql.service"
457 wants "postgresql.service"
459 exec_start "/usr/local/bin/replicate"
462 protect_system "full"
467 service "replicate" do
468 action [:enable, :start]
469 subscribes :restart, "template[/usr/local/bin/replicate]"
470 subscribes :restart, "systemd_service[replicate]"
473 template "/etc/logrotate.d/replicate" do
474 source "replicate.logrotate.erb"
480 template "/usr/local/bin/render-lowzoom" do
481 source "render-lowzoom.erb"
487 template "/etc/cron.d/render-lowzoom" do
488 source "render-lowzoom.cron.erb"
494 package "liblockfile-simple-perl"
495 package "libfilesys-df-perl"
497 template "/usr/local/bin/cleanup-tiles" do
498 source "cleanup-tiles.erb"
504 tile_directories = node[:tile][:styles].collect do |_, style|
505 style[:tile_directories].collect { |directory| directory[:name] }
506 end.flatten.sort.uniq
508 template "/etc/cron.d/cleanup-tiles" do
509 source "cleanup-tiles.cron.erb"
513 variables :directories => tile_directories
516 munin_plugin "mod_tile_fresh"
517 munin_plugin "mod_tile_latency"
518 munin_plugin "mod_tile_response"
519 munin_plugin "mod_tile_zoom"
521 munin_plugin "renderd_processed"
522 munin_plugin "renderd_queue"
523 munin_plugin "renderd_queue_time"
524 munin_plugin "renderd_zoom"
525 munin_plugin "renderd_zoom_time"
527 munin_plugin "replication_delay" do