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 nodejs_package "carto"
186 nodejs_package "millstone"
188 directory "/srv/tile.openstreetmap.org/styles" do
194 node[:tile][:styles].each do |name,details|
195 style_directory = "/srv/tile.openstreetmap.org/styles/#{name}"
196 tile_directory = "/srv/tile.openstreetmap.org/tiles/#{name}"
198 template "/usr/local/bin/update-lowzoom-#{name}" do
199 source "update-lowzoom.erb"
203 variables :style => name
206 template "/etc/init.d/update-lowzoom-#{name}" do
207 source "update-lowzoom.init.erb"
211 variables :style => name
214 service "update-lowzoom-#{name}" do
216 supports :restart => true
219 file "#{tile_directory}/planet-import-complete" do
220 action :create_if_missing
226 git style_directory do
228 repository details[:repository]
229 revision details[:revision]
234 link "#{style_directory}/data" do
235 to "/srv/tile.openstreetmap.org/data"
240 execute "#{style_directory}/project.mml" do
242 command "carto project.mml > project.xml"
246 subscribes :run, "git[#{style_directory}]"
247 notifies :restart, "service[renderd]"
248 notifies :restart, "service[update-lowzoom-#{name}]"
254 postgresql_user "jburgess" do
255 cluster node[:tile][:database][:cluster]
259 postgresql_user "tomh" do
260 cluster node[:tile][:database][:cluster]
264 postgresql_user "tile" do
265 cluster node[:tile][:database][:cluster]
268 postgresql_user "www-data" do
269 cluster node[:tile][:database][:cluster]
272 postgresql_database "gis" do
273 cluster node[:tile][:database][:cluster]
277 postgresql_extension "postgis" do
278 cluster node[:tile][:database][:cluster]
282 [ "geography_columns",
288 "spatial_ref_sys" ].each do |table|
289 postgresql_table table do
290 cluster node[:tile][:database][:cluster]
293 permissions "tile" => :all
297 [ "geometry_columns",
300 "planet_osm_polygon",
301 "planet_osm_roads" ].each do |table|
302 postgresql_table table do
303 cluster node[:tile][:database][:cluster]
306 permissions "tile" => :all, "www-data" => :select
310 postgresql_munin "gis" do
311 cluster node[:tile][:database][:cluster]
315 #if node[:tile][:node_file]
316 # file node[:tile][:node_file] do
323 directory "/var/log/tile" do
335 package "libproj-dev"
336 package "libxml2-dev"
339 gem_package "proj4rb"
340 gem_package "libxml-ruby"
343 remote_directory "/usr/local/lib/site_ruby" do
353 template "/usr/local/bin/expire-tiles" do
354 source "expire-tiles.erb"
360 directory "/var/lib/replicate" do
366 template "/var/lib/replicate/configuration.txt" do
367 source "replicate.configuration.erb"
373 template "/usr/local/bin/replicate" do
374 source "replicate.erb"
380 template "/etc/init.d/replicate" do
381 source "replicate.init.erb"
387 service "replicate" do
388 action [ :enable, :start ]
389 supports :restart => true
390 subscribes :restart, resources(:template => "/usr/local/bin/replicate")
391 subscribes :restart, resources(:template => "/etc/init.d/replicate")
394 template "/etc/logrotate.d/replicate" do
395 source "replicate.logrotate.erb"
401 munin_plugin "mod_tile_fresh"
402 munin_plugin "mod_tile_response"
403 munin_plugin "mod_tile_zoom"
405 munin_plugin "renderd_processed"
406 munin_plugin "renderd_queue"
407 munin_plugin "renderd_zoom"
408 munin_plugin "renderd_zoom_time"
410 munin_plugin "replication_delay" do