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
179 action :create_if_missing
184 notifies :run, resources(:execute => file), :immediately
185 notifies :restart, resources(:service => "renderd")
189 nodejs_package "carto"
190 nodejs_package "millstone"
192 directory "/srv/tile.openstreetmap.org/styles" do
198 node[:tile][:styles].each do |name,details|
199 style_directory = "/srv/tile.openstreetmap.org/styles/#{name}"
200 tile_directory = "/srv/tile.openstreetmap.org/tiles/#{name}"
202 template "/usr/local/bin/update-lowzoom-#{name}" do
203 source "update-lowzoom.erb"
207 variables :style => name
210 template "/etc/init.d/update-lowzoom-#{name}" do
211 source "update-lowzoom.init.erb"
215 variables :style => name
218 service "update-lowzoom-#{name}" do
220 supports :restart => true
223 directory tile_directory do
229 file "#{tile_directory}/planet-import-complete" do
230 action :create_if_missing
236 git style_directory do
238 repository details[:repository]
239 revision details[:revision]
244 link "#{style_directory}/data" do
245 to "/srv/tile.openstreetmap.org/data"
250 execute "#{style_directory}/project.mml" do
252 command "carto project.mml > project.xml"
256 subscribes :run, "git[#{style_directory}]"
257 notifies :restart, "service[renderd]"
258 notifies :restart, "service[update-lowzoom-#{name}]"
264 postgresql_user "jburgess" do
265 cluster node[:tile][:database][:cluster]
269 postgresql_user "tomh" do
270 cluster node[:tile][:database][:cluster]
274 postgresql_user "tile" do
275 cluster node[:tile][:database][:cluster]
278 postgresql_user "www-data" do
279 cluster node[:tile][:database][:cluster]
282 postgresql_database "gis" do
283 cluster node[:tile][:database][:cluster]
287 postgresql_extension "postgis" do
288 cluster node[:tile][:database][:cluster]
292 [ "geography_columns",
298 "spatial_ref_sys" ].each do |table|
299 postgresql_table table do
300 cluster node[:tile][:database][:cluster]
303 permissions "tile" => :all
307 [ "geometry_columns",
310 "planet_osm_polygon",
311 "planet_osm_roads" ].each do |table|
312 postgresql_table table do
313 cluster node[:tile][:database][:cluster]
316 permissions "tile" => :all, "www-data" => :select
320 postgresql_munin "gis" do
321 cluster node[:tile][:database][:cluster]
325 #if node[:tile][:node_file]
326 # file node[:tile][:node_file] do
333 directory "/var/log/tile" do
345 package "libproj-dev"
346 package "libxml2-dev"
349 gem_package "proj4rb"
350 gem_package "libxml-ruby"
353 remote_directory "/usr/local/lib/site_ruby" do
363 template "/usr/local/bin/expire-tiles" do
364 source "expire-tiles.erb"
370 template "/etc/sudoers.d/tile" do
377 directory "/var/lib/replicate" do
383 template "/var/lib/replicate/configuration.txt" do
384 source "replicate.configuration.erb"
390 template "/usr/local/bin/replicate" do
391 source "replicate.erb"
397 template "/etc/init.d/replicate" do
398 source "replicate.init.erb"
404 service "replicate" do
405 action [ :enable, :start ]
406 supports :restart => true
407 subscribes :restart, resources(:template => "/usr/local/bin/replicate")
408 subscribes :restart, resources(:template => "/etc/init.d/replicate")
411 template "/etc/logrotate.d/replicate" do
412 source "replicate.logrotate.erb"
418 template "/usr/local/bin/render-lowzoom" do
419 source "render-lowzoom.erb"
425 template "/etc/cron.d/render-lowzoom" do
426 source "render-lowzoom.cron.erb"
432 template "/etc/rsyslog.d/20-renderd.conf" do
433 source "renderd.rsyslog.erb"
437 notifies :restart, "service[rsyslog]"
440 munin_plugin "mod_tile_fresh"
441 munin_plugin "mod_tile_response"
442 munin_plugin "mod_tile_zoom"
444 munin_plugin "renderd_processed"
445 munin_plugin "renderd_queue"
446 munin_plugin "renderd_zoom"
447 munin_plugin "renderd_zoom_time"
449 munin_plugin "replication_delay" do