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"
25 blocks = data_bag_item("tile", "blocks")
28 apache_module "expires"
29 apache_module "headers"
30 apache_module "remoteip"
31 apache_module "rewrite"
33 apache_module "tile" do
37 tilecaches = search(:node, "roles:tilecache").sort_by { |n| n[:hostname] }
39 apache_site "default" do
43 apache_site "tile.openstreetmap.org" do
45 variables :caches => tilecaches
48 template "/etc/logrotate.d/apache2" do
49 source "logrotate.apache.erb"
55 directory "/srv/tile.openstreetmap.org" do
64 action [ :enable, :start ]
65 supports :status => false, :restart => true, :reload => false
68 directory node[:tile][:tile_directory] do
74 if node[:tile][:tile_directory] != "/srv/tile.openstreetmap.org/tiles"
75 link "/srv/tile.openstreetmap.org/tiles" do
76 to node[:tile][:tile_directory]
80 template "/etc/renderd.conf" do
81 source "renderd.conf.erb"
85 notifies :reload, resources(:service => "apache2")
86 notifies :restart, resources(:service => "renderd")
89 remote_directory "/srv/tile.openstreetmap.org/html" do
99 directory "/srv/tile.openstreetmap.org/cgi-bin" do
105 template "/srv/tile.openstreetmap.org/cgi-bin/export" do
110 variables :blocks => blocks
113 directory "/srv/tile.openstreetmap.org/data" do
119 node[:tile][:data].each do |name,data|
121 file = "/srv/tile.openstreetmap.org/data/#{File.basename(url)}"
122 directory = "/srv/tile.openstreetmap.org/data/#{data[:directory]}"
124 directory directory do
135 command "tar -zxf #{file} -C #{directory}"
139 elsif file =~ /\.tar\.bz2$/
144 command "tar -jxf #{file} -C #{directory}"
148 elsif file =~ /\.zip$/
153 command "unzip -qq #{file} -d #{directory}"
160 original = "#{directory}/#{data[:original]}"
161 processed = "#{directory}/#{data[:processed]}"
167 command "ogr2ogr #{processed} #{original}"
170 subscribes :run, resources(:execute => file), :immediately
175 action :create_if_missing
180 notifies :run, resources(:execute => file), :immediately
181 notifies :restart, resources(:service => "renderd")
185 template "/usr/local/bin/render-lowzoom" do
186 source "render-lowzoom.erb"
192 template "/etc/init.d/render-lowzoom" do
193 source "render-lowzoom.init.erb"
199 service "render-lowzoom" do
201 supports :restart => true
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 file "#{tile_directory}/planet-import-complete" do
218 action :create_if_missing
224 git style_directory do
226 repository details[:repository]
227 revision details[:revision]
232 link "#{style_directory}/data" do
233 to "/srv/tile.openstreetmap.org/data"
238 execute "#{style_directory}/project.mml" do
240 command "carto project.mml > project.xml"
244 subscribes :run, "git[#{style_directory}]"
245 notifies :restart, "service[renderd]"
246 notifies :restart, "service[render-lowzoom]"
252 postgresql_user "jburgess" do
253 cluster node[:tile][:database][:cluster]
257 postgresql_user "tomh" do
258 cluster node[:tile][:database][:cluster]
262 postgresql_user "tile" do
263 cluster node[:tile][:database][:cluster]
266 postgresql_user "www-data" do
267 cluster node[:tile][:database][:cluster]
270 postgresql_database "gis" do
271 cluster node[:tile][:database][:cluster]
275 postgresql_extension "postgis" do
276 cluster node[:tile][:database][:cluster]
280 [ "geography_columns",
286 "spatial_ref_sys" ].each do |table|
287 postgresql_table table do
288 cluster node[:tile][:database][:cluster]
291 permissions "tile" => :all
295 [ "geometry_columns",
298 "planet_osm_polygon",
299 "planet_osm_roads" ].each do |table|
300 postgresql_table table do
301 cluster node[:tile][:database][:cluster]
304 permissions "tile" => :all, "www-data" => :select
308 postgresql_munin "gis" do
309 cluster node[:tile][:database][:cluster]
313 #if node[:tile][:node_file]
314 # file node[:tile][:node_file] do
327 package "libproj-dev"
328 package "libxml2-dev"
331 gem_package "proj4rb"
332 gem_package "libxml-ruby"
335 remote_directory "/usr/local/lib/site_ruby" do
345 template "/usr/local/bin/expire-tiles" do
346 source "expire-tiles.erb"
352 directory "/var/lib/replicate" do
358 directory "/var/log/replicate" do
364 template "/var/lib/replicate/configuration.txt" do
365 source "replicate.configuration.erb"
371 template "/usr/local/bin/replicate" do
372 source "replicate.erb"
378 template "/etc/init.d/replicate" do
379 source "replicate.init.erb"
385 service "replicate" do
386 action [ :enable, :start ]
387 supports :restart => true
388 subscribes :restart, resources(:template => "/usr/local/bin/replicate")
389 subscribes :restart, resources(:template => "/etc/init.d/replicate")
392 template "/etc/logrotate.d/replicate" do
393 source "replicate.logrotate.erb"
399 munin_plugin "mod_tile_fresh"
400 munin_plugin "mod_tile_response"
401 munin_plugin "mod_tile_zoom"
403 munin_plugin "renderd_processed"
404 munin_plugin "renderd_queue"
405 munin_plugin "renderd_zoom"
406 munin_plugin "renderd_zoom_time"
408 munin_plugin "replication_delay" do