include_recipe "tools"
blocks = data_bag_item("tile", "blocks")
+admins = data_bag_item("apache", "admins")
web_passwords = data_bag_item("web", "passwords")
apache_module "alias"
fastlyips = JSON.parse(IO.read("#{Chef::Config[:file_cache_path]}/fastly-ip-list.json"))
+remote_file "#{Chef::Config[:file_cache_path]}/statuscake-locations.json" do
+ source "https://app.statuscake.com/Workfloor/Locations.php?format=json"
+ compile_time true
+ ignore_failure true
+end
+
+statuscakelocations = JSON.parse(IO.read("#{Chef::Config[:file_cache_path]}/statuscake-locations.json"))
+
apache_site "default" do
action :disable
end
apache_site "tile.openstreetmap.org" do
template "apache.erb"
- variables :fastly => fastlyips["addresses"]
+ variables :fastly => fastlyips["addresses"] + fastlyips["ipv6_addresses"],
+ :statuscake => statuscakelocations.flat_map { |_, v| [v["ip"], v["ipv6"]] },
+ :admins => admins["hosts"]
end
template "/etc/logrotate.d/apache2" do
mode "755"
end
-directory "/srv/tile.openstreetmap.org/conf" do
- owner "tile"
- group "tile"
- mode "755"
-end
-
-file "/srv/tile.openstreetmap.org/conf/ip.map" do
- owner "tile"
- group "adm"
- mode "644"
-end
+tile_directories = node[:tile][:styles].collect do |_, style|
+ style[:tile_directories].collect { |directory| directory[:name] }
+end.flatten.sort.uniq
package "renderd"
limit_nofile 4096
sandbox true
restrict_address_families "AF_UNIX"
- read_write_paths "/store/tiles"
+ read_write_paths tile_directories
restart "on-failure"
end
-systemd_service "renderd" do
- action :delete
-end
-
service "renderd" do
action [:enable, :start]
subscribes :restart, "systemd_service[renderd]"
mode "755"
end
-template "/etc/cron.hourly/export" do
- source "export.cron.erb"
- owner "root"
- group "root"
- mode "755"
+systemd_service "export-cleanup" do
+ description "Cleanup stale export temporary files"
+ joins_namespace_of "apache2.service"
+ exec_start "find /tmp -ignore_readdir_race -name 'export??????' -mmin +60 -delete"
+ user "www-data"
+ sandbox true
+end
+
+systemd_timer "export-cleanup" do
+ description "Cleanup stale export temporary files"
+ on_boot_sec "60m"
+ on_unit_inactive_sec "60m"
+end
+
+service "export-cleanup.timer" do
+ action [:enable, :start]
end
directory "/srv/tile.openstreetmap.org/data" do
only_if { node[:tile][:database][:hstore] }
end
-%w[geography_columns planet_osm_nodes planet_osm_rels planet_osm_ways raster_columns raster_overviews spatial_ref_sys].each do |table|
+%w[geography_columns planet_osm_nodes planet_osm_rels planet_osm_ways raster_columns raster_overviews].each do |table|
postgresql_table table do
cluster node[:tile][:database][:cluster]
database "gis"
end
end
-%w[geometry_columns planet_osm_line planet_osm_point planet_osm_polygon planet_osm_roads].each do |table|
+%w[geometry_columns planet_osm_line planet_osm_point planet_osm_polygon planet_osm_roads spatial_ref_sys].each do |table|
postgresql_table table do
cluster node[:tile][:database][:cluster]
database "gis"
python3-pyproj
]
-gem_package "apachelogregex" do
- gem_binary node[:ruby][:gem]
-end
-
-gem_package "file-tail" do
- gem_binary node[:ruby][:gem]
-end
-
-gem_package "lru_redux" do
- gem_binary node[:ruby][:gem]
-end
-
remote_directory "/usr/local/bin" do
source "bin"
owner "root"
files_mode "755"
end
-template "/usr/local/bin/tile-ratelimit" do
- source "tile-ratelimit.erb"
- owner "root"
- group "root"
- mode "755"
-end
-
-systemd_service "tile-ratelimit" do
- description "Monitor tile requests and enforce rate limits"
- after "apache2.service"
- user "tile"
- group "adm"
- exec_start "/usr/local/bin/tile-ratelimit"
- nice 10
- sandbox true
- read_write_paths "/srv/tile.openstreetmap.org/conf"
- restart "on-failure"
-end
-
-service "tile-ratelimit" do
- action [:enable, :start]
- subscribes :restart, "file[/usr/local/bin/tile-ratelimit]"
- subscribes :restart, "systemd_service[tile-ratelimit]"
-end
-
template "/usr/local/bin/expire-tiles" do
source "expire-tiles.erb"
owner "root"
nice 10
standard_output "null"
sandbox true
- read_write_paths [
+ read_write_paths tile_directories + [
"/store/database/nodes",
- "/store/tiles/%i",
"/var/lib/replicate/expire-queue",
"/var/log/tile"
]
subscribes :restart, "systemd_service[replicate]"
end
-template "/etc/logrotate.d/replicate" do
- source "replicate.logrotate.erb"
- owner "root"
- group "root"
- mode "644"
-end
-
template "/usr/local/bin/render-lowzoom" do
source "render-lowzoom.erb"
owner "root"
mode "755"
end
-tile_directories = node[:tile][:styles].collect do |_, style|
- style[:tile_directories].collect { |directory| directory[:name] }
-end.flatten.sort.uniq
+systemd_service "cleanup-tiles@" do
+ description "Cleanup old tiles for /%I"
+ exec_start "/usr/local/bin/cleanup-tiles /%I"
+ user "_renderd"
+ io_scheduling_class "idle"
+ sandbox true
+ read_write_paths "/%I"
+end
+
+systemd_timer "cleanup-tiles@" do
+ description "Cleanup old tiles for /%I"
+ on_boot_sec "30m"
+ on_unit_inactive_sec "60m"
+ randomized_delay_sec "10m"
+end
tile_directories.each do |directory|
- label = directory.gsub("/", "-")
+ label = directory[1..].gsub("/", "-")
- cron_d "cleanup-tiles#{label}" do
- minute "0"
- user "_renderd"
- command "ionice -c 3 /usr/local/bin/cleanup-tiles #{directory}"
- mailto "admins@openstreetmap.org"
+ service "cleanup-tiles@#{label}.timer" do
+ action [:enable, :start]
end
end