From 1f9242bfcccc128420603f191d95d6b4b36380be Mon Sep 17 00:00:00 2001 From: Varik Matevosyan Date: Wed, 24 Jul 2024 17:08:02 +0400 Subject: [PATCH] add query to remove dangling docker images --- migrate/20240724_lantern_doctor_queries.rb | 12 ++++++++++++ rhizome/lantern/bin/doctor/run_query | 9 +++++++++ 2 files changed, 21 insertions(+) create mode 100644 migrate/20240724_lantern_doctor_queries.rb diff --git a/migrate/20240724_lantern_doctor_queries.rb b/migrate/20240724_lantern_doctor_queries.rb new file mode 100644 index 000000000..f904c3988 --- /dev/null +++ b/migrate/20240724_lantern_doctor_queries.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +Sequel.migration do + up do + # check duplicate sources for embedding jobs + run "INSERT INTO lantern_doctor_query (id, name, db_name, schedule, condition, fn_label, type, severity, response_type) + VALUES ('0e5fab85-71f6-89b7-96cf-f1e8e1074389', 'Cleanup dangling docker images', 'postgres', '0 9 * * *', 'unknown', 'remove_dangling_images', 'system', 'error', 'rows')" + + # Create semaphores for all lantern doctors to sync system queries + run "INSERT INTO semaphore (id, strand_id, name) SELECT gen_random_uuid(), id, 'sync_system_queries' FROM strand s WHERE s.prog = 'Lantern::LanternDoctorNexus'" + end +end diff --git a/rhizome/lantern/bin/doctor/run_query b/rhizome/lantern/bin/doctor/run_query index 77aa39f1d..72d69b971 100755 --- a/rhizome/lantern/bin/doctor/run_query +++ b/rhizome/lantern/bin/doctor/run_query @@ -141,6 +141,15 @@ SQL output end + + def self.remove_dangling_images(_db, _query_user) + r("sudo docker image prune -af") + "" + end + + def self.remove_dangling_index_files(_db, _query_user) + r("sudo find /var/lib/lantern-data/data/ -name 'ldb-index*' -type f -mmin +240 -delete >/tmp/ldb-index-cleanup-logs 2>&1 && echo "" || cat /tmp/ldb-index-cleanup-logs").chomp.strip + end end exit_code = 0