]> git.openstreetmap.org Git - chef.git/commitdiff
Convert taginfo update to use a systemd timer
authorTom Hughes <tom@compton.nu>
Mon, 28 Nov 2022 19:13:56 +0000 (19:13 +0000)
committerTom Hughes <tom@compton.nu>
Mon, 28 Nov 2022 20:09:06 +0000 (20:09 +0000)
cookbooks/planet/attributes/default.rb
cookbooks/planet/recipes/current.rb
cookbooks/planet/templates/default/planet-update-file.erb [deleted file]
cookbooks/planet/templates/default/planet-update.erb
cookbooks/planet/templates/default/planet-update.logrotate.erb [deleted file]
cookbooks/taginfo/metadata.rb
cookbooks/taginfo/recipes/default.rb
cookbooks/taginfo/templates/default/taginfo-update.erb [deleted file]
roles/planet-current.rb [deleted file]
roles/taginfo.rb

index f01d8acc4b11744b68c2d19e7ffef3d98fda4b5c..7c8a60466ae572bd12973a0a4b3bb592bf1be597 100644 (file)
@@ -4,5 +4,3 @@ default[:planet][:dump][:xml_directory] = "/store/planet/planet"
 default[:planet][:dump][:xml_history_directory] = "/store/planet/planet/full-history"
 default[:planet][:dump][:pbf_directory] = "/store/planet/pbf"
 default[:planet][:dump][:pbf_history_directory] = "/store/planet/pbf/full-history"
-
-default[:planet][:current][:jobs] = {}
index c7175e6e17ebd0b55597b55a2d33f93ce1c79176..517123f5913219f97a73d9402c419e81415bdac7 100644 (file)
@@ -17,6 +17,8 @@
 # limitations under the License.
 #
 
+node.default[:accounts][:users][:planet][:status] = :role
+
 include_recipe "accounts"
 
 package %w[
@@ -30,13 +32,6 @@ template "/usr/local/bin/planet-update" do
   mode "755"
 end
 
-template "/usr/local/bin/planet-update-file" do
-  source "planet-update-file.erb"
-  owner "root"
-  group "root"
-  mode "755"
-end
-
 directory "/var/lib/planet" do
   owner "planet"
   group "planet"
@@ -52,16 +47,11 @@ remote_file "/var/lib/planet/planet.osh.pbf" do
   not_if { kitchen? }
 end
 
-cron_d "planet-update" do
-  minute "37"
-  hour "1"
-  user "root"
-  command "/usr/local/bin/planet-update"
-end
-
-template "/etc/logrotate.d/planet-update" do
-  source "planet-update.logrotate.erb"
-  owner "root"
-  group "root"
-  mode "644"
+systemd_service "planet-update" do
+  description "Planet file update"
+  type "oneshot"
+  exec_start "/usr/local/bin/planet-update"
+  user "planet"
+  sandbox :enable_network => true
+  read_write_paths "/var/lib/planet"
 end
diff --git a/cookbooks/planet/templates/default/planet-update-file.erb b/cookbooks/planet/templates/default/planet-update-file.erb
deleted file mode 100644 (file)
index 73a778b..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-#!/bin/sh
-
-# DO NOT EDIT - This file is being maintained by Chef
-
-# setup
-
-SUFFIX="osh.pbf"
-
-PLANETDIR="/var/lib/planet"
-PLANETPREV="${PLANETDIR}/planet-previous.${SUFFIX}"
-PLANETCURR="${PLANETDIR}/planet.${SUFFIX}"
-PLANETNEW="${PLANETDIR}/planet-new.${SUFFIX}"
-
-pyosmium-up-to-date -vvv -o "$PLANETNEW" "$PLANETCURR"
-retval=$?
-
-while [ $retval -eq 1 ]; do
-    mv "$PLANETCURR" "$PLANETPREV"
-    mv "$PLANETNEW" "$PLANETCURR"
-    pyosmium-up-to-date -vvv -o "$PLANETNEW" "$PLANETCURR"
-    retval=$?
-done
-
-if [ $retval -ne 0 ]; then
-    exit $retval
-fi
-
-# cleanup
-
-mv "$PLANETCURR" "$PLANETPREV"
-mv "$PLANETNEW" "$PLANETCURR"
index 4c00592b9b0c74684b09f48bde497e2f0cadbbc2..73a778bbaaa812c9bd33455683f0e05b0b41d3d7 100644 (file)
@@ -2,18 +2,30 @@
 
 # DO NOT EDIT - This file is being maintained by Chef
 
-exec >> /var/log/planet-update.log 2>&1
+# setup
 
-echo "Updating planet file..."
+SUFFIX="osh.pbf"
 
-/sbin/runuser -u planet -- /usr/local/bin/planet-update-file
+PLANETDIR="/var/lib/planet"
+PLANETPREV="${PLANETDIR}/planet-previous.${SUFFIX}"
+PLANETCURR="${PLANETDIR}/planet.${SUFFIX}"
+PLANETNEW="${PLANETDIR}/planet-new.${SUFFIX}"
 
-echo "Running jobs..."
-<% node[:planet][:current][:jobs].each_value do |job| -%>
+pyosmium-up-to-date -vvv -o "$PLANETNEW" "$PLANETCURR"
+retval=$?
 
-echo "Running '<%= job[:command] %>' as user '<%= job[:user] %>'..."
+while [ $retval -eq 1 ]; do
+    mv "$PLANETCURR" "$PLANETPREV"
+    mv "$PLANETNEW" "$PLANETCURR"
+    pyosmium-up-to-date -vvv -o "$PLANETNEW" "$PLANETCURR"
+    retval=$?
+done
 
-/sbin/runuser -u "<%= job[:user] %>" -- "<%= job[:command] %>"
-<% end -%>
+if [ $retval -ne 0 ]; then
+    exit $retval
+fi
 
-echo "Done."
+# cleanup
+
+mv "$PLANETCURR" "$PLANETPREV"
+mv "$PLANETNEW" "$PLANETCURR"
diff --git a/cookbooks/planet/templates/default/planet-update.logrotate.erb b/cookbooks/planet/templates/default/planet-update.logrotate.erb
deleted file mode 100644 (file)
index a3ca8ac..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-/var/log/planet-update.log {
-       compress
-       notifempty
-       missingok
-}
index dd79000ab118d2ebaa5df0199ec2d637cc80fb9d..5e468f00c57329830a46a19d0cb78eb62b82edd7 100644 (file)
@@ -10,4 +10,5 @@ depends           "accounts"
 depends           "apache"
 depends           "git"
 depends           "passenger"
+depends           "planet"
 depends           "ruby"
index ba25e998421f73076a071e4d3f5cf9e9441fdc32..e709545ad0e396a16b7ba4377e78d2ff1ac309ab 100644 (file)
@@ -23,6 +23,7 @@ include_recipe "accounts"
 include_recipe "apache"
 include_recipe "git"
 include_recipe "passenger"
+include_recipe "planet::current"
 include_recipe "ruby"
 
 package %w[
@@ -68,6 +69,25 @@ template "/etc/sudoers.d/taginfo" do
   mode "440"
 end
 
+systemd_service "taginfo-update@" do
+  description "Taginfo update for %i"
+  wants "planet-update.service"
+  after "planet-update.service"
+  exec_start "/srv/%i/bin/update"
+  user "taginfo"
+  sandbox :enable_network => true
+  read_write_paths [
+    "/srv/%i/data",
+    "/srv/%i/sources",
+    "/var/log/taginfo/%i"
+  ]
+end
+
+systemd_timer "taginfo-update@" do
+  description "Taginfo update for %i"
+  on_calendar "01:37"
+end
+
 node[:taginfo][:sites].each do |site|
   site_name = site[:name]
   site_aliases = Array(site[:aliases])
@@ -193,12 +213,8 @@ node[:taginfo][:sites].each do |site|
     directory "#{directory}/taginfo/web/public"
     variables :aliases => site_aliases
   end
-end
 
-template "/usr/local/bin/taginfo-update" do
-  source "taginfo-update.erb"
-  owner "root"
-  group "root"
-  mode "755"
-  variables :sites => node[:taginfo][:sites]
+  service "taginfo-update@#{site_name}.timer" do
+    action [:enable, :start]
+  end
 end
diff --git a/cookbooks/taginfo/templates/default/taginfo-update.erb b/cookbooks/taginfo/templates/default/taginfo-update.erb
deleted file mode 100644 (file)
index 0dd05b8..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/bin/sh
-
-# DO NOT EDIT - This file is being maintained by Chef
-
-<% @sites.each do |site| -%>
-<% if site[:directory] -%>
-<%= site[:directory] %>/bin/update
-<% else -%>
-/srv/<%= site[:name] %>/bin/update
-<% end -%>
-<% end -%>
diff --git a/roles/planet-current.rb b/roles/planet-current.rb
deleted file mode 100644 (file)
index 97f23d2..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-name "planet-current"
-description "Role applied to all servers needing an up to date planet file"
-
-default_attributes(
-  :accounts => {
-    :users => {
-      :planet => {
-        :status => :role
-      }
-    }
-  }
-)
-
-run_list(
-  "recipe[planet::current]"
-)
index c7d3d5b51cd7ecdf2905d385e266be97fae9cd10..40bffdce2f48f91b0e45504523325a9e9712a081 100644 (file)
@@ -26,16 +26,6 @@ default_attributes(
   :passenger => {
     :max_pool_size => 50
   },
-  :planet => {
-    :current => {
-      :jobs => {
-        :taginfo => {
-          :command => "/usr/local/bin/taginfo-update",
-          :user => "taginfo"
-        }
-      }
-    }
-  },
   :taginfo => {
     :sites => [
       {
@@ -51,6 +41,5 @@ default_attributes(
 )
 
 run_list(
-  "role[planet-current]",
   "recipe[taginfo]"
 )