875131f44dae71e90cff3d17bf5e7b25b98ce161
[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.9 2005/08/21 21:44:09 mlhuang Exp $
8 #
9
10 : ${UTIL_VSERVER_VARS:=/usr/lib/util-vserver/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 [ "$1" == "--static" ] && { STATIC=yes; shift; }
25 NAME=$1
26
27 # read config file to get context ID
28 . /etc/vservers/$NAME.conf
29 CTX=$S_CONTEXT
30
31 # don't bother stopping gracefully, just kill all the processes
32 chcontext --silent --secure --ctx $CTX $__LEGACYDIR/vserverkillall
33
34 # unmount any directories in vserver that are mount points
35 for d in `sed -ne "s%^[^ ]* \($__DEFAULT_VSERVERDIR/$NAME/[^ ]*\) .*%\1%p" /proc/mounts`
36 do
37         # use echo -e to turn escaped whitespace back into regular chars
38         # be careful about embedded backquotes here (i think we're safe)
39         dir=`echo -e "$d"`
40         echo "unmounting $dir"
41         umount -l "$dir"
42 done
43
44 # delete user
45 [ -z "$STATIC" ] && userdel -r $NAME
46
47 # remove vserver configuration file
48 rm -f /etc/vservers/$NAME.conf
49
50 # remove vserver profile
51 rm -f /var/run/vservers/$NAME.ctx
52
53 # destroy vserver
54 if [ -d $__DEFAULT_VSERVERDIR/$NAME ] ; then
55     TMP=$(mktemp -d "$__DEFAULT_VSERVERDIR/.vtmp/$NAME.XXXXXX")
56     mv "$__DEFAULT_VSERVERDIR/$NAME" "$TMP"
57     rm -rf "$TMP"
58 fi