From 9cb89866d2aea9415aaebc184a5ffd5c467899d5 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Mon, 28 Nov 2022 19:13:56 +0000 Subject: [PATCH] Convert taginfo update to use a systemd timer --- cookbooks/planet/attributes/default.rb | 2 -- cookbooks/planet/recipes/current.rb | 28 ++++++----------- .../templates/default/planet-update-file.erb | 31 ------------------- .../templates/default/planet-update.erb | 30 ++++++++++++------ .../default/planet-update.logrotate.erb | 5 --- cookbooks/taginfo/metadata.rb | 1 + cookbooks/taginfo/recipes/default.rb | 30 +++++++++++++----- .../templates/default/taginfo-update.erb | 11 ------- roles/planet-current.rb | 16 ---------- roles/taginfo.rb | 11 ------- 10 files changed, 54 insertions(+), 111 deletions(-) delete mode 100644 cookbooks/planet/templates/default/planet-update-file.erb delete mode 100644 cookbooks/planet/templates/default/planet-update.logrotate.erb delete mode 100644 cookbooks/taginfo/templates/default/taginfo-update.erb delete mode 100644 roles/planet-current.rb diff --git a/cookbooks/planet/attributes/default.rb b/cookbooks/planet/attributes/default.rb index f01d8acc4..7c8a60466 100644 --- a/cookbooks/planet/attributes/default.rb +++ b/cookbooks/planet/attributes/default.rb @@ -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] = {} diff --git a/cookbooks/planet/recipes/current.rb b/cookbooks/planet/recipes/current.rb index c7175e6e1..517123f59 100644 --- a/cookbooks/planet/recipes/current.rb +++ b/cookbooks/planet/recipes/current.rb @@ -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 index 73a778bba..000000000 --- a/cookbooks/planet/templates/default/planet-update-file.erb +++ /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" diff --git a/cookbooks/planet/templates/default/planet-update.erb b/cookbooks/planet/templates/default/planet-update.erb index 4c00592b9..73a778bba 100644 --- a/cookbooks/planet/templates/default/planet-update.erb +++ b/cookbooks/planet/templates/default/planet-update.erb @@ -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 index a3ca8acec..000000000 --- a/cookbooks/planet/templates/default/planet-update.logrotate.erb +++ /dev/null @@ -1,5 +0,0 @@ -/var/log/planet-update.log { - compress - notifempty - missingok -} diff --git a/cookbooks/taginfo/metadata.rb b/cookbooks/taginfo/metadata.rb index dd79000ab..5e468f00c 100644 --- a/cookbooks/taginfo/metadata.rb +++ b/cookbooks/taginfo/metadata.rb @@ -10,4 +10,5 @@ depends "accounts" depends "apache" depends "git" depends "passenger" +depends "planet" depends "ruby" diff --git a/cookbooks/taginfo/recipes/default.rb b/cookbooks/taginfo/recipes/default.rb index ba25e9984..e709545ad 100644 --- a/cookbooks/taginfo/recipes/default.rb +++ b/cookbooks/taginfo/recipes/default.rb @@ -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 index 0dd05b847..000000000 --- a/cookbooks/taginfo/templates/default/taginfo-update.erb +++ /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 index 97f23d247..000000000 --- a/roles/planet-current.rb +++ /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]" -) diff --git a/roles/taginfo.rb b/roles/taginfo.rb index c7d3d5b51..40bffdce2 100644 --- a/roles/taginfo.rb +++ b/roles/taginfo.rb @@ -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]" ) -- 2.39.5