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")
27 web_passwords = data_bag_item("web", "passwords")
31 apache_module "expires"
32 apache_module "headers"
33 apache_module "remoteip"
34 apache_module "rewrite"
36 apache_module "tile" do
40 tilecaches = search(:node, "roles:tilecache").sort_by { |n| n[:hostname] }
42 apache_site "default" do
46 apache_site "tile.openstreetmap.org" do
48 variables :caches => tilecaches
51 template "/etc/logrotate.d/apache2" do
52 source "logrotate.apache.erb"
58 directory "/srv/tile.openstreetmap.org" do
66 systemd_service "renderd" do
67 description "Mapnik rendering daemon"
68 after "postgresql.service"
69 wants "postgresql.service"
71 exec_start "/usr/bin/renderd -f"
72 runtime_directory "renderd"
83 action [:enable, :start]
86 directory "/srv/tile.openstreetmap.org/tiles" do
92 template "/etc/renderd.conf" do
93 source "renderd.conf.erb"
97 notifies :reload, "service[apache2]"
98 notifies :restart, "service[renderd]"
101 remote_directory "/srv/tile.openstreetmap.org/html" do
111 template "/srv/tile.openstreetmap.org/html/index.html" do
112 source "index.html.erb"
118 package "python-cairo"
119 package "python-mapnik"
120 package "python-setuptools"
122 easy_install_package "pyotp"
124 package "fonts-noto-cjk"
125 package "fonts-noto-hinted"
126 package "fonts-noto-unhinted"
127 package "ttf-unifont"
129 directory "/srv/tile.openstreetmap.org/cgi-bin" do
135 template "/srv/tile.openstreetmap.org/cgi-bin/export" do
140 variables :blocks => blocks, :totp_key => web_passwords["totp_key"]
143 template "/srv/tile.openstreetmap.org/cgi-bin/debug" do
150 template "/etc/cron.hourly/export" do
151 source "export.cron.erb"
157 directory "/srv/tile.openstreetmap.org/data" do
163 package "mapnik-utils"
165 node[:tile][:data].each_value do |data|
167 file = "/srv/tile.openstreetmap.org/data/#{File.basename(url)}"
170 directory = "/srv/tile.openstreetmap.org/data/#{data[:directory]}"
172 directory directory do
178 directory = "/srv/tile.openstreetmap.org/data"
186 command "tar -zxf #{file} -C #{directory}"
190 elsif file =~ /\.tar\.bz2$/
195 command "tar -jxf #{file} -C #{directory}"
199 elsif file =~ /\.zip$/
204 command "unzip -qq -o #{file} -d #{directory}"
210 execute "#{file}_shapeindex" do
212 command "find #{directory} -type f -iname '*.shp' -print0 | xargs -0 --no-run-if-empty shapeindex --shape_files"
215 subscribes :run, "execute[#{file}]", :immediately
221 use_conditional_get true
224 action :create_if_missing
232 notifies :run, "execute[#{file}]", :immediately
233 notifies :restart, "service[renderd]"
237 nodejs_package "carto"
238 nodejs_package "millstone"
240 directory "/srv/tile.openstreetmap.org/styles" do
246 node[:tile][:styles].each do |name, details|
247 style_directory = "/srv/tile.openstreetmap.org/styles/#{name}"
248 tile_directory = "/srv/tile.openstreetmap.org/tiles/#{name}"
250 template "/usr/local/bin/update-lowzoom-#{name}" do
251 source "update-lowzoom.erb"
255 variables :style => name
258 template "/etc/init.d/update-lowzoom-#{name}" do
259 source "update-lowzoom.init.erb"
263 variables :style => name
266 service "update-lowzoom-#{name}" do
268 supports :restart => true
271 directory tile_directory do
277 details[:tile_directories].each do |directory|
278 directory directory[:name] do
284 directory[:min_zoom].upto(directory[:max_zoom]) do |zoom|
285 directory "#{directory[:name]}/#{zoom}" do
291 link "#{tile_directory}/#{zoom}" do
292 to "#{directory[:name]}/#{zoom}"
299 file "#{tile_directory}/planet-import-complete" do
300 action :create_if_missing
306 git style_directory do
308 repository details[:repository]
309 revision details[:revision]
314 link "#{style_directory}/data" do
315 to "/srv/tile.openstreetmap.org/data"
320 execute "#{style_directory}/project.mml" do
322 command "carto -a 3.0.0 project.mml > project.xml"
326 subscribes :run, "git[#{style_directory}]"
327 notifies :restart, "service[renderd]", :immediately
328 notifies :restart, "service[update-lowzoom-#{name}]"
332 postgresql_version = node[:tile][:database][:cluster].split("/").first
335 package "postgresql-#{postgresql_version}-postgis-2.3"
337 postgresql_user "jburgess" do
338 cluster node[:tile][:database][:cluster]
342 postgresql_user "tomh" do
343 cluster node[:tile][:database][:cluster]
347 postgresql_user "tile" do
348 cluster node[:tile][:database][:cluster]
351 postgresql_user "www-data" do
352 cluster node[:tile][:database][:cluster]
355 postgresql_database "gis" do
356 cluster node[:tile][:database][:cluster]
360 postgresql_extension "postgis" do
361 cluster node[:tile][:database][:cluster]
365 %w(geography_columns planet_osm_nodes planet_osm_rels planet_osm_ways raster_columns raster_overviews spatial_ref_sys).each do |table|
366 postgresql_table table do
367 cluster node[:tile][:database][:cluster]
370 permissions "tile" => :all
374 %w(geometry_columns planet_osm_line planet_osm_point planet_osm_polygon planet_osm_roads).each do |table|
375 postgresql_table table do
376 cluster node[:tile][:database][:cluster]
379 permissions "tile" => :all, "www-data" => :select
383 postgresql_munin "gis" do
384 cluster node[:tile][:database][:cluster]
388 file node[:tile][:node_file] do
394 directory "/var/log/tile" do
406 package "libproj-dev"
407 package "libxml2-dev"
409 gem_package "proj4rb"
410 gem_package "libxml-ruby"
412 remote_directory "/usr/local/lib/site_ruby" do
422 template "/usr/local/bin/expire-tiles" do
423 source "expire-tiles.erb"
429 template "/etc/sudoers.d/tile" do
436 directory "/var/lib/replicate" do
442 template "/var/lib/replicate/configuration.txt" do
443 source "replicate.configuration.erb"
449 template "/usr/local/bin/replicate" do
450 source "replicate.erb"
456 systemd_service "replicate" do
457 description "Rendering database replication service"
458 after "postgresql.service"
459 wants "postgresql.service"
461 exec_start "/usr/local/bin/replicate"
464 protect_system "full"
469 service "replicate" do
470 action [:enable, :start]
471 subscribes :restart, "template[/usr/local/bin/replicate]"
472 subscribes :restart, "systemd_service[replicate]"
475 template "/etc/logrotate.d/replicate" do
476 source "replicate.logrotate.erb"
482 template "/usr/local/bin/render-lowzoom" do
483 source "render-lowzoom.erb"
489 template "/etc/cron.d/render-lowzoom" do
490 source "render-lowzoom.cron.erb"
496 package "liblockfile-simple-perl"
497 package "libfilesys-df-perl"
499 template "/usr/local/bin/cleanup-tiles" do
500 source "cleanup-tiles.erb"
506 tile_directories = node[:tile][:styles].collect do |_, style|
507 style[:tile_directories].collect { |directory| directory[:name] }
508 end.flatten.sort.uniq
510 template "/etc/cron.d/cleanup-tiles" do
511 source "cleanup-tiles.cron.erb"
515 variables :directories => tile_directories
518 munin_plugin "mod_tile_fresh"
519 munin_plugin "mod_tile_latency"
520 munin_plugin "mod_tile_response"
521 munin_plugin "mod_tile_zoom"
523 munin_plugin "renderd_processed"
524 munin_plugin "renderd_queue"
525 munin_plugin "renderd_queue_time"
526 munin_plugin "renderd_zoom"
527 munin_plugin "renderd_zoom_time"
529 munin_plugin "replication_delay" do