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
202 action :create_if_missing
207 notifies :run, resources(:execute => file), :immediately
208 notifies :restart, resources(:service => "renderd")
212 nodejs_package "carto"
213 nodejs_package "millstone"
215 directory "/srv/tile.openstreetmap.org/styles" do
221 node[:tile][:styles].each do |name,details|
222 style_directory = "/srv/tile.openstreetmap.org/styles/#{name}"
223 tile_directory = "/srv/tile.openstreetmap.org/tiles/#{name}"
225 template "/usr/local/bin/update-lowzoom-#{name}" do
226 source "update-lowzoom.erb"
230 variables :style => name
233 template "/etc/init.d/update-lowzoom-#{name}" do
234 source "update-lowzoom.init.erb"
238 variables :style => name
241 service "update-lowzoom-#{name}" do
243 supports :restart => true
246 directory tile_directory do
252 details[:tile_directories].each do |directory|
253 directory[:min_zoom].upto(directory[:max_zoom]) do |zoom|
254 directory "#{directory[:name]}/#{zoom}" do
260 link "#{tile_directory}/#{zoom}" do
261 to "#{directory[:name]}/#{zoom}"
268 file "#{tile_directory}/planet-import-complete" do
269 action :create_if_missing
275 git style_directory do
277 repository details[:repository]
278 revision details[:revision]
283 link "#{style_directory}/data" do
284 to "/srv/tile.openstreetmap.org/data"
289 execute "#{style_directory}/project.mml" do
291 command "carto project.mml > project.xml"
295 subscribes :run, "git[#{style_directory}]"
296 notifies :restart, "service[renderd]", :immediately
297 notifies :restart, "service[update-lowzoom-#{name}]"
303 postgresql_user "jburgess" do
304 cluster node[:tile][:database][:cluster]
308 postgresql_user "tomh" do
309 cluster node[:tile][:database][:cluster]
313 postgresql_user "tile" do
314 cluster node[:tile][:database][:cluster]
317 postgresql_user "www-data" do
318 cluster node[:tile][:database][:cluster]
321 postgresql_database "gis" do
322 cluster node[:tile][:database][:cluster]
326 postgresql_extension "postgis" do
327 cluster node[:tile][:database][:cluster]
331 [ "geography_columns",
337 "spatial_ref_sys" ].each do |table|
338 postgresql_table table do
339 cluster node[:tile][:database][:cluster]
342 permissions "tile" => :all
346 [ "geometry_columns",
349 "planet_osm_polygon",
350 "planet_osm_roads" ].each do |table|
351 postgresql_table table do
352 cluster node[:tile][:database][:cluster]
355 permissions "tile" => :all, "www-data" => :select
359 postgresql_munin "gis" do
360 cluster node[:tile][:database][:cluster]
364 #file node[:tile][:node_file] do
370 directory "/var/log/tile" do
382 package "libproj-dev"
383 package "libxml2-dev"
385 gem_package "proj4rb"
386 gem_package "libxml-ruby"
389 remote_directory "/usr/local/lib/site_ruby" do
399 template "/usr/local/bin/expire-tiles" do
400 source "expire-tiles.erb"
406 template "/etc/sudoers.d/tile" do
413 directory "/var/lib/replicate" do
419 template "/var/lib/replicate/configuration.txt" do
420 source "replicate.configuration.erb"
426 template "/usr/local/bin/replicate" do
427 source "replicate.erb"
433 template "/etc/init.d/replicate" do
434 source "replicate.init.erb"
440 service "replicate" do
441 action [ :enable, :start ]
442 supports :restart => true
443 subscribes :restart, resources(:template => "/usr/local/bin/replicate")
444 subscribes :restart, resources(:template => "/etc/init.d/replicate")
447 template "/etc/logrotate.d/replicate" do
448 source "replicate.logrotate.erb"
454 template "/usr/local/bin/render-lowzoom" do
455 source "render-lowzoom.erb"
461 template "/etc/cron.d/render-lowzoom" do
462 source "render-lowzoom.cron.erb"
468 template "/etc/rsyslog.d/20-renderd.conf" do
469 source "renderd.rsyslog.erb"
473 notifies :restart, "service[rsyslog]"
476 package "libfilesys-df-perl"
478 template "/usr/local/bin/cleanup-tiles" do
479 source "cleanup-tiles.erb"
485 tile_directories = node[:tile][:styles].collect do |name,style|
486 style[:tile_directories].collect { |directory| directory[:name] }
487 end.flatten.sort.uniq
489 template "/etc/cron.d/cleanup-tiles" do
490 source "cleanup-tiles.cron.erb"
494 variables :directories => tile_directories
497 munin_plugin "mod_tile_fresh"
498 munin_plugin "mod_tile_response"
499 munin_plugin "mod_tile_zoom"
500 munin_plugin "mod_tile_latency"
502 munin_plugin "renderd_processed"
503 munin_plugin "renderd_queue"
504 munin_plugin "renderd_zoom"
505 munin_plugin "renderd_zoom_time"
507 munin_plugin "replication_delay" do