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")
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 directory = "/srv/tile.openstreetmap.org/styles/#{name}"
199 repository details[:repository]
200 revision details[:revision]
205 link "#{directory}/data" do
206 to "/srv/tile.openstreetmap.org/data"
211 execute "#{directory}/project.mml" do
212 command "carto project.mml > project.xml"
217 File.exist?("#{directory}/project.xml") and
218 File.mtime("#{directory}/project.xml") >= File.mtime("#{directory}/project.mml")
220 notifies :restart, resources(:service => "renderd")
226 postgresql_user "jburgess" do
227 cluster node[:tile][:database][:cluster]
231 postgresql_user "tomh" do
232 cluster node[:tile][:database][:cluster]
236 postgresql_user "tile" do
237 cluster node[:tile][:database][:cluster]
240 postgresql_user "www-data" do
241 cluster node[:tile][:database][:cluster]
244 postgresql_database "gis" do
245 cluster node[:tile][:database][:cluster]
249 postgresql_extension "postgis" do
250 cluster node[:tile][:database][:cluster]
254 [ "geography_columns",
260 "spatial_ref_sys" ].each do |table|
261 postgresql_table table do
262 cluster node[:tile][:database][:cluster]
265 permissions "tile" => :all
269 [ "geometry_columns",
272 "planet_osm_polygon",
273 "planet_osm_roads" ].each do |table|
274 postgresql_table table do
275 cluster node[:tile][:database][:cluster]
278 permissions "tile" => :all, "www-data" => :select
282 postgresql_munin "gis" do
283 cluster node[:tile][:database][:cluster]
287 #if node[:tile][:node_file]
288 # file node[:tile][:node_file] do
301 package "libproj-dev"
302 package "libxml2-dev"
305 gem_package "proj4rb"
306 gem_package "libxml-ruby"
309 remote_directory "/usr/local/lib/site_ruby" do
319 template "/usr/local/bin/expire-tiles" do
320 source "expire-tiles.erb"
326 directory "/var/lib/replicate" do
332 directory "/var/log/replicate" do
338 template "/var/lib/replicate/configuration.txt" do
339 source "replicate.configuration.erb"
345 template "/usr/local/bin/replicate" do
346 source "replicate.erb"
352 template "/etc/init.d/replicate" do
353 source "replicate.init.erb"
359 service "replicate" do
360 action [ :enable, :start ]
361 supports :restart => true
362 subscribes :restart, resources(:template => "/usr/local/bin/replicate")
363 subscribes :restart, resources(:template => "/etc/init.d/replicate")
366 template "/etc/logrotate.d/replicate" do
367 source "replicate.logrotate.erb"
373 munin_plugin "mod_tile_fresh"
374 munin_plugin "mod_tile_response"
375 munin_plugin "mod_tile_zoom"
377 munin_plugin "renderd_processed"
378 munin_plugin "renderd_queue"
379 munin_plugin "renderd_zoom"
380 munin_plugin "renderd_zoom_time"
382 munin_plugin "replication_delay" do