From owner-svn-src-projects@FreeBSD.ORG Mon May 30 02:02:16 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 50FE6106566B; Mon, 30 May 2011 02:02:16 +0000 (UTC) (envelope-from linimon@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 376868FC0A; Mon, 30 May 2011 02:02:16 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p4U22GPA055412; Mon, 30 May 2011 02:02:16 GMT (envelope-from linimon@svn.freebsd.org) Received: (from linimon@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p4U22GNM055410; Mon, 30 May 2011 02:02:16 GMT (envelope-from linimon@svn.freebsd.org) Message-Id: <201105300202.p4U22GNM055410@svn.freebsd.org> From: Mark Linimon Date: Mon, 30 May 2011 02:02:16 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r222470 - projects/portbuild/scripts X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 May 2011 02:02:16 -0000 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 -