From c5240e80f7bb5aa517f1319eb2f1515d55f2ccc7 Mon Sep 17 00:00:00 2001 From: Zhenying Niu Date: Thu, 12 Sep 2024 21:22:38 +0800 Subject: [PATCH] clean registry when disk util over 40 percent --- .../root/usr/bin/clean-registries.sh | 11 +++++++++-- .../root/usr/bin/gen_registry_file.sh | 5 ++++- .../usr/lib/systemd/system/clean-registries.timer | 4 ++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/images/fcos-bastion-image/root/usr/bin/clean-registries.sh b/images/fcos-bastion-image/root/usr/bin/clean-registries.sh index e78c636..08c9876 100755 --- a/images/fcos-bastion-image/root/usr/bin/clean-registries.sh +++ b/images/fcos-bastion-image/root/usr/bin/clean-registries.sh @@ -21,14 +21,21 @@ wait_for_container_running() { mapfile -t ports < <(systemctl list-units 'registry@*' --no-pager --quiet | awk -F'[@.]' '{print $2}') for port in "${ports[@]}"; do disk_use=$(df /opt/registry-"${port}" --output='pcent' | grep -o '[0-9]*') - if [ "$disk_use" -gt 85 ]; then - rm -rf /opt/registry-"${port}"/data/docker/registry/v2/repositories/* + if [ "$disk_use" -gt 50 ]; then + for dir in `find /opt/registry-"${port}"/data/docker/registry/v2/repositories/ -maxdepth 1 -type d -mtime +1`; do + find ${dir}/release/_manifests/tags/ -name link -type f -exec rm -f {} \; + done + sed -i -e '/delete/{n;s/enabled:.*/enabled: true/;}' /opt/registry-"${port}"/config.yaml sed -i -e '/readonly/{n;s/enabled:.*/enabled: true/;}' /opt/registry-"${port}"/config.yaml systemctl restart registry@"${port}".service wait_for_container_running registry-"${port}" podman exec registry-"${port}" /bin/registry garbage-collect /etc/docker/registry/config.yml + sed -i -e '/delete/{n;s/enabled:.*/enabled: false/;}' /opt/registry-"${port}"/config.yaml sed -i -e '/readonly/{n;s/enabled:.*/enabled: false/;}' /opt/registry-"${port}"/config.yaml systemctl restart registry@"${port}".service + for dir in `find /opt/registry-"${port}"/data/docker/registry/v2/repositories/ -maxdepth 1 -type d -mtime +1`; do + rm -rf ${dir} + done fi done diff --git a/images/fcos-bastion-image/root/usr/bin/gen_registry_file.sh b/images/fcos-bastion-image/root/usr/bin/gen_registry_file.sh index 1c72dfe..5df1722 100755 --- a/images/fcos-bastion-image/root/usr/bin/gen_registry_file.sh +++ b/images/fcos-bastion-image/root/usr/bin/gen_registry_file.sh @@ -32,11 +32,14 @@ http: key: /certs/domain.key storage: delete: - enabled: true + enabled: false cache: blobdescriptor: inmemory filesystem: rootdirectory: /var/lib/registry + maintenance: + readonly: + enabled: false auth: htpasswd: realm: Registry Realm diff --git a/images/fcos-bastion-image/root/usr/lib/systemd/system/clean-registries.timer b/images/fcos-bastion-image/root/usr/lib/systemd/system/clean-registries.timer index 0fe47f8..b7a162a 100644 --- a/images/fcos-bastion-image/root/usr/lib/systemd/system/clean-registries.timer +++ b/images/fcos-bastion-image/root/usr/lib/systemd/system/clean-registries.timer @@ -1,8 +1,8 @@ [Unit] -Description=Timer to cleanup mirrored registries caches on boot +Description=Timer to cleanup mirrored registries caches on boot and 6 hours once [Timer] OnBootSec=5min -OnCalendar=*-*-* *:00:00 +OnCalendar=*-*-* */6:00:00 [Install] WantedBy=timers.target