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, resources(:service => "apache2")
81 notifies :restart, resources(: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"
104 directory "/srv/tile.openstreetmap.org/cgi-bin" do
110 template "/srv/tile.openstreetmap.org/cgi-bin/export" do
115 variables :blocks => blocks
118 template "/srv/tile.openstreetmap.org/cgi-bin/debug" do
125 template "/etc/cron.hourly/export" do
126 source "export.cron.erb"
132 directory "/srv/tile.openstreetmap.org/data" do
138 node[:tile][:data].each do |name,data|
140 file = "/srv/tile.openstreetmap.org/data/#{File.basename(url)}"
141 directory = "/srv/tile.openstreetmap.org/data/#{data[:directory]}"
143 directory directory do
154 command "tar -zxf #{file} -C #{directory}"
158 elsif file =~ /\.tar\.bz2$/
163 command "tar -jxf #{file} -C #{directory}"
167 elsif file =~ /\.zip$/
172 command "unzip -qq #{file} -d #{directory}"
179 original = "#{directory}/#{data[:original]}"
180 processed = "#{directory}/#{data[:processed]}"
186 command "ogr2ogr #{processed} #{original}"
189 subscribes :run, resources(:execute => file), :immediately
193 execute "#{file}_shapeindex" do
195 command "find #{directory} -type f -iname '*.shp' -print0 | xargs -0 --no-run-if-empty shapeindex --shape_files"
198 subscribes :run, resources(:execute => file), :immediately
204 use_conditional_get true
206 action :create_if_missing
213 notifies :run, resources(:execute => file), :immediately
214 notifies :restart, resources(: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[:min_zoom].upto(directory[:max_zoom]) do |zoom|
260 directory "#{directory[:name]}/#{zoom}" do
266 link "#{tile_directory}/#{zoom}" do
267 to "#{directory[:name]}/#{zoom}"
274 file "#{tile_directory}/planet-import-complete" do
275 action :create_if_missing
281 git style_directory do
283 repository details[:repository]
284 revision details[:revision]
289 link "#{style_directory}/data" do
290 to "/srv/tile.openstreetmap.org/data"
295 execute "#{style_directory}/project.mml" do
297 command "carto project.mml > project.xml"
301 subscribes :run, "git[#{style_directory}]"
302 notifies :restart, "service[renderd]", :immediately
303 notifies :restart, "service[update-lowzoom-#{name}]"
309 postgresql_user "jburgess" do
310 cluster node[:tile][:database][:cluster]
314 postgresql_user "tomh" do
315 cluster node[:tile][:database][:cluster]
319 postgresql_user "tile" do
320 cluster node[:tile][:database][:cluster]
323 postgresql_user "www-data" do
324 cluster node[:tile][:database][:cluster]
327 postgresql_database "gis" do
328 cluster node[:tile][:database][:cluster]
332 postgresql_extension "postgis" do
333 cluster node[:tile][:database][:cluster]
337 [ "geography_columns",
343 "spatial_ref_sys" ].each do |table|
344 postgresql_table table do
345 cluster node[:tile][:database][:cluster]
348 permissions "tile" => :all
352 [ "geometry_columns",
355 "planet_osm_polygon",
356 "planet_osm_roads" ].each do |table|
357 postgresql_table table do
358 cluster node[:tile][:database][:cluster]
361 permissions "tile" => :all, "www-data" => :select
365 postgresql_munin "gis" do
366 cluster node[:tile][:database][:cluster]
370 #file node[:tile][:node_file] do
376 directory "/var/log/tile" do
388 package "libproj-dev"
389 package "libxml2-dev"
391 gem_package "proj4rb"
392 gem_package "libxml-ruby"
395 remote_directory "/usr/local/lib/site_ruby" do
405 template "/usr/local/bin/expire-tiles" do
406 source "expire-tiles.erb"
412 template "/etc/sudoers.d/tile" do
419 directory "/var/lib/replicate" do
425 template "/var/lib/replicate/configuration.txt" do
426 source "replicate.configuration.erb"
432 template "/usr/local/bin/replicate" do
433 source "replicate.erb"
439 template "/etc/init.d/replicate" do
440 source "replicate.init.erb"
446 service "replicate" do
447 action [ :enable, :start ]
448 supports :restart => true
449 subscribes :restart, resources(:template => "/usr/local/bin/replicate")
450 subscribes :restart, resources(:template => "/etc/init.d/replicate")
453 template "/etc/logrotate.d/replicate" do
454 source "replicate.logrotate.erb"
460 template "/usr/local/bin/render-lowzoom" do
461 source "render-lowzoom.erb"
467 template "/etc/cron.d/render-lowzoom" do
468 source "render-lowzoom.cron.erb"
474 template "/etc/rsyslog.d/20-renderd.conf" do
475 source "renderd.rsyslog.erb"
479 notifies :restart, "service[rsyslog]"
482 package "libfilesys-df-perl"
484 template "/usr/local/bin/cleanup-tiles" do
485 source "cleanup-tiles.erb"
491 tile_directories = node[:tile][:styles].collect do |name,style|
492 style[:tile_directories].collect { |directory| directory[:name] }
493 end.flatten.sort.uniq
495 template "/etc/cron.d/cleanup-tiles" do
496 source "cleanup-tiles.cron.erb"
500 variables :directories => tile_directories
503 munin_plugin "mod_tile_fresh"
504 munin_plugin "mod_tile_response"
505 munin_plugin "mod_tile_zoom"
506 munin_plugin "mod_tile_latency"
508 munin_plugin "renderd_processed"
509 munin_plugin "renderd_queue"
510 munin_plugin "renderd_zoom"
511 munin_plugin "renderd_zoom_time"
513 munin_plugin "replication_delay" do