From 4b21efe6b2a7bd1b631be972d175a92df329d41a 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 | 10 ++++------ 1 file changed, 4 insertions(+), 6 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..f08c52d 100755 --- a/images/fcos-bastion-image/root/usr/bin/clean-registries.sh +++ b/images/fcos-bastion-image/root/usr/bin/clean-registries.sh @@ -21,15 +21,13 @@ 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 + if [ "$disk_use" -gt 50 ]; then rm -rf /opt/registry-"${port}"/data/docker/registry/v2/repositories/* - 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}" + fi + if [ "$disk_use" -gt 40 ]; then podman exec registry-"${port}" /bin/registry garbage-collect /etc/docker/registry/config.yml - sed -i -e '/readonly/{n;s/enabled:.*/enabled: false/;}' /opt/registry-"${port}"/config.yaml - systemctl restart registry@"${port}".service fi + wait_for_container_running registry-"${port}" done exit 0