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 file "#{tile_directory}/planet-import-complete" do
199 action :create_if_missing
205 git style_directory do
207 repository details[:repository]
208 revision details[:revision]
213 link "#{style_directory}/data" do
214 to "/srv/tile.openstreetmap.org/data"
219 execute "#{style_directory}/project.mml" do
220 command "carto project.mml > project.xml"
225 File.exist?("#{style_directory}/project.xml") and
226 File.mtime("#{style_directory}/project.xml") >= File.mtime("#{style_directory}/project.mml")
228 notifies :touch, "file[#{tile_directory}/planet-import-complete]"
229 notifies :restart, "service[renderd]"
235 postgresql_user "jburgess" do
236 cluster node[:tile][:database][:cluster]
240 postgresql_user "tomh" do
241 cluster node[:tile][:database][:cluster]
245 postgresql_user "tile" do
246 cluster node[:tile][:database][:cluster]
249 postgresql_user "www-data" do
250 cluster node[:tile][:database][:cluster]
253 postgresql_database "gis" do
254 cluster node[:tile][:database][:cluster]
258 postgresql_extension "postgis" do
259 cluster node[:tile][:database][:cluster]
263 [ "geography_columns",
269 "spatial_ref_sys" ].each do |table|
270 postgresql_table table do
271 cluster node[:tile][:database][:cluster]
274 permissions "tile" => :all
278 [ "geometry_columns",
281 "planet_osm_polygon",
282 "planet_osm_roads" ].each do |table|
283 postgresql_table table do
284 cluster node[:tile][:database][:cluster]
287 permissions "tile" => :all, "www-data" => :select
291 postgresql_munin "gis" do
292 cluster node[:tile][:database][:cluster]
296 #if node[:tile][:node_file]
297 # file node[:tile][:node_file] do
310 package "libproj-dev"
311 package "libxml2-dev"
314 gem_package "proj4rb"
315 gem_package "libxml-ruby"
318 remote_directory "/usr/local/lib/site_ruby" do
328 template "/usr/local/bin/expire-tiles" do
329 source "expire-tiles.erb"
335 directory "/var/lib/replicate" do
341 directory "/var/log/replicate" do
347 template "/var/lib/replicate/configuration.txt" do
348 source "replicate.configuration.erb"
354 template "/usr/local/bin/replicate" do
355 source "replicate.erb"
361 template "/etc/init.d/replicate" do
362 source "replicate.init.erb"
368 service "replicate" do
369 action [ :enable, :start ]
370 supports :restart => true
371 subscribes :restart, resources(:template => "/usr/local/bin/replicate")
372 subscribes :restart, resources(:template => "/etc/init.d/replicate")
375 template "/etc/logrotate.d/replicate" do
376 source "replicate.logrotate.erb"
382 munin_plugin "mod_tile_fresh"
383 munin_plugin "mod_tile_response"
384 munin_plugin "mod_tile_zoom"
386 munin_plugin "renderd_processed"
387 munin_plugin "renderd_queue"
388 munin_plugin "renderd_zoom"
389 munin_plugin "renderd_zoom_time"
391 munin_plugin "replication_delay" do