From 2b5b3983f437e71eb64e4eb9e9174bb6d6388489 Mon Sep 17 00:00:00 2001 From: Joseph Graham Date: Mon, 29 May 2017 11:06:59 +0100 Subject: Made it clean up old torrents less frequently, to save resources. --- cron-jobs/make_repo_torrents | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/cron-jobs/make_repo_torrents b/cron-jobs/make_repo_torrents index b130de1..d513f6e 100755 --- a/cron-jobs/make_repo_torrents +++ b/cron-jobs/make_repo_torrents @@ -15,7 +15,7 @@ # along with this program. If not, see . # This script finds any updated packages and calls -# `make_indivudual_torrent' for each of them. +# `make_indivudual_torrent' for each of them. Run every hour from cron. username=$( id -un ) @@ -67,15 +67,22 @@ do fi done < "${pkgfilelist}" -# For torrents older than 1 year, we check if it's package still exists, else clean it up -find -H "${torrent_location}" -mtime +365 -name '*.torrent' -type f | - while read oldtorrent - do - oldtorrentnm="${oldtorrent##*/}" - correspackagenm="${oldtorrentnm%.torrent}" +# For torrents older than 1 year, we check if it's package still +# exists, else clean it up This shouldn't be done every hour, but it +# is good for it to be in this cronjob so it can re-use the +# $pkgfilelist we made earlier. So we do it with a 1-in-30 +# probability. +if ! (( $(shuf -e {0..29} | head -1) )) +then + find -H "${torrent_location}" -mtime +365 -name '*.torrent' -type f | + while read oldtorrent + do + oldtorrentnm="${oldtorrent##*/}" + correspackagenm="${oldtorrentnm%.torrent}" - grep "${correspackagenm}" "${pkgfilelist}" &> /dev/null || rm "${oldtorrent}" - done + grep "${correspackagenm}" "${pkgfilelist}" &> /dev/null || rm "${oldtorrent}" + done +fi if [[ "${username}" == root ]] then -- cgit v1.2.3