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"
104 package "ttf-unifont"
105 package "fonts-droid"
106 package "fonts-sipa-arundina"
107 package "fonts-sil-padauk"
108 package "fonts-khmeros"
110 directory "/srv/tile.openstreetmap.org/cgi-bin" do
116 template "/srv/tile.openstreetmap.org/cgi-bin/export" do
121 variables :blocks => blocks
124 template "/srv/tile.openstreetmap.org/cgi-bin/debug" do
131 template "/etc/cron.hourly/export" do
132 source "export.cron.erb"
138 directory "/srv/tile.openstreetmap.org/data" do
144 node[:tile][:data].each do |name,data|
146 file = "/srv/tile.openstreetmap.org/data/#{File.basename(url)}"
147 directory = "/srv/tile.openstreetmap.org/data/#{data[:directory]}"
149 directory directory do
160 command "tar -zxf #{file} -C #{directory}"
164 elsif file =~ /\.tar\.bz2$/
169 command "tar -jxf #{file} -C #{directory}"
173 elsif file =~ /\.zip$/
178 command "unzip -qq -o #{file} -d #{directory}"
185 original = "#{directory}/#{data[:original]}"
186 processed = "#{directory}/#{data[:processed]}"
192 command "ogr2ogr #{processed} #{original}"
195 subscribes :run, "execute[#{file}]", :immediately
199 execute "#{file}_shapeindex" do
201 command "find #{directory} -type f -iname '*.shp' -print0 | xargs -0 --no-run-if-empty shapeindex --shape_files"
204 subscribes :run, "execute[#{file}]", :immediately
210 use_conditional_get true
212 action :create_if_missing
220 notifies :run, "execute[#{file}]", :immediately
221 notifies :restart, "service[renderd]"
225 nodejs_package "carto"
226 nodejs_package "millstone"
228 directory "/srv/tile.openstreetmap.org/styles" do
234 node[:tile][:styles].each do |name,details|
235 style_directory = "/srv/tile.openstreetmap.org/styles/#{name}"
236 tile_directory = "/srv/tile.openstreetmap.org/tiles/#{name}"
238 template "/usr/local/bin/update-lowzoom-#{name}" do
239 source "update-lowzoom.erb"
243 variables :style => name
246 template "/etc/init.d/update-lowzoom-#{name}" do
247 source "update-lowzoom.init.erb"
251 variables :style => name
254 service "update-lowzoom-#{name}" do
256 supports :restart => true
259 directory tile_directory do
265 details[:tile_directories].each do |directory|
266 directory directory[:name] do
272 directory[:min_zoom].upto(directory[:max_zoom]) do |zoom|
273 directory "#{directory[:name]}/#{zoom}" do
279 link "#{tile_directory}/#{zoom}" do
280 to "#{directory[:name]}/#{zoom}"
287 file "#{tile_directory}/planet-import-complete" do
288 action :create_if_missing
294 git style_directory do
296 repository details[:repository]
297 revision details[:revision]
302 link "#{style_directory}/data" do
303 to "/srv/tile.openstreetmap.org/data"
308 execute "#{style_directory}/project.mml" do
310 command "carto project.mml > project.xml"
314 subscribes :run, "git[#{style_directory}]"
315 notifies :restart, "service[renderd]", :immediately
316 notifies :restart, "service[update-lowzoom-#{name}]"
322 postgresql_user "jburgess" do
323 cluster node[:tile][:database][:cluster]
327 postgresql_user "tomh" do
328 cluster node[:tile][:database][:cluster]
332 postgresql_user "tile" do
333 cluster node[:tile][:database][:cluster]
336 postgresql_user "www-data" do
337 cluster node[:tile][:database][:cluster]
340 postgresql_database "gis" do
341 cluster node[:tile][:database][:cluster]
345 postgresql_extension "postgis" do
346 cluster node[:tile][:database][:cluster]
350 [ "geography_columns",
356 "spatial_ref_sys" ].each do |table|
357 postgresql_table table do
358 cluster node[:tile][:database][:cluster]
361 permissions "tile" => :all
365 [ "geometry_columns",
368 "planet_osm_polygon",
369 "planet_osm_roads" ].each do |table|
370 postgresql_table table do
371 cluster node[:tile][:database][:cluster]
374 permissions "tile" => :all, "www-data" => :select
378 postgresql_munin "gis" do
379 cluster node[:tile][:database][:cluster]
383 file node[:tile][:node_file] do
389 directory "/var/log/tile" do
401 package "libproj-dev"
402 package "libxml2-dev"
404 gem_package "proj4rb"
405 gem_package "libxml-ruby"
408 remote_directory "/usr/local/lib/site_ruby" do
418 template "/usr/local/bin/expire-tiles" do
419 source "expire-tiles.erb"
425 template "/etc/sudoers.d/tile" do
432 directory "/var/lib/replicate" do
438 template "/var/lib/replicate/configuration.txt" do
439 source "replicate.configuration.erb"
445 template "/usr/local/bin/replicate" do
446 source "replicate.erb"
452 template "/etc/init.d/replicate" do
453 source "replicate.init.erb"
459 service "replicate" do
460 action [ :enable, :start ]
461 supports :restart => true
462 subscribes :restart, "template[/usr/local/bin/replicate]"
463 subscribes :restart, "template[/etc/init.d/replicate]"
466 template "/etc/logrotate.d/replicate" do
467 source "replicate.logrotate.erb"
473 template "/usr/local/bin/render-lowzoom" do
474 source "render-lowzoom.erb"
480 template "/etc/cron.d/render-lowzoom" do
481 source "render-lowzoom.cron.erb"
487 template "/etc/rsyslog.d/20-renderd.conf" do
488 source "renderd.rsyslog.erb"
492 notifies :restart, "service[rsyslog]"
495 package "liblockfile-simple-perl"
496 package "libfilesys-df-perl"
498 template "/usr/local/bin/cleanup-tiles" do
499 source "cleanup-tiles.erb"
505 tile_directories = node[:tile][:styles].collect do |name,style|
506 style[:tile_directories].collect { |directory| directory[:name] }
507 end.flatten.sort.uniq
509 template "/etc/cron.d/cleanup-tiles" do
510 source "cleanup-tiles.cron.erb"
514 variables :directories => tile_directories
517 munin_plugin "mod_tile_fresh"
518 munin_plugin "mod_tile_latency"
519 munin_plugin "mod_tile_response"
520 munin_plugin "mod_tile_zoom"
522 munin_plugin "renderd_processed"
523 munin_plugin "renderd_queue"
524 munin_plugin "renderd_queue_time"
525 munin_plugin "renderd_zoom"
526 munin_plugin "renderd_zoom_time"
528 munin_plugin "replication_delay" do