Fix vuserdel to unmount all mountpoints before deleting vserver
[util-vserver.git] / scripts / vuserdel
index d24c479..5cc663e 100755 (executable)
@@ -4,7 +4,7 @@
 #
 # Copyright (c) 2004  The Trustees of Princeton University (Trustees).
 #
-# $Id: vuserdel,v 1.4 2004/10/20 21:45:43 mef Exp $
+# $Id: vuserdel,v 1.6 2004/11/23 14:47:35 mlhuang Exp $
 #
 
 : ${UTIL_VSERVER_VARS:=$(dirname $0)/util-vserver-vars}
@@ -23,8 +23,22 @@ usage()
 [ -z "$1" ] && usage
 NAME=$1
 
-# stop vserver
-vserver $NAME stop
+# read config file to get context ID
+. /etc/vservers/$NAME.conf
+CTX=$S_CONTEXT
+
+# don't bother stopping gracefully, just kill all the processes
+$SBINDIR/chcontext --silent --secure --ctx $CTX $PKGLIBDIR/vserverkillall
+
+# unmount any directories in vserver that are mount points
+for d in `sed -ne "s%^[^ ]* \($VROOTDIR/$NAME/[^ ]*\) .*%\1%p" /proc/mounts`
+do
+        # use echo -e to turn escaped whitespace back into regular chars
+        # be careful about embedded backquotes here (i think we're safe)
+        dir=`echo -e "$d"`
+        echo "unmounting $dir"
+        umount -l "$dir"
+done
 
 # turn resource management off for vserver $NAME
 service resman stop $NAME
@@ -42,6 +56,5 @@ rm -f /var/run/vservers/$NAME.ctx
 if [ -d $VROOTDIR/$NAME ] ; then
     TMP=$(mktemp -d "$VROOTDIR/.vtmp/$NAME.XXXXXX")
     mv "$VROOTDIR/$NAME" "$TMP"
-    chattr -R -i "$TMP"
     rm -rf "$TMP"
 fi