svn commit: r222470 - projects/portbuild/scripts
Mark Linimon
linimon at FreeBSD.org
Mon May 30 02:02:16 UTC 2011
Author: linimon (doc,ports committer)
Date: Mon May 30 02:02:15 2011
New Revision: 222470
URL: http://svn.freebsd.org/changeset/base/222470
Log:
Parameterize; make more verbose in the non-VERBOSE case so you can actually
see what is being deleted.
Modified:
projects/portbuild/scripts/cleanup-chroots
Modified: projects/portbuild/scripts/cleanup-chroots
==============================================================================
--- projects/portbuild/scripts/cleanup-chroots Sun May 29 22:37:23 2011 (r222469)
+++ projects/portbuild/scripts/cleanup-chroots Mon May 30 02:02:15 2011 (r222470)
@@ -9,7 +9,13 @@
pbd=${PORTBUILD_DATA:-/var/portbuild}
-VERBOSE=1
+# XXX TODO promote
+# all times are in minutes
+REMOVE_EMPTY_BUILD_TIME=10080
+REMOVE_INUSE_CHROOT_TIME=7200
+REMOVE_NOTINUSE_CHROOT_TIME=60
+
+#VERBOSE=1
kill_procs()
{
@@ -23,6 +29,7 @@ kill_procs()
ps -p $pids
kill -KILL ${pids} 2> /dev/null
sleep 2
+ echo
fi
done
}
@@ -50,6 +57,11 @@ cleanup_all() {
mounts=$(mount | grep ${chroot} | awk '{print $3}')
if [ ! -z "${mounts}" ]; then
+ if [ $VERBOSE ]; then
+ echo "trying to kill off mounts:"
+ echo ${mounts}
+ echo
+ fi
for j in ${mounts}; do
umount ${j} || cleanup_mount ${j}
done
@@ -72,14 +84,20 @@ arch=$(uname -m)
. ${pbd}/${arch}/portbuild.$(hostname)
if [ "${use_zfs}" = "1" ]; then
- old_chroots=$(find ${scratchdir}/*/*/* -prune -mmin +60 2> /dev/null)
+ old_chroots=$(find ${scratchdir}/*/*/* -prune -mmin +${REMOVE_NOTINUSE_CHROOT_TIME} 2> /dev/null)
else
- old_chroots=$(find ${scratchdir}/*/*/chroot/* -prune -mmin +60 2> /dev/null)
+ old_chroots=$(find ${scratchdir}/*/*/chroot/* -prune -mmin +${REMOVE_NOTINUSE_CHROOT_TIME} 2> /dev/null)
fi
-if [ $VERBOSE ]; then
+if [ ! -z "${old_chroots}" ]; then
echo "non-empty chroots > 1 hr old found on $(hostname):"
echo ${old_chroots}
+ echo
+else
+ if [ $VERBOSE ]; then
+ echo "no non-empty chroots > 1 hr old found on $(hostname)."
+ echo
+ fi
fi
if [ ! -z "${old_chroots}" ]; then
@@ -87,19 +105,26 @@ if [ ! -z "${old_chroots}" ]; then
for chroot in ${old_chroots}; do
if [ ! -d ${chroot}/used ]; then
stale_chroots="${chroot} ${stale_chroots}"
- # Also flag "in use" chroots that were set up more than 5 days ago
- elif [ ! -z "`find ${chroot}/used -prune -mmin +7200`" ]; then
+ # Also flag "in use" chroots that were set up more than N days ago
+ elif [ ! -z "`find ${chroot}/used -prune -mmin +${REMOVE_INUSE_CHROOT_TIME}`" ]; then
echo "cleanup-chroots: Found old files on $(hostname):"
ls -l ${chroot}/tmp ${chroot}/used
- echo "${chroot} allegedly in use but >5 days old"
+ echo "${chroot} allegedly in use but > N days old"
stale_chroots="${chroot} ${stale_chroots}"
+ echo
fi
done
fi
-if [ $VERBOSE ]; then
- echo "non-empty, >1 hr old stale chroots found on $(hostname):"
+if [ ! -z "${stale_chroots}" ]; then
+ echo "non-empty, > 1 hr old stale chroots found on $(hostname):"
echo ${stale_chroots}
+ echo
+else
+ if [ $VERBOSE ]; then
+ echo "no non-empty, > 1 hr old stale chroots found on $(hostname)."
+ echo
+ fi
fi
# save off non-empty, stale chroots for possible examination
@@ -124,9 +149,10 @@ fi
# now look for empty stale builds
if [ "${use_zfs}" = "1" ]; then
- builds=$(find ${scratchdir}/[0-9]*/* -prune -mmin +7200 2> /dev/null)
+ # XXX MCL zfs case not yet tested; is this the right command?
+ builds=$(find ${scratchdir}/[0-9]*/* -prune -mmin +${REMOVE_EMPTY_BUILD_TIME} 2> /dev/null)
else
- builds=$(find ${scratchdir}/[0-9]*/* -prune -mmin +7200 2> /dev/null)
+ builds=$(find ${scratchdir}/[0-9]*/* -prune -mmin +${REMOVE_EMPTY_BUILD_TIME} 2> /dev/null)
fi
for build in ${builds}; do
@@ -135,9 +161,15 @@ for build in ${builds}; do
fi
done
-if [ $VERBOSE ]; then
+if [ ! -z "${stale_builds}" ]; then
echo "empty stale builds found on $(hostname):"
echo ${stale_builds}
+ echo
+else
+ if [ $VERBOSE ]; then
+ echo "no empty stale builds found on $(hostname)."
+ echo
+ fi
fi
# cleanup old NFS and devfs mounts for vanished chroots in stale builds
@@ -145,6 +177,11 @@ if [ ! -z "${stale_builds}" ]; then
for build in ${stale_builds}; do
# XXX MCL HACK! what I really want is "give me the next 2 subdirs after $build"
mounts=$(mount | grep "${build}" | awk '{print $3}' | grep -E "/dev$")
+ if [ $VERBOSE ]; then
+ echo "suspected stale mounts on $(hostname):"
+ echo ${mounts}
+ echo
+ fi
if [ ! -z "${mounts}" ]; then
for mount in ${mounts}; do
target=`echo ${mount} | sed -e "s@/dev@@"`
@@ -154,4 +191,3 @@ if [ ! -z "${stale_builds}" ]; then
rm -rf ${build}
done
fi
-
More information about the svn-src-projects
mailing list