From 1198cc96af6115a360c08e95ecb7654c83f944ef Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Tue, 21 Jul 2020 18:42:33 +0100 Subject: [PATCH 1/1] Replace cron.d templates with cron_d resources --- cookbooks/planet/recipes/current.rb | 10 +-- cookbooks/planet/recipes/default.rb | 17 +++-- cookbooks/planet/recipes/dump.rb | 10 +-- cookbooks/planet/recipes/notes.rb | 20 ++++-- cookbooks/planet/recipes/replication.rb | 70 +++++++++++++++++-- .../default/old-planet-file-cleanup.cron.erb | 4 -- .../default/planet-dump-mirror-cron.erb | 3 - .../default/planet-notes-dump.cron.erb | 5 -- .../templates/default/planet-update.cron.erb | 3 - .../templates/default/replication.cron.erb | 16 ----- 10 files changed, 97 insertions(+), 61 deletions(-) delete mode 100644 cookbooks/planet/templates/default/old-planet-file-cleanup.cron.erb delete mode 100644 cookbooks/planet/templates/default/planet-dump-mirror-cron.erb delete mode 100644 cookbooks/planet/templates/default/planet-notes-dump.cron.erb delete mode 100644 cookbooks/planet/templates/default/planet-update.cron.erb delete mode 100644 cookbooks/planet/templates/default/replication.cron.erb diff --git a/cookbooks/planet/recipes/current.rb b/cookbooks/planet/recipes/current.rb index 20c77b732..6242559eb 100644 --- a/cookbooks/planet/recipes/current.rb +++ b/cookbooks/planet/recipes/current.rb @@ -52,11 +52,11 @@ remote_file "/var/lib/planet/planet.pbf" do not_if { ENV["TEST_KITCHEN"] } end -template "/etc/cron.d/planet-update" do - source "planet-update.cron.erb" - owner "root" - group "root" - mode 0o644 +cron_d "planet-update" do + minute "17" + hour "1" + user "root" + command "/usr/local/bin/planet-update" end template "/etc/logrotate.d/planet-update" do diff --git a/cookbooks/planet/recipes/default.rb b/cookbooks/planet/recipes/default.rb index b72d4d1c5..4ea86b7ac 100644 --- a/cookbooks/planet/recipes/default.rb +++ b/cookbooks/planet/recipes/default.rb @@ -26,10 +26,6 @@ package %w[ php-cli ] -file "/etc/cron.d/planet" do - action :delete -end - remote_directory "/store/planet#html" do path "/store/planet" source "html" @@ -125,9 +121,12 @@ template "/usr/local/bin/old-planet-file-cleanup" do mode 0o755 end -template "/etc/cron.d/old-planet-file-cleanup" do - source "old-planet-file-cleanup.cron.erb" - owner "root" - group "root" - mode 0o644 +cron_d "old-planet-file-cleanup" do + comment "run this on the first monday of the month at 3:44am" + minute "44" + hour "3" + day "1-7" + user "www-data" + command "test $(date +\%u) -eq 1 && /usr/local/bin/old-planet-file-cleanup --debug" + mailto "zerebubuth@gmail.com" end diff --git a/cookbooks/planet/recipes/dump.rb b/cookbooks/planet/recipes/dump.rb index d873a9036..1d1d170bf 100644 --- a/cookbooks/planet/recipes/dump.rb +++ b/cookbooks/planet/recipes/dump.rb @@ -120,9 +120,9 @@ systemd_service "planetdump@" do no_new_privileges true end -template "/etc/cron.d/planet-dump-mirror" do - source "planet-dump-mirror-cron.erb" - owner "root" - group "root" - mode 0o644 +cron_d "planet-dump-mirror" do + minute "*/10" + user "www-data" + command "/usr/local/bin/planet-mirror-redirect-update" + mailto "horntail-www-data-cron@firefishy.com" end diff --git a/cookbooks/planet/recipes/notes.rb b/cookbooks/planet/recipes/notes.rb index 68a548b15..662abe770 100644 --- a/cookbooks/planet/recipes/notes.rb +++ b/cookbooks/planet/recipes/notes.rb @@ -50,9 +50,19 @@ template "/usr/local/bin/planet-notes-dump" do variables :password => db_passwords["planetdump"] end -template "/etc/cron.d/planet-notes-dump" do - source "planet-notes-dump.cron.erb" - owner "root" - group "root" - mode 0o644 +cron_d "planet-notes-dump" do + minute "0" + hour "3" + user "www-data" + command "/usr/local/bin/planet-notes-dump" + mailto "grant-smaug@firefishy.com" +end + +cron_d "planet-notes-cleanup" do + comment "Delete Planet Notes dump files older than 8 days" + minute "10" + hour "8" + user "www-data" + command "find /store/planet/notes/20??/ -maxdepth 1 -type f -iname 'planet-notes-??????.osn*' -printf '\%T@ \%p\n' | sort -k 1nr | sed 's/^[^ ]* //' | tail -n +17 | xargs -r rm -f" + mailto "grant-smaug@firefishy.com" end diff --git a/cookbooks/planet/recipes/replication.rb b/cookbooks/planet/recipes/replication.rb index f1be1d0d0..3fbfd7377 100644 --- a/cookbooks/planet/recipes/replication.rb +++ b/cookbooks/planet/recipes/replication.rb @@ -200,14 +200,72 @@ link "/var/lib/replication/day/data" do end if node[:planet][:replication] == "enabled" - template "/etc/cron.d/replication" do - source "replication.cron.erb" - owner "root" - group "root" - mode 0o644 + cron_d "users-agreed" do + minute "0" + hour "7" + user "planet" + command "/usr/local/bin/users-agreed" + mailto "zerebubuth@gmail.com" + end + + cron_d "users-deleted" do + minute "0" + hour "17" + user "planet" + command "/usr/local/bin/users-deleted" + mailto "zerebubuth@gmail.com" + end + + cron_d "replication-changesets" do + user "planet" + command "/usr/local/bin/replicate-changesets /etc/replication/changesets.conf" + mailto "zerebubuth@gmail.com" + end + + cron_d "replication-minutely" do + user "planet" + command "/usr/local/bin/osmosis -q --replicate-apidb authFile=/etc/replication/auth.conf validateSchemaVersion=false --write-replication workingDirectory=/store/planet/replication/minute" + mailto "brett@bretth.com" + environment "LD_PRELOAD" => "/opt/flush/flush.so" + end + + cron_d "replication-hourly" do + minute "2,7,12,17" + user "planet" + command "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/hour" + mailto "brett@bretth.com" + environment "LD_PRELOAD" => "/opt/flush/flush.so" + end + + cron_d "replication-daily" do + minute "5,10,15,20" + user "planet" + command "/usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/day" + mailto "brett@bretth.com" + environment "LD_PRELOAD" => "/opt/flush/flush.so" end else - file "/etc/cron.d/replication" do + cron_d "users-agreed" do + action :delete + end + + cron_d "users-deleted" do + action :delete + end + + cron_d "replication-changesets" do + action :delete + end + + cron_d "replication-minutely" do + action :delete + end + + cron_d "replication-hourly" do + action :delete + end + + cron_d "replication-daily" do action :delete end end diff --git a/cookbooks/planet/templates/default/old-planet-file-cleanup.cron.erb b/cookbooks/planet/templates/default/old-planet-file-cleanup.cron.erb deleted file mode 100644 index 4c880b4b7..000000000 --- a/cookbooks/planet/templates/default/old-planet-file-cleanup.cron.erb +++ /dev/null @@ -1,4 +0,0 @@ -# DO NOT EDIT - This file is being maintained by Chef -MAILTO=zerebubuth@gmail.com -# run this on the first monday of the month at 3:44am -44 3 1-7 * * www-data test $(date +\%u) -eq 1 && /usr/local/bin/old-planet-file-cleanup --debug diff --git a/cookbooks/planet/templates/default/planet-dump-mirror-cron.erb b/cookbooks/planet/templates/default/planet-dump-mirror-cron.erb deleted file mode 100644 index d635c107e..000000000 --- a/cookbooks/planet/templates/default/planet-dump-mirror-cron.erb +++ /dev/null @@ -1,3 +0,0 @@ -# DO NOT EDIT - This file is being maintained by Chef -MAILTO=horntail-www-data-cron@firefishy.com -*/10 * * * * www-data /usr/local/bin/planet-mirror-redirect-update diff --git a/cookbooks/planet/templates/default/planet-notes-dump.cron.erb b/cookbooks/planet/templates/default/planet-notes-dump.cron.erb deleted file mode 100644 index 3c5709af1..000000000 --- a/cookbooks/planet/templates/default/planet-notes-dump.cron.erb +++ /dev/null @@ -1,5 +0,0 @@ -MAILTO=grant-smaug@firefishy.com -0 3 * * * www-data /usr/local/bin/planet-notes-dump - -#Delete Planet Notes dump files older than 8 days -10 8 * * * www-data find /store/planet/notes/20??/ -maxdepth 1 -type f -iname 'planet-notes-??????.osn*' -printf '\%T@ \%p\n' | sort -k 1nr | sed 's/^[^ ]* //' | tail -n +17 | xargs -r rm -f diff --git a/cookbooks/planet/templates/default/planet-update.cron.erb b/cookbooks/planet/templates/default/planet-update.cron.erb deleted file mode 100644 index 5a9f6f768..000000000 --- a/cookbooks/planet/templates/default/planet-update.cron.erb +++ /dev/null @@ -1,3 +0,0 @@ -# DO NOT EDIT - This file is being maintained by Chef - -17 1 * * * root /usr/local/bin/planet-update diff --git a/cookbooks/planet/templates/default/replication.cron.erb b/cookbooks/planet/templates/default/replication.cron.erb deleted file mode 100644 index 80d7184ee..000000000 --- a/cookbooks/planet/templates/default/replication.cron.erb +++ /dev/null @@ -1,16 +0,0 @@ -# DO NOT EDIT - This file is being maintained by Chef - -TZ=UTC - -MAILTO=zerebubuth@gmail.com - -0 7 * * * planet /usr/local/bin/users-agreed -0 17 * * * planet /usr/local/bin/users-deleted -* * * * * planet /usr/local/bin/replicate-changesets /etc/replication/changesets.conf - -MAILTO=brett@bretth.com -LD_PRELOAD=/opt/flush/flush.so - -* * * * * planet /usr/local/bin/osmosis -q --replicate-apidb authFile=/etc/replication/auth.conf validateSchemaVersion=false --write-replication workingDirectory=/store/planet/replication/minute -2,7,12,17 * * * * planet /usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/hour -5,10,15,20 * * * * planet /usr/local/bin/osmosis -q --merge-replication-files workingDirectory=/var/lib/replication/day -- 2.43.2