5cc663eedd8c02f74143f6f8db616521242f290e
[util-vserver.git] / scripts / vuserdel
1 #!/bin/bash
2 #
3 # userdel(8) wrapper for vservers
4 #
5 # Copyright (c) 2004  The Trustees of Princeton University (Trustees).
6 #
7 # $Id: vuserdel,v 1.6 2004/11/23 14:47:35 mlhuang Exp $
8 #
9
10 : ${UTIL_VSERVER_VARS:=$(dirname $0)/util-vserver-vars}
11 test -e "$UTIL_VSERVER_VARS" || {
12     echo "Can not find util-vserver installation; aborting..."
13     exit 1
14 }
15 . "$UTIL_VSERVER_VARS"
16
17 usage()
18 {
19     echo "usage: $0 name"
20     exit 1
21 }
22
23 [ -z "$1" ] && usage
24 NAME=$1
25
26 # read config file to get context ID
27 . /etc/vservers/$NAME.conf
28 CTX=$S_CONTEXT
29
30 # don't bother stopping gracefully, just kill all the processes
31 $SBINDIR/chcontext --silent --secure --ctx $CTX $PKGLIBDIR/vserverkillall
32
33 # unmount any directories in vserver that are mount points
34 for d in `sed -ne "s%^[^ ]* \($VROOTDIR/$NAME/[^ ]*\) .*%\1%p" /proc/mounts`
35 do
36         # use echo -e to turn escaped whitespace back into regular chars
37         # be careful about embedded backquotes here (i think we're safe)
38         dir=`echo -e "$d"`
39         echo "unmounting $dir"
40         umount -l "$dir"
41 done
42
43 # turn resource management off for vserver $NAME
44 service resman stop $NAME
45
46 # delete user
47 userdel -r $NAME
48
49 # remove vserver configuration file
50 rm -f /etc/vservers/$NAME.conf
51
52 # remove vserver profile
53 rm -f /var/run/vservers/$NAME.ctx
54
55 # destroy vserver
56 if [ -d $VROOTDIR/$NAME ] ; then
57     TMP=$(mktemp -d "$VROOTDIR/.vtmp/$NAME.XXXXXX")
58     mv "$VROOTDIR/$NAME" "$TMP"
59     rm -rf "$TMP"
60 fi