Skip to content

Commit

Permalink
Run expiry as a separate service for osm2pgsql replication
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhughes committed Nov 23, 2023
1 parent 9005630 commit 5d6af18
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 27 deletions.
45 changes: 32 additions & 13 deletions cookbooks/tile/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -596,24 +596,44 @@
subscribes :restart, "systemd_service[replicate]"
end
elsif node[:tile][:replication][:engine] == "osm2pgsql"
service "expire-tiles.path" do
action [:disable, :stop]
template "/usr/local/bin/expire-tiles" do
source "expire-tiles-osm2pgsql.erb"
owner "root"
group "root"
mode "755"
end

systemd_path "expire-tiles" do
action :delete
directory "/var/lib/replicate/expire-queue" do
owner "tile"
group "_renderd"
mode "775"
end

systemd_service "expire-tiles" do
description "Tile dirtying service"
type "simple"
user "_renderd"
exec_start "/usr/local/bin/expire-tiles"
nice 10
sandbox true
restrict_address_families "AF_UNIX"
read_write_paths tile_directories + [
"/var/lib/replicate/expire-queue"
]
end

service "expire-tiles" do
action :stop
systemd_path "expire-tiles" do
description "Tile dirtying trigger"
directory_not_empty "/var/lib/replicate/expire-queue"
end

systemd_service "expire-tiles" do
action :delete
service "expire-tiles.path" do
action [:enable, :start]
subscribes :restart, "systemd_path[expire-tiles]"
end

template "/usr/local/bin/expire-tiles" do
source "expire-tiles-osm2pgsql.erb"
template "/usr/local/bin/replicate-post" do
source "replicate-post.erb"
owner "root"
group "root"
mode "755"
Expand All @@ -635,11 +655,10 @@
after "postgresql.service"
wants "postgresql.service"
user "tile"
exec_start "/bin/osm2pgsql-replication update --database gis --post-processing /usr/local/bin/expire-tiles -- #{osm2pgsql_arguments.join(' ')}"
exec_start "/bin/osm2pgsql-replication update --database gis --post-processing /usr/local/bin/replicate-post -- #{osm2pgsql_arguments.join(' ')}"
sandbox :enable_network => true
restrict_address_families "AF_UNIX"
read_write_paths tile_directories + [
"/srv/tile.openstreetmap.org/tiles",
read_write_paths [
"/store/database/nodes",
"/var/lib/replicate"
]
Expand Down
27 changes: 13 additions & 14 deletions cookbooks/tile/templates/default/expire-tiles-osm2pgsql.erb
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
#!/bin/sh -e
#!/usr/bin/ruby

# DO NOT EDIT - This file is being maintained by Chef

sequence="$1"
timestamp="$2"
args = [
"--socket=/var/run/renderd/renderd.sock",
"--tile-dir=/srv/tile.openstreetmap.org/tiles",
"--touch-from=13",
"--min-zoom=13"
]

render_expired \
--map=default \
--socket=/var/run/renderd/renderd.sock \
--tile-dir=/srv/tile.openstreetmap.org/tiles \
--min-zoom=13 --max-zoom=19 \
--touch-from=13 < /var/lib/replicate/dirty-tiles.txt

rm -f /var/lib/replicate/dirty-tiles.txt

echo "$sequence" > /var/log/replicate/sequence.txt
echo "$timestamp" > /var/log/replicate/timestamp.txt
Dir.glob("/var/lib/replicate/expire-queue/changes-*.txt").sort.each do |f|
<% node[:tile][:styles].each do |name,details| -%>
system("/usr/bin/render_expired", "--map=<%= name %>", *args, "--max-zoom=<%= details[:max_zoom] %>", :in=> f) &&
<% end -%>
File::unlink(f)
end
11 changes: 11 additions & 0 deletions cookbooks/tile/templates/default/replicate-post.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh -e

# DO NOT EDIT - This file is being maintained by Chef

sequence="$1"
timestamp="$2"

mv /var/lib/replicate/dirty-tiles.txt /var/lib/replicate/expire-queue/changes-${sequence}.txt

echo "$sequence" > /var/lib/replicate/sequence.txt
echo "$timestamp" > /var/lib/replicate/timestamp.txt

0 comments on commit 5d6af18

Please sign in to comment.