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 "/etc/cron.hourly/export" do
119 source "export.cron.erb"
125 directory "/srv/tile.openstreetmap.org/data" do
131 node[:tile][:data].each do |name,data|
133 file = "/srv/tile.openstreetmap.org/data/#{File.basename(url)}"
134 directory = "/srv/tile.openstreetmap.org/data/#{data[:directory]}"
136 directory directory do
147 command "tar -zxf #{file} -C #{directory}"
151 elsif file =~ /\.tar\.bz2$/
156 command "tar -jxf #{file} -C #{directory}"
160 elsif file =~ /\.zip$/
165 command "unzip -qq #{file} -d #{directory}"
172 original = "#{directory}/#{data[:original]}"
173 processed = "#{directory}/#{data[:processed]}"
179 command "ogr2ogr #{processed} #{original}"
182 subscribes :run, resources(:execute => file), :immediately
186 execute "#{file}_shapeindex" do
188 command "find #{directory} -type f -iname '*.shp' -print0 | xargs -0 --no-run-if-empty shapeindex --shape_files"
191 subscribes :run, resources(:execute => file), :immediately
195 action :create_if_missing
200 notifies :run, resources(:execute => file), :immediately
201 notifies :restart, resources(:service => "renderd")
205 nodejs_package "carto"
206 nodejs_package "millstone"
208 directory "/srv/tile.openstreetmap.org/styles" do
214 node[:tile][:styles].each do |name,details|
215 style_directory = "/srv/tile.openstreetmap.org/styles/#{name}"
216 tile_directory = "/srv/tile.openstreetmap.org/tiles/#{name}"
218 template "/usr/local/bin/update-lowzoom-#{name}" do
219 source "update-lowzoom.erb"
223 variables :style => name
226 template "/etc/init.d/update-lowzoom-#{name}" do
227 source "update-lowzoom.init.erb"
231 variables :style => name
234 service "update-lowzoom-#{name}" do
236 supports :restart => true
239 directory tile_directory do
245 details[:tile_directories].each do |directory|
246 directory[:min_zoom].upto(directory[:max_zoom]) do |zoom|
247 directory "#{directory[:name]}/#{zoom}" do
253 link "#{tile_directory}/#{zoom}" do
254 to "#{directory[:name]}/#{zoom}"
261 file "#{tile_directory}/planet-import-complete" do
262 action :create_if_missing
268 git style_directory do
270 repository details[:repository]
271 revision details[:revision]
276 link "#{style_directory}/data" do
277 to "/srv/tile.openstreetmap.org/data"
282 execute "#{style_directory}/project.mml" do
284 command "carto project.mml > project.xml"
288 subscribes :run, "git[#{style_directory}]"
289 notifies :restart, "service[renderd]", :immediately
290 notifies :restart, "service[update-lowzoom-#{name}]"
296 postgresql_user "jburgess" do
297 cluster node[:tile][:database][:cluster]
301 postgresql_user "tomh" do
302 cluster node[:tile][:database][:cluster]
306 postgresql_user "tile" do
307 cluster node[:tile][:database][:cluster]
310 postgresql_user "www-data" do
311 cluster node[:tile][:database][:cluster]
314 postgresql_database "gis" do
315 cluster node[:tile][:database][:cluster]
319 postgresql_extension "postgis" do
320 cluster node[:tile][:database][:cluster]
324 [ "geography_columns",
330 "spatial_ref_sys" ].each do |table|
331 postgresql_table table do
332 cluster node[:tile][:database][:cluster]
335 permissions "tile" => :all
339 [ "geometry_columns",
342 "planet_osm_polygon",
343 "planet_osm_roads" ].each do |table|
344 postgresql_table table do
345 cluster node[:tile][:database][:cluster]
348 permissions "tile" => :all, "www-data" => :select
352 postgresql_munin "gis" do
353 cluster node[:tile][:database][:cluster]
357 #file node[:tile][:node_file] do
363 directory "/var/log/tile" do
375 package "libproj-dev"
376 package "libxml2-dev"
378 gem_package "proj4rb"
379 gem_package "libxml-ruby"
382 remote_directory "/usr/local/lib/site_ruby" do
392 template "/usr/local/bin/expire-tiles" do
393 source "expire-tiles.erb"
399 template "/etc/sudoers.d/tile" do
406 directory "/var/lib/replicate" do
412 template "/var/lib/replicate/configuration.txt" do
413 source "replicate.configuration.erb"
419 template "/usr/local/bin/replicate" do
420 source "replicate.erb"
426 template "/etc/init.d/replicate" do
427 source "replicate.init.erb"
433 service "replicate" do
434 action [ :enable, :start ]
435 supports :restart => true
436 subscribes :restart, resources(:template => "/usr/local/bin/replicate")
437 subscribes :restart, resources(:template => "/etc/init.d/replicate")
440 template "/etc/logrotate.d/replicate" do
441 source "replicate.logrotate.erb"
447 template "/usr/local/bin/render-lowzoom" do
448 source "render-lowzoom.erb"
454 template "/etc/cron.d/render-lowzoom" do
455 source "render-lowzoom.cron.erb"
461 template "/etc/rsyslog.d/20-renderd.conf" do
462 source "renderd.rsyslog.erb"
466 notifies :restart, "service[rsyslog]"
469 munin_plugin "mod_tile_fresh"
470 munin_plugin "mod_tile_response"
471 munin_plugin "mod_tile_zoom"
472 munin_plugin "mod_tile_latency"
474 munin_plugin "renderd_processed"
475 munin_plugin "renderd_queue"
476 munin_plugin "renderd_zoom"
477 munin_plugin "renderd_zoom_time"
479 munin_plugin "replication_delay" do