Get rid of the context on vuserdel.
[util-vserver-pl.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$
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 CTX=`cat $__CONFDIR/$NAME/context`
29
30 # don't bother stopping gracefully, just kill all the processes
31 $_VKILL -c "$CTX" -s 15 -1
32 sleep 2
33 $_VKILL -c "$CTX" -s 9 -1
34 $_VATTRIBUTE --set --xid "$CTX" --flag ~persistent
35 $_NATTRIBUTE --set --nid "$CTX" --flag ~persistent
36
37 # unmount any directories in vserver that are mount points
38 for d in `sed -ne "s%^[^ ]* \($__DEFAULT_VSERVERDIR/$NAME/[^ ]*\) .*%\1%p" /proc/mounts`
39 do
40         # use echo -e to turn escaped whitespace back into regular chars
41         # be careful about embedded backquotes here (i think we're safe)
42         dir=`echo -e "$d"`
43         echo "unmounting $dir"
44         umount -l "$dir"
45 done
46
47 # delete user
48 [ -z "$STATIC" ] && userdel -r $NAME
49
50 # remove vserver configuration directory
51 rm -rf /etc/vservers/$NAME
52
53 # remove vserver profile
54 rm -f /var/run/vservers/$NAME.ctx
55
56 # destroy vserver
57 if [ -d $__DEFAULT_VSERVERDIR/$NAME ] ; then
58     TMP=$(mktemp -d "$__DEFAULT_VSERVERDIR/.vtmp/$NAME.XXXXXX")
59     mv "$__DEFAULT_VSERVERDIR/$NAME" "$TMP"
60     rm -rf "$TMP"
61 fi