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 file "#{tile_directory}/planet-import-complete" do
224 action :create_if_missing
230 git style_directory do
232 repository details[:repository]
233 revision details[:revision]
238 link "#{style_directory}/data" do
239 to "/srv/tile.openstreetmap.org/data"
244 execute "#{style_directory}/project.mml" do
246 command "carto project.mml > project.xml"
250 subscribes :run, "git[#{style_directory}]"
251 notifies :restart, "service[renderd]"
252 notifies :restart, "service[update-lowzoom-#{name}]"
258 postgresql_user "jburgess" do
259 cluster node[:tile][:database][:cluster]
263 postgresql_user "tomh" do
264 cluster node[:tile][:database][:cluster]
268 postgresql_user "tile" do
269 cluster node[:tile][:database][:cluster]
272 postgresql_user "www-data" do
273 cluster node[:tile][:database][:cluster]
276 postgresql_database "gis" do
277 cluster node[:tile][:database][:cluster]
281 postgresql_extension "postgis" do
282 cluster node[:tile][:database][:cluster]
286 [ "geography_columns",
292 "spatial_ref_sys" ].each do |table|
293 postgresql_table table do
294 cluster node[:tile][:database][:cluster]
297 permissions "tile" => :all
301 [ "geometry_columns",
304 "planet_osm_polygon",
305 "planet_osm_roads" ].each do |table|
306 postgresql_table table do
307 cluster node[:tile][:database][:cluster]
310 permissions "tile" => :all, "www-data" => :select
314 postgresql_munin "gis" do
315 cluster node[:tile][:database][:cluster]
319 #if node[:tile][:node_file]
320 # file node[:tile][:node_file] do
327 directory "/var/log/tile" do
339 package "libproj-dev"
340 package "libxml2-dev"
343 gem_package "proj4rb"
344 gem_package "libxml-ruby"
347 remote_directory "/usr/local/lib/site_ruby" do
357 template "/usr/local/bin/expire-tiles" do
358 source "expire-tiles.erb"
364 directory "/var/lib/replicate" do
370 template "/var/lib/replicate/configuration.txt" do
371 source "replicate.configuration.erb"
377 template "/usr/local/bin/replicate" do
378 source "replicate.erb"
384 template "/etc/init.d/replicate" do
385 source "replicate.init.erb"
391 service "replicate" do
392 action [ :enable, :start ]
393 supports :restart => true
394 subscribes :restart, resources(:template => "/usr/local/bin/replicate")
395 subscribes :restart, resources(:template => "/etc/init.d/replicate")
398 template "/etc/logrotate.d/replicate" do
399 source "replicate.logrotate.erb"
405 template "/usr/local/bin/render-lowzoom" do
406 source "render-lowzoom.erb"
412 template "/etc/cron.d/render-lowzoom" do
413 source "render-lowzoom.cron.erb"
419 template "/etc/rsyslog.d/20-renderd.conf" do
420 source "renderd.rsyslog.erb"
424 notifies :restart, "service[rsyslog]"
427 munin_plugin "mod_tile_fresh"
428 munin_plugin "mod_tile_response"
429 munin_plugin "mod_tile_zoom"
431 munin_plugin "renderd_processed"
432 munin_plugin "renderd_queue"
433 munin_plugin "renderd_zoom"
434 munin_plugin "renderd_zoom_time"
436 munin_plugin "replication_delay" do