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 directory "/srv/tile.openstreetmap.org/data" do
130 node[:tile][:data].each do |name,data|
132 file = "/srv/tile.openstreetmap.org/data/#{File.basename(url)}"
133 directory = "/srv/tile.openstreetmap.org/data/#{data[:directory]}"
135 directory directory do
146 command "tar -zxf #{file} -C #{directory}"
150 elsif file =~ /\.tar\.bz2$/
155 command "tar -jxf #{file} -C #{directory}"
159 elsif file =~ /\.zip$/
164 command "unzip -qq #{file} -d #{directory}"
171 original = "#{directory}/#{data[:original]}"
172 processed = "#{directory}/#{data[:processed]}"
178 command "ogr2ogr #{processed} #{original}"
181 subscribes :run, resources(:execute => file), :immediately
185 execute "#{file}_shapeindex" do
187 command "find #{directory} -type f -iname '*.shp' -print0 | xargs -0 --no-run-if-empty shapeindex --shape_files"
190 subscribes :run, resources(:execute => file), :immediately
194 action :create_if_missing
199 notifies :run, resources(:execute => file), :immediately
200 notifies :restart, resources(:service => "renderd")
204 nodejs_package "carto"
205 nodejs_package "millstone"
207 directory "/srv/tile.openstreetmap.org/styles" do
213 node[:tile][:styles].each do |name,details|
214 style_directory = "/srv/tile.openstreetmap.org/styles/#{name}"
215 tile_directory = "/srv/tile.openstreetmap.org/tiles/#{name}"
217 template "/usr/local/bin/update-lowzoom-#{name}" do
218 source "update-lowzoom.erb"
222 variables :style => name
225 template "/etc/init.d/update-lowzoom-#{name}" do
226 source "update-lowzoom.init.erb"
230 variables :style => name
233 service "update-lowzoom-#{name}" do
235 supports :restart => true
238 directory tile_directory do
244 file "#{tile_directory}/planet-import-complete" do
245 action :create_if_missing
251 git style_directory do
253 repository details[:repository]
254 revision details[:revision]
259 link "#{style_directory}/data" do
260 to "/srv/tile.openstreetmap.org/data"
265 execute "#{style_directory}/project.mml" do
267 command "carto project.mml > project.xml"
271 subscribes :run, "git[#{style_directory}]"
272 notifies :restart, "service[renderd]", :immediately
273 notifies :restart, "service[update-lowzoom-#{name}]"
279 postgresql_user "jburgess" do
280 cluster node[:tile][:database][:cluster]
284 postgresql_user "tomh" do
285 cluster node[:tile][:database][:cluster]
289 postgresql_user "tile" do
290 cluster node[:tile][:database][:cluster]
293 postgresql_user "www-data" do
294 cluster node[:tile][:database][:cluster]
297 postgresql_database "gis" do
298 cluster node[:tile][:database][:cluster]
302 postgresql_extension "postgis" do
303 cluster node[:tile][:database][:cluster]
307 [ "geography_columns",
313 "spatial_ref_sys" ].each do |table|
314 postgresql_table table do
315 cluster node[:tile][:database][:cluster]
318 permissions "tile" => :all
322 [ "geometry_columns",
325 "planet_osm_polygon",
326 "planet_osm_roads" ].each do |table|
327 postgresql_table table do
328 cluster node[:tile][:database][:cluster]
331 permissions "tile" => :all, "www-data" => :select
335 postgresql_munin "gis" do
336 cluster node[:tile][:database][:cluster]
340 #file node[:tile][:node_file] do
346 directory "/var/log/tile" do
358 package "libproj-dev"
359 package "libxml2-dev"
361 gem_package "proj4rb"
362 gem_package "libxml-ruby"
365 remote_directory "/usr/local/lib/site_ruby" do
375 template "/usr/local/bin/expire-tiles" do
376 source "expire-tiles.erb"
382 template "/etc/sudoers.d/tile" do
389 directory "/var/lib/replicate" do
395 template "/var/lib/replicate/configuration.txt" do
396 source "replicate.configuration.erb"
402 template "/usr/local/bin/replicate" do
403 source "replicate.erb"
409 template "/etc/init.d/replicate" do
410 source "replicate.init.erb"
416 service "replicate" do
417 action [ :enable, :start ]
418 supports :restart => true
419 subscribes :restart, resources(:template => "/usr/local/bin/replicate")
420 subscribes :restart, resources(:template => "/etc/init.d/replicate")
423 template "/etc/logrotate.d/replicate" do
424 source "replicate.logrotate.erb"
430 template "/usr/local/bin/render-lowzoom" do
431 source "render-lowzoom.erb"
437 template "/etc/cron.d/render-lowzoom" do
438 source "render-lowzoom.cron.erb"
444 template "/etc/rsyslog.d/20-renderd.conf" do
445 source "renderd.rsyslog.erb"
449 notifies :restart, "service[rsyslog]"
452 munin_plugin "mod_tile_fresh"
453 munin_plugin "mod_tile_response"
454 munin_plugin "mod_tile_zoom"
455 munin_plugin "mod_tile_latency"
457 munin_plugin "renderd_processed"
458 munin_plugin "renderd_queue"
459 munin_plugin "renderd_zoom"
460 munin_plugin "renderd_zoom_time"
462 munin_plugin "replication_delay" do