Skip to content

Commit

Permalink
clean registry when disk util over 40 percent
Browse files Browse the repository at this point in the history
  • Loading branch information
zniu1011 committed Sep 12, 2024
1 parent 74a6367 commit 4a8e4ad
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions images/fcos-bastion-image/root/usr/bin/clean-registries.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 60 ]; 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 50 ]; 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

0 comments on commit 4a8e4ad

Please sign in to comment.