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 package "python-cairo"
101 package "python-mapnik"
103 directory "/srv/tile.openstreetmap.org/cgi-bin" do
109 template "/srv/tile.openstreetmap.org/cgi-bin/export" do
114 variables :blocks => blocks
117 directory "/srv/tile.openstreetmap.org/data" do
123 node[:tile][:data].each do |name,data|
125 file = "/srv/tile.openstreetmap.org/data/#{File.basename(url)}"
126 directory = "/srv/tile.openstreetmap.org/data/#{data[:directory]}"
128 directory directory do
139 command "tar -zxf #{file} -C #{directory}"
143 elsif file =~ /\.tar\.bz2$/
148 command "tar -jxf #{file} -C #{directory}"
152 elsif file =~ /\.zip$/
157 command "unzip -qq #{file} -d #{directory}"
164 original = "#{directory}/#{data[:original]}"
165 processed = "#{directory}/#{data[:processed]}"
171 command "ogr2ogr #{processed} #{original}"
174 subscribes :run, resources(:execute => file), :immediately
178 execute "#{file}_shapeindex" do
180 command "find #{directory} -type f -iname '*.shp' -print0 | xargs -0 --no-run-if-empty shapeindex --shape_files"
183 subscribes :run, resources(:execute => file), :immediately
187 action :create_if_missing
192 notifies :run, resources(:execute => file), :immediately
193 notifies :restart, resources(:service => "renderd")
197 nodejs_package "carto"
198 nodejs_package "millstone"
200 directory "/srv/tile.openstreetmap.org/styles" do
206 node[:tile][:styles].each do |name,details|
207 style_directory = "/srv/tile.openstreetmap.org/styles/#{name}"
208 tile_directory = "/srv/tile.openstreetmap.org/tiles/#{name}"
210 template "/usr/local/bin/update-lowzoom-#{name}" do
211 source "update-lowzoom.erb"
215 variables :style => name
218 template "/etc/init.d/update-lowzoom-#{name}" do
219 source "update-lowzoom.init.erb"
223 variables :style => name
226 service "update-lowzoom-#{name}" do
228 supports :restart => true
231 directory tile_directory do
237 file "#{tile_directory}/planet-import-complete" do
238 action :create_if_missing
244 git style_directory do
246 repository details[:repository]
247 revision details[:revision]
252 link "#{style_directory}/data" do
253 to "/srv/tile.openstreetmap.org/data"
258 execute "#{style_directory}/project.mml" do
260 command "carto project.mml > project.xml"
264 subscribes :run, "git[#{style_directory}]"
265 notifies :restart, "service[renderd]", :immediately
266 notifies :restart, "service[update-lowzoom-#{name}]"
272 postgresql_user "jburgess" do
273 cluster node[:tile][:database][:cluster]
277 postgresql_user "tomh" do
278 cluster node[:tile][:database][:cluster]
282 postgresql_user "tile" do
283 cluster node[:tile][:database][:cluster]
286 postgresql_user "www-data" do
287 cluster node[:tile][:database][:cluster]
290 postgresql_database "gis" do
291 cluster node[:tile][:database][:cluster]
295 postgresql_extension "postgis" do
296 cluster node[:tile][:database][:cluster]
300 [ "geography_columns",
306 "spatial_ref_sys" ].each do |table|
307 postgresql_table table do
308 cluster node[:tile][:database][:cluster]
311 permissions "tile" => :all
315 [ "geometry_columns",
318 "planet_osm_polygon",
319 "planet_osm_roads" ].each do |table|
320 postgresql_table table do
321 cluster node[:tile][:database][:cluster]
324 permissions "tile" => :all, "www-data" => :select
328 postgresql_munin "gis" do
329 cluster node[:tile][:database][:cluster]
333 #file node[:tile][:node_file] do
339 directory "/var/log/tile" do
351 package "libproj-dev"
352 package "libxml2-dev"
354 gem_package "proj4rb"
355 gem_package "libxml-ruby"
358 remote_directory "/usr/local/lib/site_ruby" do
368 template "/usr/local/bin/expire-tiles" do
369 source "expire-tiles.erb"
375 template "/etc/sudoers.d/tile" do
382 directory "/var/lib/replicate" do
388 template "/var/lib/replicate/configuration.txt" do
389 source "replicate.configuration.erb"
395 template "/usr/local/bin/replicate" do
396 source "replicate.erb"
402 template "/etc/init.d/replicate" do
403 source "replicate.init.erb"
409 service "replicate" do
410 action [ :enable, :start ]
411 supports :restart => true
412 subscribes :restart, resources(:template => "/usr/local/bin/replicate")
413 subscribes :restart, resources(:template => "/etc/init.d/replicate")
416 template "/etc/logrotate.d/replicate" do
417 source "replicate.logrotate.erb"
423 template "/usr/local/bin/render-lowzoom" do
424 source "render-lowzoom.erb"
430 template "/etc/cron.d/render-lowzoom" do
431 source "render-lowzoom.cron.erb"
437 template "/etc/rsyslog.d/20-renderd.conf" do
438 source "renderd.rsyslog.erb"
442 notifies :restart, "service[rsyslog]"
445 munin_plugin "mod_tile_fresh"
446 munin_plugin "mod_tile_response"
447 munin_plugin "mod_tile_zoom"
448 munin_plugin "mod_tile_latency"
450 munin_plugin "renderd_processed"
451 munin_plugin "renderd_queue"
452 munin_plugin "renderd_zoom"
453 munin_plugin "renderd_zoom_time"
455 munin_plugin "replication_delay" do