diff options
author | kris <kris@FreeBSD.org> | 2004-03-08 01:56:16 +0000 |
---|---|---|
committer | kris <kris@FreeBSD.org> | 2004-03-08 01:56:16 +0000 |
commit | 353c1d8e52d1dec726e52b822f0ed01a1b2c7b7f (patch) | |
tree | 8c9a0d9f7835aaf4e0c16de2c9e3ec4a978a1d8b | |
parent | 7e1beb210cecb193e2972dff1a1da8af19ffbef5 (diff) | |
download | FreeBSD-ports-353c1d8e52d1dec726e52b822f0ed01a1b2c7b7f.zip FreeBSD-ports-353c1d8e52d1dec726e52b822f0ed01a1b2c7b7f.tar.gz |
To be run on the client, this script looks for chroot directories that have not been
used in 20 minutes, as well as directories listed as 'in use' that have not been touched
in 24 hours (corresponding to port builds that have timed out or shut down uncleanly)
and prunes them to reclaim space. This is intended to be run as a cron job.
-rwxr-xr-x | Tools/portbuild/scripts/cleanup-chroots | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/Tools/portbuild/scripts/cleanup-chroots b/Tools/portbuild/scripts/cleanup-chroots new file mode 100755 index 0000000..4caae9c --- /dev/null +++ b/Tools/portbuild/scripts/cleanup-chroots @@ -0,0 +1,48 @@ +#!/bin/sh +# +# To be run on the client, this script looks for chroot directories that have not been +# used in 20 minutes, as well as directories listed as 'in use' that have not been touched +# in 24 hours (corresponding to port builds that have timed out or shut down uncleanly) +# and prunes them to reclaim space. + +pb=/var/portbuild +arch=$(cat /etc/arch) + +. ${pb}/${arch}/portbuild.conf + +old=$(find ${scratchdir}/*/chroot/* -prune -mmin +20 2> /dev/null) + +if [ -z "${old}" ]; then + exit 0 +fi + +# Prune out chroots with active builds +for i in ${old}; do + if [ ! -d ${i}/used ]; then + old2="${i} ${old2}" + # Also remove "in use" chroots that were set up more than 24 hours ago + elif [ ! -z "`find $i/used -prune -mmin +1440`" ]; then + echo "cleanup-chroots: Found old files on `hostname`:" + ls -l ${i}/tmp ${i}/used + echo "${i} allegedly in use but >24 hours old" + old2="${i} ${old2}" + fi +done + +if [ -z "${old2}" ]; then + exit 0 +fi + +# cleanup old NFS and devfs mounts +for i in ${old2}; do + mounts=$(mount | grep $i | awk '{print $3}') + if [ ! -z "${mounts}" ]; then + umount -f ${mounts} + fi +done + +mkdir -p ${scratchdir}/old +mv ${old2} ${scratchdir}/old +rm -rf ${scratchdir}/old 2> /dev/null +chflags -R noschg ${scratchdir}/old +rm -rf ${scratchdir}/old |