]> git.openstreetmap.org Git - chef.git/commitdiff
Run expiry as a separate service for osm2pgsql replication
authorTom Hughes <tom@compton.nu>
Thu, 23 Nov 2023 00:10:51 +0000 (00:10 +0000)
committerTom Hughes <tom@compton.nu>
Thu, 23 Nov 2023 00:30:07 +0000 (00:30 +0000)
cookbooks/tile/recipes/default.rb
cookbooks/tile/templates/default/expire-tiles-osm2pgsql.erb
cookbooks/tile/templates/default/replicate-post.erb [new file with mode: 0644]

index 41c63cd4f81f1b9c95f55252027be7035d3a3f65..4df7c25547dd60a14891c6a348a217006557f4ed 100644 (file)
@@ -596,24 +596,44 @@ if node[:tile][:replication][:engine] == "custom"
     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"
@@ -635,11 +655,10 @@ elsif node[:tile][:replication][:engine] == "osm2pgsql"
     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"
     ]
index 0ad14e80358d15331b0f1fa81ba84ad54104a418..1af7f0a64dd426e2257bc41c5fe801df705eb430 100644 (file)
@@ -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
diff --git a/cookbooks/tile/templates/default/replicate-post.erb b/cookbooks/tile/templates/default/replicate-post.erb
new file mode 100644 (file)
index 0000000..63ca93b
--- /dev/null
@@ -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