copr-dist-git: run the cleanup cron twice per month

https://github.com/fedora-copr/copr/issues/3020
This commit is contained in:
Pavel Raiskup 2023-12-17 11:34:50 +01:00
parent 445dd11353
commit 5766ff851c
3 changed files with 68 additions and 4 deletions

View file

@ -4,6 +4,11 @@
# When you uncomment this, all the sources from the dist-git lookaside cache
# will be periodically unlinked, except for those sources mentioned in the
# last commits of the git repo branches.
# We run this on Sunday 4.22 every week (default cron weekly timing). To run
# this bi-weekly, we have to skip every second run.
/usr/local/bin/test-too-soon "cleaning-dist-git-data-volume" 10 && exit 0
runuser -c 'dist-git-clear-tarballs.py' - copr-dist-git
# From time to time assure that the CGIT caches are consistent, and that the

View file

@ -0,0 +1,38 @@
#! /bin/bash
# Return non-zero exit status if this script has been run before more than N
# days (or never). Arguments are $ID (word or description) and number of days.
# Use like 'test-not-before last-dist-git-cleanup-run 10 || do_something'
id=$1
days=$2
file=/var/tmp/
umask 0077
dir="/var/tmp/test-too-soon-script-$(id -u -n)"
file=$dir/$id
lock=$file.lock
coeficient="24*3600"
log() { echo >&2 "LOG: $id: $*"; }
mkdir -p "$dir"
(
flock 9
stamp=$(date +%s)
if test ! -e "$file"; then
log "running for the first time"
echo "$stamp" > "$file"
exit 1
fi
old_stamp=$(cat "$file")
last=$(( (stamp - old_stamp) / ("$coeficient") ))
if test $(( stamp - old_stamp )) -ge $(( days * ("$coeficient") )); then
log "Last run $old_stamp, before $last days, running."
echo "$stamp" > "$file"
exit 1
else
log "Last run $old_stamp, before $last days, skipping."
exit 0
fi
) 9>"$lock"
# no more tasks, exit status inherited from sub-shell

View file

@ -133,12 +133,33 @@
- name: install .config/copr for copr-dist-git user (required for pruning)
template: src="copr.conf" dest="/home/copr-dist-git/.config/copr" owner=copr-dist-git group=copr-dist-git
- name: install the helper cron scripts
copy:
src: "{{ item }}"
dest: "/usr/local/bin/{{ item }}"
mode: '0755'
tags:
- config
- cron
loop:
- test-too-soon
- name: install copr-dist-git.daily cron file
copy: src="copr-dist-git.daily" dest="/etc/cron.daily/copr-dist-git" mode=755
tags:
- config
- config
- cron
- name: install copr-dist-git.monthly cron file
copy: src="copr-dist-git.monthly" dest="/etc/cron.monthly/copr-dist-git" mode=755
- name: install copr-dist-git.weekly cron file
copy: src="copr-dist-git.weekly" dest="/etc/cron.weekly/copr-dist-git" mode=755
tags:
- config
- config
- cron
- name: drop monthly cron job
file:
path: /etc/cron.weekly/copr-dist-git
state: absent
tags:
- config
- cron