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"
106 directory "/srv/tile.openstreetmap.org/cgi-bin" do
112 template "/srv/tile.openstreetmap.org/cgi-bin/export" do
117 variables :blocks => blocks
120 template "/srv/tile.openstreetmap.org/cgi-bin/debug" do
127 template "/etc/cron.hourly/export" do
128 source "export.cron.erb"
134 directory "/srv/tile.openstreetmap.org/data" do
140 node[:tile][:data].each do |name,data|
142 file = "/srv/tile.openstreetmap.org/data/#{File.basename(url)}"
143 directory = "/srv/tile.openstreetmap.org/data/#{data[:directory]}"
145 directory directory do
156 command "tar -zxf #{file} -C #{directory}"
160 elsif file =~ /\.tar\.bz2$/
165 command "tar -jxf #{file} -C #{directory}"
169 elsif file =~ /\.zip$/
174 command "unzip -qq -o #{file} -d #{directory}"
181 original = "#{directory}/#{data[:original]}"
182 processed = "#{directory}/#{data[:processed]}"
188 command "ogr2ogr #{processed} #{original}"
191 subscribes :run, "execute[#{file}]", :immediately
195 execute "#{file}_shapeindex" do
197 command "find #{directory} -type f -iname '*.shp' -print0 | xargs -0 --no-run-if-empty shapeindex --shape_files"
200 subscribes :run, "execute[#{file}]", :immediately
206 use_conditional_get true
208 action :create_if_missing
216 notifies :run, "execute[#{file}]", :immediately
217 notifies :restart, "service[renderd]"
221 nodejs_package "carto"
222 nodejs_package "millstone"
224 directory "/srv/tile.openstreetmap.org/styles" do
230 node[:tile][:styles].each do |name,details|
231 style_directory = "/srv/tile.openstreetmap.org/styles/#{name}"
232 tile_directory = "/srv/tile.openstreetmap.org/tiles/#{name}"
234 template "/usr/local/bin/update-lowzoom-#{name}" do
235 source "update-lowzoom.erb"
239 variables :style => name
242 template "/etc/init.d/update-lowzoom-#{name}" do
243 source "update-lowzoom.init.erb"
247 variables :style => name
250 service "update-lowzoom-#{name}" do
252 supports :restart => true
255 directory tile_directory do
261 details[:tile_directories].each do |directory|
262 directory directory[:name] do
268 directory[:min_zoom].upto(directory[:max_zoom]) do |zoom|
269 directory "#{directory[:name]}/#{zoom}" do
275 link "#{tile_directory}/#{zoom}" do
276 to "#{directory[:name]}/#{zoom}"
283 file "#{tile_directory}/planet-import-complete" do
284 action :create_if_missing
290 git style_directory do
292 repository details[:repository]
293 revision details[:revision]
298 link "#{style_directory}/data" do
299 to "/srv/tile.openstreetmap.org/data"
304 execute "#{style_directory}/project.mml" do
306 command "carto project.mml > project.xml"
310 subscribes :run, "git[#{style_directory}]"
311 notifies :restart, "service[renderd]", :immediately
312 notifies :restart, "service[update-lowzoom-#{name}]"
318 postgresql_user "jburgess" do
319 cluster node[:tile][:database][:cluster]
323 postgresql_user "tomh" do
324 cluster node[:tile][:database][:cluster]
328 postgresql_user "tile" do
329 cluster node[:tile][:database][:cluster]
332 postgresql_user "www-data" do
333 cluster node[:tile][:database][:cluster]
336 postgresql_database "gis" do
337 cluster node[:tile][:database][:cluster]
341 postgresql_extension "postgis" do
342 cluster node[:tile][:database][:cluster]
346 [ "geography_columns",
352 "spatial_ref_sys" ].each do |table|
353 postgresql_table table do
354 cluster node[:tile][:database][:cluster]
357 permissions "tile" => :all
361 [ "geometry_columns",
364 "planet_osm_polygon",
365 "planet_osm_roads" ].each do |table|
366 postgresql_table table do
367 cluster node[:tile][:database][:cluster]
370 permissions "tile" => :all, "www-data" => :select
374 postgresql_munin "gis" do
375 cluster node[:tile][:database][:cluster]
379 tile_uid = node[:etc][:passwd][:"tile"][:uid]
380 www_data_gid = node[:etc][:group][:"www-data"][:gid]
382 ruby_block node[:tile][:node_file] do
384 File.chown(tile_uid, www_data_gid, node[:tile][:node_file])
385 File.chmod(0640, node[:tile][:node_file])
388 stat = File.stat(node[:tile][:node_file])
389 stat.uid == tile_uid && stat.gid == www_data_gid && stat.mode == 0640
393 directory "/var/log/tile" do
405 package "libproj-dev"
406 package "libxml2-dev"
408 gem_package "proj4rb"
409 gem_package "libxml-ruby"
412 remote_directory "/usr/local/lib/site_ruby" do
422 template "/usr/local/bin/expire-tiles" do
423 source "expire-tiles.erb"
429 template "/etc/sudoers.d/tile" do
436 directory "/var/lib/replicate" do
442 template "/var/lib/replicate/configuration.txt" do
443 source "replicate.configuration.erb"
449 template "/usr/local/bin/replicate" do
450 source "replicate.erb"
456 template "/etc/init.d/replicate" do
457 source "replicate.init.erb"
463 service "replicate" do
464 action [ :enable, :start ]
465 supports :restart => true
466 subscribes :restart, "template[/usr/local/bin/replicate]"
467 subscribes :restart, "template[/etc/init.d/replicate]"
470 template "/etc/logrotate.d/replicate" do
471 source "replicate.logrotate.erb"
477 template "/usr/local/bin/render-lowzoom" do
478 source "render-lowzoom.erb"
484 template "/etc/cron.d/render-lowzoom" do
485 source "render-lowzoom.cron.erb"
491 template "/etc/rsyslog.d/20-renderd.conf" do
492 source "renderd.rsyslog.erb"
496 notifies :restart, "service[rsyslog]"
499 package "liblockfile-simple-perl"
500 package "libfilesys-df-perl"
502 template "/usr/local/bin/cleanup-tiles" do
503 source "cleanup-tiles.erb"
509 tile_directories = node[:tile][:styles].collect do |name,style|
510 style[:tile_directories].collect { |directory| directory[:name] }
511 end.flatten.sort.uniq
513 template "/etc/cron.d/cleanup-tiles" do
514 source "cleanup-tiles.cron.erb"
518 variables :directories => tile_directories
521 munin_plugin "mod_tile_fresh"
522 munin_plugin "mod_tile_latency"
523 munin_plugin "mod_tile_response"
524 munin_plugin "mod_tile_zoom"
526 munin_plugin "renderd_processed"
527 munin_plugin "renderd_queue"
528 munin_plugin "renderd_queue_time"
529 munin_plugin "renderd_zoom"
530 munin_plugin "renderd_zoom_time"
532 munin_plugin "replication_delay" do