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"
79 no_new_privileges true
84 action [:enable, :start]
85 subscribes :restart, "systemd_service[renderd]"
88 directory "/srv/tile.openstreetmap.org/tiles" do
94 template "/etc/renderd.conf" do
95 source "renderd.conf.erb"
99 notifies :reload, "service[apache2]"
100 notifies :restart, "service[renderd]"
103 remote_directory "/srv/tile.openstreetmap.org/html" do
113 template "/srv/tile.openstreetmap.org/html/index.html" do
114 source "index.html.erb"
120 package "python-cairo"
121 package "python-mapnik"
122 package "python-setuptools"
124 easy_install_package "pyotp"
126 package "fonts-noto-cjk"
127 package "fonts-noto-hinted"
128 package "fonts-noto-unhinted"
129 package "ttf-unifont"
131 directory "/srv/tile.openstreetmap.org/cgi-bin" do
137 template "/srv/tile.openstreetmap.org/cgi-bin/export" do
142 variables :blocks => blocks, :totp_key => web_passwords["totp_key"]
145 template "/srv/tile.openstreetmap.org/cgi-bin/debug" do
152 template "/etc/cron.hourly/export" do
153 source "export.cron.erb"
159 directory "/srv/tile.openstreetmap.org/data" do
165 package "mapnik-utils"
167 node[:tile][:data].each_value do |data|
169 file = "/srv/tile.openstreetmap.org/data/#{File.basename(url)}"
172 directory = "/srv/tile.openstreetmap.org/data/#{data[:directory]}"
174 directory directory do
180 directory = "/srv/tile.openstreetmap.org/data"
188 command "tar -zxf #{file} -C #{directory}"
192 elsif file =~ /\.tar\.bz2$/
197 command "tar -jxf #{file} -C #{directory}"
201 elsif file =~ /\.zip$/
206 command "unzip -qq -o #{file} -d #{directory}"
212 execute "#{file}_shapeindex" do
214 command "find #{directory} -type f -iname '*.shp' -print0 | xargs -0 --no-run-if-empty shapeindex --shape_files"
217 subscribes :run, "execute[#{file}]", :immediately
223 use_conditional_get true
226 action :create_if_missing
234 notifies :run, "execute[#{file}]", :immediately
235 notifies :restart, "service[renderd]"
239 nodejs_package "carto"
240 nodejs_package "millstone"
242 systemd_service "update-lowzoom@" do
243 description "Low zoom tile update service for %i layer"
245 exec_start "/usr/local/bin/update-lowzoom-%i"
249 protect_system "full"
251 no_new_privileges true
255 directory "/srv/tile.openstreetmap.org/styles" do
261 node[:tile][:styles].each do |name, details|
262 style_directory = "/srv/tile.openstreetmap.org/styles/#{name}"
263 tile_directory = "/srv/tile.openstreetmap.org/tiles/#{name}"
265 template "/usr/local/bin/update-lowzoom-#{name}" do
266 source "update-lowzoom.erb"
270 variables :style => name
273 service "update-lowzoom@#{name}" do
275 supports :restart => true
278 directory tile_directory do
284 details[:tile_directories].each do |directory|
285 directory directory[:name] do
291 directory[:min_zoom].upto(directory[:max_zoom]) do |zoom|
292 directory "#{directory[:name]}/#{zoom}" do
298 link "#{tile_directory}/#{zoom}" do
299 to "#{directory[:name]}/#{zoom}"
306 file "#{tile_directory}/planet-import-complete" do
307 action :create_if_missing
313 git style_directory do
315 repository details[:repository]
316 revision details[:revision]
321 link "#{style_directory}/data" do
322 to "/srv/tile.openstreetmap.org/data"
327 execute "#{style_directory}/project.mml" do
329 command "carto -a 3.0.0 project.mml > project.xml"
333 subscribes :run, "git[#{style_directory}]"
334 notifies :restart, "service[renderd]", :immediately
335 notifies :restart, "service[update-lowzoom@#{name}]"
339 postgresql_version = node[:tile][:database][:cluster].split("/").first
342 package "postgresql-#{postgresql_version}-postgis-2.3"
344 postgresql_user "jburgess" do
345 cluster node[:tile][:database][:cluster]
349 postgresql_user "tomh" do
350 cluster node[:tile][:database][:cluster]
354 postgresql_user "tile" do
355 cluster node[:tile][:database][:cluster]
358 postgresql_user "www-data" do
359 cluster node[:tile][:database][:cluster]
362 postgresql_database "gis" do
363 cluster node[:tile][:database][:cluster]
367 postgresql_extension "postgis" do
368 cluster node[:tile][:database][:cluster]
372 %w(geography_columns planet_osm_nodes planet_osm_rels planet_osm_ways raster_columns raster_overviews spatial_ref_sys).each do |table|
373 postgresql_table table do
374 cluster node[:tile][:database][:cluster]
377 permissions "tile" => :all
381 %w(geometry_columns planet_osm_line planet_osm_point planet_osm_polygon planet_osm_roads).each do |table|
382 postgresql_table table do
383 cluster node[:tile][:database][:cluster]
386 permissions "tile" => :all, "www-data" => :select
390 postgresql_munin "gis" do
391 cluster node[:tile][:database][:cluster]
395 file node[:tile][:node_file] do
401 directory "/var/log/tile" do
413 package "libproj-dev"
414 package "libxml2-dev"
416 gem_package "proj4rb"
417 gem_package "libxml-ruby"
419 remote_directory "/usr/local/lib/site_ruby" do
429 template "/usr/local/bin/expire-tiles" do
430 source "expire-tiles.erb"
436 directory "/var/lib/replicate" do
442 directory "/var/lib/replicate/expire-queue" do
448 template "/var/lib/replicate/configuration.txt" do
449 source "replicate.configuration.erb"
455 template "/usr/local/bin/replicate" do
456 source "replicate.erb"
462 systemd_service "expire-tiles" do
463 description "Tile dirtying service"
466 exec_start "/usr/local/bin/expire-tiles"
467 standard_output "null"
470 protect_system "full"
472 no_new_privileges true
475 systemd_path "expire-tiles" do
476 description "Tile dirtying trigger"
477 directory_not_empty "/var/lib/replicate/expire-queue"
480 service "expire-tiles.path" do
481 action [:enable, :start]
482 subscribes :restart, "systemd_path[expire-tiles]"
485 systemd_service "replicate" do
486 description "Rendering database replication service"
487 after "postgresql.service"
488 wants "postgresql.service"
490 exec_start "/usr/local/bin/replicate"
493 protect_system "full"
495 no_new_privileges true
499 service "replicate" do
500 action [:enable, :start]
501 subscribes :restart, "template[/usr/local/bin/replicate]"
502 subscribes :restart, "systemd_service[replicate]"
505 template "/etc/logrotate.d/replicate" do
506 source "replicate.logrotate.erb"
512 template "/usr/local/bin/render-lowzoom" do
513 source "render-lowzoom.erb"
519 template "/etc/cron.d/render-lowzoom" do
520 source "render-lowzoom.cron.erb"
526 package "liblockfile-simple-perl"
527 package "libfilesys-df-perl"
529 template "/usr/local/bin/cleanup-tiles" do
530 source "cleanup-tiles.erb"
536 tile_directories = node[:tile][:styles].collect do |_, style|
537 style[:tile_directories].collect { |directory| directory[:name] }
538 end.flatten.sort.uniq
540 template "/etc/cron.d/cleanup-tiles" do
541 source "cleanup-tiles.cron.erb"
545 variables :directories => tile_directories
548 munin_plugin "mod_tile_fresh"
549 munin_plugin "mod_tile_latency"
550 munin_plugin "mod_tile_response"
551 munin_plugin "mod_tile_zoom"
553 munin_plugin "renderd_processed"
554 munin_plugin "renderd_queue"
555 munin_plugin "renderd_queue_time"
556 munin_plugin "renderd_zoom"
557 munin_plugin "renderd_zoom_time"
559 munin_plugin "replication_delay" do