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 node[:tile][:tile_directory] do
75 if node[:tile][:tile_directory] != "/srv/tile.openstreetmap.org/tiles"
76 link "/srv/tile.openstreetmap.org/tiles" do
77 to node[:tile][:tile_directory]
81 template "/etc/renderd.conf" do
82 source "renderd.conf.erb"
86 notifies :reload, resources(:service => "apache2")
87 notifies :restart, resources(:service => "renderd")
90 remote_directory "/srv/tile.openstreetmap.org/html" do
100 template "/srv/tile.openstreetmap.org/html/index.html" do
101 source "index.html.erb"
107 package "python-cairo"
108 package "python-mapnik"
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 "/etc/cron.hourly/export" do
125 source "export.cron.erb"
131 directory "/srv/tile.openstreetmap.org/data" do
137 node[:tile][:data].each do |name,data|
139 file = "/srv/tile.openstreetmap.org/data/#{File.basename(url)}"
140 directory = "/srv/tile.openstreetmap.org/data/#{data[:directory]}"
142 directory directory do
153 command "tar -zxf #{file} -C #{directory}"
157 elsif file =~ /\.tar\.bz2$/
162 command "tar -jxf #{file} -C #{directory}"
166 elsif file =~ /\.zip$/
171 command "unzip -qq #{file} -d #{directory}"
178 original = "#{directory}/#{data[:original]}"
179 processed = "#{directory}/#{data[:processed]}"
185 command "ogr2ogr #{processed} #{original}"
188 subscribes :run, resources(:execute => file), :immediately
192 execute "#{file}_shapeindex" do
194 command "find #{directory} -type f -iname '*.shp' -print0 | xargs -0 --no-run-if-empty shapeindex --shape_files"
197 subscribes :run, resources(:execute => file), :immediately
201 action :create_if_missing
206 notifies :run, resources(:execute => file), :immediately
207 notifies :restart, resources(:service => "renderd")
211 nodejs_package "carto"
212 nodejs_package "millstone"
214 directory "/srv/tile.openstreetmap.org/styles" do
220 node[:tile][:styles].each do |name,details|
221 style_directory = "/srv/tile.openstreetmap.org/styles/#{name}"
222 tile_directory = "/srv/tile.openstreetmap.org/tiles/#{name}"
224 template "/usr/local/bin/update-lowzoom-#{name}" do
225 source "update-lowzoom.erb"
229 variables :style => name
232 template "/etc/init.d/update-lowzoom-#{name}" do
233 source "update-lowzoom.init.erb"
237 variables :style => name
240 service "update-lowzoom-#{name}" do
242 supports :restart => true
245 directory tile_directory do
251 file "#{tile_directory}/planet-import-complete" do
252 action :create_if_missing
258 git style_directory do
260 repository details[:repository]
261 revision details[:revision]
266 link "#{style_directory}/data" do
267 to "/srv/tile.openstreetmap.org/data"
272 execute "#{style_directory}/project.mml" do
274 command "carto project.mml > project.xml"
278 subscribes :run, "git[#{style_directory}]"
279 notifies :restart, "service[renderd]", :immediately
280 notifies :restart, "service[update-lowzoom-#{name}]"
286 postgresql_user "jburgess" do
287 cluster node[:tile][:database][:cluster]
291 postgresql_user "tomh" do
292 cluster node[:tile][:database][:cluster]
296 postgresql_user "tile" do
297 cluster node[:tile][:database][:cluster]
300 postgresql_user "www-data" do
301 cluster node[:tile][:database][:cluster]
304 postgresql_database "gis" do
305 cluster node[:tile][:database][:cluster]
309 postgresql_extension "postgis" do
310 cluster node[:tile][:database][:cluster]
314 [ "geography_columns",
320 "spatial_ref_sys" ].each do |table|
321 postgresql_table table do
322 cluster node[:tile][:database][:cluster]
325 permissions "tile" => :all
329 [ "geometry_columns",
332 "planet_osm_polygon",
333 "planet_osm_roads" ].each do |table|
334 postgresql_table table do
335 cluster node[:tile][:database][:cluster]
338 permissions "tile" => :all, "www-data" => :select
342 postgresql_munin "gis" do
343 cluster node[:tile][:database][:cluster]
347 #file node[:tile][:node_file] do
353 directory "/var/log/tile" do
365 package "libproj-dev"
366 package "libxml2-dev"
368 gem_package "proj4rb"
369 gem_package "libxml-ruby"
372 remote_directory "/usr/local/lib/site_ruby" do
382 template "/usr/local/bin/expire-tiles" do
383 source "expire-tiles.erb"
389 template "/etc/sudoers.d/tile" do
396 directory "/var/lib/replicate" do
402 template "/var/lib/replicate/configuration.txt" do
403 source "replicate.configuration.erb"
409 template "/usr/local/bin/replicate" do
410 source "replicate.erb"
416 template "/etc/init.d/replicate" do
417 source "replicate.init.erb"
423 service "replicate" do
424 action [ :enable, :start ]
425 supports :restart => true
426 subscribes :restart, resources(:template => "/usr/local/bin/replicate")
427 subscribes :restart, resources(:template => "/etc/init.d/replicate")
430 template "/etc/logrotate.d/replicate" do
431 source "replicate.logrotate.erb"
437 template "/usr/local/bin/render-lowzoom" do
438 source "render-lowzoom.erb"
444 template "/etc/cron.d/render-lowzoom" do
445 source "render-lowzoom.cron.erb"
451 template "/etc/rsyslog.d/20-renderd.conf" do
452 source "renderd.rsyslog.erb"
456 notifies :restart, "service[rsyslog]"
459 munin_plugin "mod_tile_fresh"
460 munin_plugin "mod_tile_response"
461 munin_plugin "mod_tile_zoom"
462 munin_plugin "mod_tile_latency"
464 munin_plugin "renderd_processed"
465 munin_plugin "renderd_queue"
466 munin_plugin "renderd_zoom"
467 munin_plugin "renderd_zoom_time"
469 munin_plugin "replication_delay" do